mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-23 22:04:26 -04:00
Merge branch 'master' into keyring1
This commit is contained in:
commit
c1bf4fb27f
2772 changed files with 62382 additions and 338334 deletions
22
.gitignore
vendored
22
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
# SPDX-FileCopyrightText: (C) 2004-2019 Retroshare Team <contact@retroshare.cc>
|
# SPDX-FileCopyrightText: (C) 2004-2022 Retroshare Team <contact@retroshare.cc>
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
*.o
|
*.o
|
||||||
|
@ -15,3 +15,23 @@ Thumbs.db
|
||||||
*.pro.user
|
*.pro.user
|
||||||
.kdev4
|
.kdev4
|
||||||
*.kdev4
|
*.kdev4
|
||||||
|
|
||||||
|
.qmake.stash
|
||||||
|
|
||||||
|
!supportlibs/libsam3/Makefile
|
||||||
|
|
||||||
|
# QtCreator cruft
|
||||||
|
*CMakeLists.txt.user
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
/jsonapi-generator/src/jsonapi-generator
|
||||||
|
/jsonapi-generator/src/jsonapi-generator-doxygen-final.conf
|
||||||
|
/jsonapi-generator/src/jsonapi-includes.inl
|
||||||
|
/jsonapi-generator/src/jsonapi-wrappers.inl
|
||||||
|
/jsonapi-generator/src/xml/
|
||||||
|
/retroshare-friendserver/src/retroshare-friendserver
|
||||||
|
/retroshare-gui/src/include/
|
||||||
|
/retroshare-gui/src/retroshare
|
||||||
|
/retroshare-gui/src/temp/
|
||||||
|
/retroshare-service/src/retroshare-service
|
||||||
|
/*.tar.?z
|
||||||
|
|
|
@ -3,30 +3,46 @@ image: docker:stable
|
||||||
services:
|
services:
|
||||||
- docker:stable-dind
|
- docker:stable-dind
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
|
||||||
workflow:
|
workflow:
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_MERGE_REQUEST_ID
|
- if: $CI_MERGE_REQUEST_ID
|
||||||
- if: $CI_COMMIT_BRANCH
|
- if: $CI_COMMIT_BRANCH
|
||||||
|
|
||||||
build-and-test:
|
variables:
|
||||||
|
UBUNTU_TESTING_IMAGE_TAG: "$CI_REGISTRY_IMAGE/gitlabci_outputs/ubuntu_testing:$CI_COMMIT_SHA"
|
||||||
|
|
||||||
|
build-ubuntu-test-image:
|
||||||
|
stage: build
|
||||||
script:
|
script:
|
||||||
- >
|
- >
|
||||||
if [ -n "$CI_MERGE_REQUEST_ID" ]; then
|
docker login "$CI_REGISTRY"
|
||||||
REPO_ARGS="--build-arg REPO_URL=$CI_MERGE_REQUEST_SOURCE_PROJECT_URL" ;
|
--username "$CI_REGISTRY_USER"
|
||||||
REPO_ARGS="$REPO_ARGS --build-arg REPO_BRANCH=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" ;
|
--password "$CI_REGISTRY_PASSWORD"
|
||||||
else
|
|
||||||
REPO_ARGS="--build-arg REPO_URL=$CI_REPOSITORY_URL" ;
|
|
||||||
REPO_ARGS="$REPO_ARGS --build-arg REPO_BRANCH=$CI_COMMIT_BRANCH" ;
|
|
||||||
fi ;
|
|
||||||
export REPO_ARGS ;
|
|
||||||
echo REPO_ARGS=$REPO_ARGS ;
|
|
||||||
- mkdir Dockercontext
|
- mkdir Dockercontext
|
||||||
- >
|
- >
|
||||||
docker build -t retroshare:testing $REPO_ARGS
|
docker build
|
||||||
|
-t $UBUNTU_TESTING_IMAGE_TAG
|
||||||
|
$($CI_PROJECT_DIR/build_scripts/GitlabCI/getRepoArgs.sh)
|
||||||
--file $CI_PROJECT_DIR/build_scripts/GitlabCI/gitlabCI.Dockerfile
|
--file $CI_PROJECT_DIR/build_scripts/GitlabCI/gitlabCI.Dockerfile
|
||||||
Dockercontext
|
Dockercontext
|
||||||
|
- docker push $UBUNTU_TESTING_IMAGE_TAG
|
||||||
|
- echo UBUNTU_TESTING_IMAGE_TAG=$UBUNTU_TESTING_IMAGE_TAG
|
||||||
|
|
||||||
|
test-ubuntu:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
- >
|
- >
|
||||||
docker run --name retroshare --detach --tty retroshare:testing
|
docker login "$CI_REGISTRY"
|
||||||
|
--username "$CI_REGISTRY_USER"
|
||||||
|
--password "$CI_REGISTRY_PASSWORD"
|
||||||
|
- echo UBUNTU_TESTING_IMAGE_TAG=$UBUNTU_TESTING_IMAGE_TAG
|
||||||
|
- docker pull $UBUNTU_TESTING_IMAGE_TAG
|
||||||
|
- >
|
||||||
|
docker run --name retroshare --detach --tty $UBUNTU_TESTING_IMAGE_TAG
|
||||||
retroshare-service --jsonApiPort 9092
|
retroshare-service --jsonApiPort 9092
|
||||||
- apk add jq
|
- apk add jq
|
||||||
- >
|
- >
|
||||||
|
|
21
.gitmodules
vendored
21
.gitmodules
vendored
|
@ -14,3 +14,24 @@
|
||||||
[submodule "supportlibs/rapidjson"]
|
[submodule "supportlibs/rapidjson"]
|
||||||
path = supportlibs/rapidjson
|
path = supportlibs/rapidjson
|
||||||
url = https://github.com/Tencent/rapidjson.git
|
url = https://github.com/Tencent/rapidjson.git
|
||||||
|
[submodule "supportlibs/libsam3"]
|
||||||
|
path = supportlibs/libsam3
|
||||||
|
url = https://github.com/i2p/libsam3.git
|
||||||
|
[submodule "supportlibs/jni.hpp"]
|
||||||
|
path = supportlibs/jni.hpp
|
||||||
|
url = https://github.com/RetroShare/jni.hpp.git
|
||||||
|
[submodule "openpgpsdk"]
|
||||||
|
path = openpgpsdk
|
||||||
|
url = ../OpenPGP-SDK
|
||||||
|
branch = master
|
||||||
|
[submodule "libbitdht"]
|
||||||
|
path = libbitdht
|
||||||
|
url = ../BitDHT
|
||||||
|
branch = master
|
||||||
|
[submodule "libretroshare"]
|
||||||
|
path = libretroshare
|
||||||
|
url = ../libretroshare
|
||||||
|
branch = master
|
||||||
|
[submodule "retroshare-webui"]
|
||||||
|
path = retroshare-webui
|
||||||
|
url = ../RSNewWebUI
|
||||||
|
|
14
.travis.yml
14
.travis.yml
|
@ -8,12 +8,12 @@ language: cpp
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: linux
|
# - os: linux
|
||||||
dist: bionic
|
# dist: bionic
|
||||||
sudo: required
|
# sudo: required
|
||||||
compiler: gcc
|
# compiler: gcc
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode10.1
|
osx_image: xcode10.2
|
||||||
compiler: clang
|
compiler: clang
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
|
@ -68,11 +68,11 @@ before_script:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j4; fi
|
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then travis_wait 30 make -j$(nproc); fi
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- if [ $TRAVIS_OS_NAME == osx ]; then build_scripts/OSX/travis_makeOSXPackage.sh ; fi
|
- if [ $TRAVIS_OS_NAME == osx ]; then build_scripts/OSX/travis_makeOSXPackage.sh ; fi
|
||||||
- if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j2; fi
|
# - if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j2; fi
|
||||||
|
|
||||||
|
|
||||||
# branches:
|
# branches:
|
||||||
|
|
|
@ -10,10 +10,21 @@ RetroShare provides file sharing, chat, messages, forums, channels and more.
|
||||||
.Build Status
|
.Build Status
|
||||||
|===============================================================================
|
|===============================================================================
|
||||||
|GNU/Linux (via Gitlab CI) | image:https://gitlab.com/RetroShare/RetroShare/badges/master/pipeline.svg[link="https://gitlab.com/RetroShare/RetroShare/-/commits/master",title="pipeline status"]
|
|GNU/Linux (via Gitlab CI) | image:https://gitlab.com/RetroShare/RetroShare/badges/master/pipeline.svg[link="https://gitlab.com/RetroShare/RetroShare/-/commits/master",title="pipeline status"]
|
||||||
|GNU/Linux, macOS, (via Travis CI) | image:https://travis-ci.org/RetroShare/RetroShare.svg?branch=master[link="https://travis-ci.org/RetroShare/RetroShare"]
|
|
||||||
|Windows (via AppVeyor) | image:https://ci.appveyor.com/api/projects/status/github/RetroShare/RetroShare?svg=true[link="https://ci.appveyor.com/project/RetroShare58622/retroshare"]
|
|Windows (via AppVeyor) | image:https://ci.appveyor.com/api/projects/status/github/RetroShare/RetroShare?svg=true[link="https://ci.appveyor.com/project/RetroShare58622/retroshare"]
|
||||||
|
|macOS, (via Travis CI) | image:https://app.travis-ci.com/RetroShare/RetroShare.svg?branch=master[link="https://app.travis-ci.com/github/RetroShare/RetroShare"]
|
||||||
|
|libretroshare GNU/Linux, Android (via Gitlab CI) | image:https://gitlab.com/RetroShare/libretroshare/badges/master/pipeline.svg[link="https://gitlab.com/RetroShare/libretroshare/-/commits/master",title="pipeline status"]
|
||||||
|===============================================================================
|
|===============================================================================
|
||||||
|
|
||||||
|
== Get the source
|
||||||
|
|
||||||
|
Clone this repository, enter the directory and then get the submodules with the
|
||||||
|
following command
|
||||||
|
|
||||||
|
[source,bash]
|
||||||
|
--------
|
||||||
|
git submodule update --init --remote --force libbitdht/ libretroshare/ openpgpsdk/
|
||||||
|
--------
|
||||||
|
|
||||||
|
|
||||||
== Compilation
|
== Compilation
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,12 @@ retroshare_service {
|
||||||
retroshare_service.target = retroshare_service
|
retroshare_service.target = retroshare_service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retroshare_friendserver {
|
||||||
|
SUBDIRS += retroshare_friendserver
|
||||||
|
retroshare_friendserver.file = retroshare-friendserver/src/retroshare-friendserver.pro
|
||||||
|
retroshare_friendserver.depends = libretroshare
|
||||||
|
retroshare_friendserver.target = retroshare_friendserver
|
||||||
|
}
|
||||||
retroshare_plugins {
|
retroshare_plugins {
|
||||||
SUBDIRS += plugins
|
SUBDIRS += plugins
|
||||||
plugins.file = plugins/plugins.pro
|
plugins.file = plugins/plugins.pro
|
||||||
|
@ -62,6 +68,13 @@ retroshare_plugins {
|
||||||
plugins.target = plugins
|
plugins.target = plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rs_webui {
|
||||||
|
SUBDIRS += retroshare-webui
|
||||||
|
retroshare-webui.file = retroshare-webui/webui.pro
|
||||||
|
retroshare-webui.target = rs_webui
|
||||||
|
retroshare-webui.depends = retroshare_gui
|
||||||
|
}
|
||||||
|
|
||||||
wikipoos {
|
wikipoos {
|
||||||
SUBDIRS += pegmarkdown
|
SUBDIRS += pegmarkdown
|
||||||
pegmarkdown.file = supportlibs/pegmarkdown/pegmarkdown.pro
|
pegmarkdown.file = supportlibs/pegmarkdown/pegmarkdown.pro
|
||||||
|
|
|
@ -258,10 +258,10 @@ after_build:
|
||||||
# artifacts configuration #
|
# artifacts configuration #
|
||||||
#---------------------------------#
|
#---------------------------------#
|
||||||
|
|
||||||
#artifacts:
|
artifacts:
|
||||||
# - path: '**\*.exe'
|
- path: '**\*.exe'
|
||||||
# - path: filelist.txt
|
- path: filelist.txt
|
||||||
# - path: $(RS_DEPLOY)
|
- path: $(RS_DEPLOY)
|
||||||
|
|
||||||
#
|
#
|
||||||
# # pushing a single file
|
# # pushing a single file
|
||||||
|
|
|
@ -1,399 +0,0 @@
|
||||||
= RetroShare development on Android
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: RetroShare Team <contact@retroshare.cc>
|
|
||||||
// SPDX-License-Identifier: CC-BY-SA-4.0
|
|
||||||
|
|
||||||
|
|
||||||
Compiling an application for Android is not as easy as one would imagine,
|
|
||||||
expecially one like RetroShare that has a big codebase and is not well
|
|
||||||
documented. This document is aimed to empower the reader so she can hopefully
|
|
||||||
succed or at least have a significant help in compiling her own RetroShare APK
|
|
||||||
installable on Android.
|
|
||||||
|
|
||||||
|
|
||||||
== Preparing The Environement
|
|
||||||
|
|
||||||
First of all setup your Qt for Android development environement following the
|
|
||||||
guide on the link:http://doc.qt.io/qt-5/androidgs.html[Qt for android web site].
|
|
||||||
At this point you should have Android SDK, Android NDK, and Qt for Android
|
|
||||||
working fine, and you should be capable of executing on an Android emulator or
|
|
||||||
on your Android phone Qt for Android examples.
|
|
||||||
|
|
||||||
But RetroShare is not as simple to compile as those examples. The good news is
|
|
||||||
that Android NDK ships all the necessary to build a custom toolchain that is
|
|
||||||
suitable to build RetroShare.
|
|
||||||
In order to build the toolchain with needed libraries RetroShare provides the
|
|
||||||
+android-prepare-toolchain.sh+ script; before you execute it you should define
|
|
||||||
some variables the script cannot determine in an easy and reliable manner by
|
|
||||||
itself in your terminal.
|
|
||||||
|
|
||||||
[source,bash]
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
## The path where Android NDK is installed in your system
|
|
||||||
export ANDROID_NDK_PATH="/opt/android-ndk/"
|
|
||||||
|
|
||||||
## The path where your fresh compiled toolchain will be installed, make sure
|
|
||||||
## the parent exists
|
|
||||||
export NATIVE_LIBS_TOOLCHAIN_PATH="${HOME}/Builds/android-toolchains/retroshare-android/"
|
|
||||||
|
|
||||||
## The CPU architecture of the Android device you want to target
|
|
||||||
export ANDROID_NDK_ARCH="arm"
|
|
||||||
|
|
||||||
## The Android API level the Android device you want to target
|
|
||||||
export ANDROID_PLATFORM_VER="16"
|
|
||||||
|
|
||||||
## The number of core that yout host CPU have (just to speed up compilation) set
|
|
||||||
## it to 1 if unsure
|
|
||||||
export HOST_NUM_CPU=1
|
|
||||||
|
|
||||||
./android-prepare-toolchain.sh
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
== Preparing Qt Creator
|
|
||||||
|
|
||||||
Now that your environement is set up you should configure Qt Creator for Android
|
|
||||||
following the
|
|
||||||
link:http://doc.qt.io/qtcreator/creator-developing-android.html[official guide].
|
|
||||||
At the end of this step your Qt Creator should recognize the Android compiler
|
|
||||||
and the Qt for Android kit.
|
|
||||||
|
|
||||||
Your Kit is now ready to use. Now you can open RetroShare as a Qt Creator
|
|
||||||
project and in the Projects left menu add the newly created kit if not already
|
|
||||||
present, so you can select it on the build type selection button down on the
|
|
||||||
left.
|
|
||||||
|
|
||||||
Now you need to set properly a few options like `JSONAPI_GENERATOR_EXE` and
|
|
||||||
disable some of RetroShare modules like `retroshare-gui` that are not available
|
|
||||||
on Android so you will have to go to
|
|
||||||
|
|
||||||
_Qt Creator left pane -> Projects -> Build and Run -> Android SOMESTUFF kit ->
|
|
||||||
Build Steps -> qmake -> Additional arguments_ +
|
|
||||||
|
|
||||||
and add the following configurations (change `Your_Path` according to your
|
|
||||||
deployment)
|
|
||||||
|
|
||||||
[source,makefile]
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
CONFIG+=retroshare_service CONFIG+=rs_jsonapi CONFIG+=rs_deep_search
|
|
||||||
RS_UPNP_LIB=miniupnpc
|
|
||||||
JSONAPI_GENERATOR_EXE=Your_Path/jsonapi-generator/src/jsonapi-generator
|
|
||||||
NATIVE_LIBS_TOOLCHAIN_PATH=Your_Path/retroshare-android-16-arm/
|
|
||||||
CONFIG+=no_retroshare_gui CONFIG+=no_rs_service_webui_terminal_password
|
|
||||||
CONFIG+=no_rs_service_terminal_login
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
TIP: Some versions of QtCreator try to find the Android SDK in
|
|
||||||
`/opt/android/sdk`. A workaround to this is to make a symbolic link there
|
|
||||||
pointing to your SDK installation path, like
|
|
||||||
+mkdir -p /opt/android/sdk && ln -s /home/user/android-sdk-linux
|
|
||||||
/opt/android/sdk+
|
|
||||||
|
|
||||||
|
|
||||||
== Quircks
|
|
||||||
|
|
||||||
=== Protected Apps
|
|
||||||
|
|
||||||
On some Android devices like +Huawei ALE-L21+ background applications are
|
|
||||||
killed when screen is turned off unless they are in the _protected app_ list.
|
|
||||||
At moment seems apps developers don't have a way to have the application
|
|
||||||
_protected_ by default, unless the phone vendor decide the app is _popular_ so
|
|
||||||
the user have to enable _protection_ for RetroShare manually on those mobile
|
|
||||||
phones. +
|
|
||||||
|
|
||||||
{empty} +
|
|
||||||
To enable enable _protection_: +Android menu -> Settings -> Privacy & security
|
|
||||||
-> Protected apps -> RetroShare+ +
|
|
||||||
{empty} +
|
|
||||||
|
|
||||||
Other devices may offer similar _features_ please report them.
|
|
||||||
|
|
||||||
|
|
||||||
=== APK signature mismatch
|
|
||||||
|
|
||||||
If you try to install a RetroShare APK that comes from a different source
|
|
||||||
(eg: if you try to upgrade from F-Droid when you originally installed an APK
|
|
||||||
build by yourself) Android will prevent that from happening. In that case the
|
|
||||||
only solution is to uninstall the app and then install the new APK but if you do
|
|
||||||
it also the application data and your precious cryptographic keys, friend list
|
|
||||||
etc. will be lost forever.
|
|
||||||
To avoid that you can attempt to manually backup and then restore from the
|
|
||||||
command-line (`adb backup` seems not working either) to change the app source
|
|
||||||
without erasing the appliation data.
|
|
||||||
|
|
||||||
CAUTION: Following steps require root access on your Android device
|
|
||||||
|
|
||||||
.Backup RetroShare Android application data
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
export ORIG_DIR="/data/data/org.retroshare.android.qml_app"
|
|
||||||
export BACKUP_DIR="org.retroshare.android.qml_app.backup"
|
|
||||||
|
|
||||||
adb root
|
|
||||||
|
|
||||||
adb shell am force-stop org.retroshare.android.qml_app
|
|
||||||
sleep 1s
|
|
||||||
|
|
||||||
mkdir ${BACKUP_DIR}
|
|
||||||
|
|
||||||
# Avoid adb pull failing
|
|
||||||
adb shell rm ${ORIG_DIR}/files/.retroshare/libresapi.sock
|
|
||||||
adb pull ${ORIG_DIR}/files/ ${BACKUP_DIR}/files/
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
After this you should be able to uninstall the old APK with your preferred
|
|
||||||
method, as example from the command-line.
|
|
||||||
|
|
||||||
.Uninstall RetroShare Android from the command-line
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
adb uninstall org.retroshare.android.qml_app
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Now you can install a different signature APK and then restore the application
|
|
||||||
data with the following commands.
|
|
||||||
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
export ORIG_DIR="/data/data/org.retroshare.android.qml_app"
|
|
||||||
export BACKUP_DIR="org.retroshare.android.qml_app.backup"
|
|
||||||
|
|
||||||
adb root
|
|
||||||
|
|
||||||
## Launch the app to make sure the parent directory exists and has proper owner
|
|
||||||
adb shell monkey -p org.retroshare.android.qml_app -c android.intent.category.LAUNCHER 1
|
|
||||||
sleep 1s
|
|
||||||
|
|
||||||
adb shell am force-stop org.retroshare.android.qml_app
|
|
||||||
sleep 1s
|
|
||||||
|
|
||||||
|
|
||||||
APP_OWNER="$(adb shell busybox ls -lnd ${ORIG_DIR} | awk '{print $3":"$4}')"
|
|
||||||
adb shell rm -rf ${ORIG_DIR}/files
|
|
||||||
adb push ${BACKUP_DIR}/files/ ${ORIG_DIR}/files/
|
|
||||||
adb shell busybox chown -R ${APP_OWNER} ${ORIG_DIR}/files/
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Opening RetroShare android app now should show your old profile.
|
|
||||||
|
|
||||||
|
|
||||||
== Debugging with GDB
|
|
||||||
|
|
||||||
If building RetroShare Android package seems tricky, setting up a functional
|
|
||||||
debugging environement for it feels like black magic. This section is meant to
|
|
||||||
help you doing it with less headache and hopefully in a reproducible way.
|
|
||||||
|
|
||||||
Unfortunately at the time of the last update to this guide, Qt build system
|
|
||||||
strips debugging symbols from the package and from the buildroot also if you
|
|
||||||
compile with debugging enabled. Fiddling with `qmake` configurations and
|
|
||||||
variables like `CONFIG+=debug`, `CONFIG+=force_debug_info` or `QMAKE_STRIP`
|
|
||||||
either as commandline arguments or inside retroshare `.pro` and `.pri` files is
|
|
||||||
uneffective. IMHO Qt should handle this on itself so it is probably worth
|
|
||||||
reporting a bug to them. So to workaround this problem you need to fiddle a bit
|
|
||||||
with the Android NDK. In my case I always keep +Debug+ or +Release+ suffix in
|
|
||||||
my build directory name depending on what kind of build it is, so I use this
|
|
||||||
information and modify `llvm-strip` in a way that it will strip only if stripped
|
|
||||||
file path doesn't contain +Debug+.
|
|
||||||
|
|
||||||
.Modify llvm-strip inside Android NDK
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Set ANDROID_NDK_PATH to your Android NDK installation path
|
|
||||||
export ANDROID_NDK_PATH="/opt/android-ndk/"
|
|
||||||
|
|
||||||
## Define a convenience variable with llvm-strip path
|
|
||||||
export ANDROID_NDK_LLVM_STRIP="${ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
|
|
||||||
|
|
||||||
## If not existing yer create a backup of the original llvm-strip
|
|
||||||
[ -f "${ANDROID_NDK_LLVM_STRIP}.back" ] ||
|
|
||||||
cp "${ANDROID_NDK_LLVM_STRIP}" "${ANDROID_NDK_LLVM_STRIP}.back"
|
|
||||||
|
|
||||||
## Create a new llvm-strip that does nothing if the argument path contains Debug
|
|
||||||
cat > "${ANDROID_NDK_LLVM_STRIP}" << LLVMSTRIPTRICK
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
echo "\${2}" | grep -q Debug ||
|
|
||||||
"${ANDROID_NDK_LLVM_STRIP}.back" --strip-all "\${2}"
|
|
||||||
|
|
||||||
LLVMSTRIPTRICK
|
|
||||||
|
|
||||||
## Eventually you can revert back simply by running
|
|
||||||
# `mv "${ANDROID_NDK_LLVM_STRIP}.back" "${ANDROID_NDK_LLVM_STRIP}"`
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
To attach to the `retroshare-service` running on Android you need also to pull a
|
|
||||||
debugging sysroot out of your device first, RetroShare sources provides an
|
|
||||||
helper script to do that.
|
|
||||||
|
|
||||||
.Prepare debugging sysroot with helper script
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Set RetroShare source path
|
|
||||||
export RS_SOURCE_DIR="${HOME}/Development/rs-develop"
|
|
||||||
|
|
||||||
## Optionally set your device ID first available will be used, you can run
|
|
||||||
## `adb devices` to list available devices.
|
|
||||||
#export ANDROID_SERIAL="YT013PSPGK"
|
|
||||||
|
|
||||||
## Optionally set a path where to save the debugging sysroot otherwise default
|
|
||||||
## is used.
|
|
||||||
#export DEBUG_SYSROOT="${HOME}/Builds/debug_sysroot/${ANDROID_SERIAL}/"
|
|
||||||
|
|
||||||
## Run the helper script
|
|
||||||
${RS_SOURCE_DIR}/build_scripts/Android/pull_sysroot.sh
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.Prepare Android NDK GDB configurations
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Optionally set Qt version variable consistently with your installation
|
|
||||||
export QT_VERSION="5.12.7"
|
|
||||||
|
|
||||||
## Optionally set Qt architecture variable consistently with Android device
|
|
||||||
export QT_ARCH="arm64_v8a"
|
|
||||||
|
|
||||||
## Optionally set Qt path variable consistently with your installation
|
|
||||||
export QT_DIR="/opt/Qt-${QT_VERSION}/${QT_VERSION}/"
|
|
||||||
|
|
||||||
## Optionally set RetroShare buildroot path
|
|
||||||
export RS_BUILD_DIR="${HOME}/Builds/RetroShare-Android_for_${QT_ARCH}_Clang_Qt_${QT_VERSION//./_}_android_${QT_ARCH}-Debug/"
|
|
||||||
|
|
||||||
## Optionally set gdb config file path
|
|
||||||
export GDB_CONFIGS_FILE="${HOME}/Builds/gdb_configs_${QT_ARCH}"
|
|
||||||
|
|
||||||
## Generate Android NDK GDB configuration
|
|
||||||
${RS_SOURCE_DIR}/build_scripts/Android/generate_gdb_init_commands.sh
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
You will need to run the following steps everytime you want to debug
|
|
||||||
`retroshare-service` on Android.
|
|
||||||
|
|
||||||
Make sure `retroshare-service` is running on your connected Android device.
|
|
||||||
|
|
||||||
.Run GDB server on your Android device from your host console
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
${RS_SOURCE_DIR}/build_scripts/Android/start_gdbserver.sh
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
.Run Android NDK GDB on your workstation and attach
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Start NDK gdb
|
|
||||||
${ANDROID_NDK_PATH}/prebuilt/linux-x86_64/bin/gdb
|
|
||||||
|
|
||||||
## Instruct GDB how and where to find debugging symbols
|
|
||||||
(gdb) source $GDB_CONFIGS_FILE
|
|
||||||
|
|
||||||
## Connect to the gdbserver running on the phone
|
|
||||||
(gdb) target remote 127.0.01:5039
|
|
||||||
|
|
||||||
## Have fun debugging
|
|
||||||
(gdb)
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
== Debugging with Qt Creator
|
|
||||||
|
|
||||||
WARNING: As of the last update to this guide, debugging retroshare-service
|
|
||||||
running on Android via Qt creator doesn't wrok even with all the trickery
|
|
||||||
explained in this section, you better learn how to debug with GDB reading
|
|
||||||
carefully previous section.
|
|
||||||
|
|
||||||
Qt Creator actually support debugging only for the foreground activity, so to
|
|
||||||
debug what's happening in the core extra trickery is needed.
|
|
||||||
|
|
||||||
- Run the App in Debug mode from QtCreator "Start Debugging" button
|
|
||||||
- Enable QtCreator debugger console view Menu->Window->Debugger Log
|
|
||||||
- Run +show solib-search-path+ in the QtCreator GDB console
|
|
||||||
- Take note of the output you get in the right pane of the console
|
|
||||||
- Thanks https://stackoverflow.com/a/31164313 for the idea
|
|
||||||
|
|
||||||
TIP: QtCreator GDB console seems a bit buggy and easly trigger timeout
|
|
||||||
message when a command is run, in that case attempt to run the command while the
|
|
||||||
debugging is paused or at breakpoint, or with other similar tricks.
|
|
||||||
|
|
||||||
CAUTION: Following steps require root access on your Android device
|
|
||||||
|
|
||||||
Now on your phone yuo need to authorize root access to applications, then once
|
|
||||||
you plug your sacrifical Android phone run this commands
|
|
||||||
|
|
||||||
.Run gdbserver as root on Android phone
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Open a shell from your workstation on the connected Android phone
|
|
||||||
adb shell
|
|
||||||
|
|
||||||
## take the note of the phone IP address
|
|
||||||
ip address show
|
|
||||||
|
|
||||||
## Gain root permissions on the shell
|
|
||||||
su
|
|
||||||
|
|
||||||
## Attach with gdbserver and listen on one TCP port
|
|
||||||
gdbserver :4567 --attach $(pgrep org.retroshare.android.qml_app:rs)
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
.Prepare and run Android NDK GDB on your workstation
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
## Setup some convenience variables
|
|
||||||
NDK_GDB="${ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb"
|
|
||||||
RS_BUILD_PATH="${HOME}/Builds/RetroShare-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_2_android_armv7-Debug/"
|
|
||||||
|
|
||||||
## Start Android NDK GDB of your phone architecture passing the executable
|
|
||||||
$NDK_GDB $RS_BUILD_PATH/retroshare-android-service/src/libretroshare-android-service.so
|
|
||||||
|
|
||||||
## Instruct GDB how and where to find debugging symbols
|
|
||||||
(gdb) set auto-solib-add on
|
|
||||||
(gdb) set solib-search-path THE:BIG:LIST:OF:DIRECTORIES:YOU:TAKE:NOTE:BEFORE
|
|
||||||
|
|
||||||
## Connect to the gdbserver running on the phone
|
|
||||||
(gdb) target remote $PHONE_IP:4567
|
|
||||||
|
|
||||||
## Have fun debugging
|
|
||||||
(gdb)
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
TIP: Some time WiFi power saving on Android mess with the GDB connection,
|
|
||||||
to prevent that from appening open another +adb shell+ and live +ping+ toward
|
|
||||||
your work-station running
|
|
||||||
|
|
||||||
== Embedding into other Android packages
|
|
||||||
|
|
||||||
As showed by https://elrepo.io/[elRepo.io] developers it is possible and quite
|
|
||||||
easy to embed `retroshare-service` into other Android packages see description
|
|
||||||
|
|
||||||
https://gitlab.com/elRepo.io/elRepo.io-android/-/blob/master/README.adoc
|
|
||||||
|
|
||||||
And implementation details
|
|
||||||
|
|
||||||
https://gitlab.com/elRepo.io/elRepo.io-android/-/blob/master/android/app/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
== Furter Readings
|
|
||||||
|
|
||||||
- link:http://doc.qt.io/qt-5/android-support.html[]
|
|
||||||
- link:https://developer.android.com/ndk/guides/libs.html[]
|
|
||||||
- link:retroshare://forum?name=Compiling%20nogui%20for%20android&id=8fd22bd8f99754461e7ba1ca8a727995&msgid=4e0f92330600bba9cf978f384f4b7b2f2ca64eff[]
|
|
||||||
- link:retroshare://file?name=Android%20Native%20Development%20Kit%20Cookbook.pdf&size=29214468&hash=0123361c1b14366ce36118e82b90faf7c7b1b136[]
|
|
||||||
- link:https://groups.google.com/forum/#!topic/android-developers/srATPaL0aRU[]
|
|
||||||
- link:https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it[]
|
|
||||||
- link:https://tthtlc.wordpress.com/2012/09/19/how-to-do-remote-debugging-via-gdbserver-running-inside-the-android-phone/[]
|
|
||||||
- link:https://source.android.com/devices/tech/debug/[]
|
|
||||||
- link:https://source.android.com/devices/tech/debug/gdb[]
|
|
||||||
- link:https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html[]
|
|
||||||
- link:https://fragglet.livejournal.com/19646.html[]
|
|
||||||
- link:https://github.com/android-ndk/ndk/issues/773[How to build without using standalone toolchain?]
|
|
||||||
|
|
||||||
== License
|
|
||||||
|
|
||||||
Copyright (C) 2016-2020 Gioacchino Mazzurco <gio@eigenlab.org> +
|
|
||||||
Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> +
|
|
||||||
|
|
||||||
This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
|
|
||||||
|
|
||||||
image::https://i.creativecommons.org/l/by-sa/4.0/88x31.png[Creative Commons License, link=http://creativecommons.org/licenses/by-sa/4.0/]
|
|
|
@ -1,85 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to prepare Android NDK GDB configurations to debug retroshare-service
|
|
||||||
#
|
|
||||||
# Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
||||||
# Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU Affero General Public License as published by the
|
|
||||||
# Free Software Foundation, version 3.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License along
|
|
||||||
# with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
|
|
||||||
## Define default value for variable, take two arguments, $1 variable name,
|
|
||||||
## $2 default variable value, if the variable is not already define define it
|
|
||||||
## with default value.
|
|
||||||
function define_default_value()
|
|
||||||
{
|
|
||||||
VAR_NAME="${1}"
|
|
||||||
DEFAULT_VALUE="${2}"
|
|
||||||
|
|
||||||
[ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
define_default_value QT_VERSION "5.12.4"
|
|
||||||
define_default_value QT_ARCH "arm64_v8a"
|
|
||||||
define_default_value QT_DIR "/opt/Qt-${QT_VERSION}/${QT_VERSION}/"
|
|
||||||
define_default_value ANDROID_SERIAL "$(adb devices | head -n 2 | tail -n 1 | awk '{print $1}')"
|
|
||||||
define_default_value RS_BUILD_DIR "${HOME}/Builds/RetroShare-Android_for_${QT_ARCH}_Clang_Qt_${QT_VERSION//./_}_android_${QT_ARCH}-Debug/"
|
|
||||||
define_default_value RS_SOURCE_DIR "${HOME}/Development/rs-develop/"
|
|
||||||
define_default_value DEBUG_SYSROOT "${HOME}/Builds/debug_sysroot/${ANDROID_SERIAL}/"
|
|
||||||
define_default_value GDB_CONFIGS_FILE "${HOME}/Builds/gdb_configs_${QT_ARCH}"
|
|
||||||
|
|
||||||
scanDir()
|
|
||||||
{
|
|
||||||
find "$1" -type d -not -path '*/\.git/*' | tr '\n' ':' >> $GDB_CONFIGS_FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
putSeparator()
|
|
||||||
{
|
|
||||||
echo >> $GDB_CONFIGS_FILE
|
|
||||||
echo >> $GDB_CONFIGS_FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "set sysroot ${DEBUG_SYSROOT}" > $GDB_CONFIGS_FILE
|
|
||||||
putSeparator
|
|
||||||
|
|
||||||
echo "set auto-solib-add on" >> $GDB_CONFIGS_FILE
|
|
||||||
echo -n "set solib-search-path " >> $GDB_CONFIGS_FILE
|
|
||||||
scanDir "${RS_BUILD_DIR}"
|
|
||||||
scanDir "${DEBUG_SYSROOT}"
|
|
||||||
scanDir "${QT_DIR}/android_${QT_ARCH}/lib/"
|
|
||||||
scanDir "${QT_DIR}/android_${QT_ARCH}/plugins/"
|
|
||||||
scanDir "${QT_DIR}/android_${QT_ARCH}/qml/"
|
|
||||||
putSeparator
|
|
||||||
|
|
||||||
echo -n "directory " >> $GDB_CONFIGS_FILE
|
|
||||||
scanDir ${RS_SOURCE_DIR}/jsonapi-generator/src
|
|
||||||
scanDir ${RS_SOURCE_DIR}/libbitdht/src
|
|
||||||
scanDir ${RS_SOURCE_DIR}/openpgpsdk/src
|
|
||||||
scanDir ${RS_SOURCE_DIR}/libretroshare/src
|
|
||||||
scanDir ${RS_SOURCE_DIR}/retroshare-service/src
|
|
||||||
scanDir ${RS_SOURCE_DIR}/supportlibs/rapidjson/include/
|
|
||||||
scanDir ${RS_SOURCE_DIR}/supportlibs/restbed/source/
|
|
||||||
scanDir ${RS_SOURCE_DIR}/supportlibs/udp-discovery-cpp/
|
|
||||||
scanDir ${RS_SOURCE_DIR}/supportlibs/restbed/dependency/asio/asio/include/
|
|
||||||
scanDir ${RS_SOURCE_DIR}/supportlibs/restbed/dependency/catch/include/
|
|
||||||
putSeparator
|
|
||||||
|
|
||||||
## see https://stackoverflow.com/questions/28972367/gdb-backtrace-without-stopping
|
|
||||||
echo "catch signal SIGSEGV" >> $GDB_CONFIGS_FILE
|
|
||||||
echo "commands
|
|
||||||
bt
|
|
||||||
continue
|
|
||||||
end" >> $GDB_CONFIGS_FILE
|
|
||||||
putSeparator
|
|
||||||
|
|
||||||
echo GDB_CONFIGS_FILE=$GDB_CONFIGS_FILE
|
|
|
@ -1,549 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to prepare RetroShare Android package building toolchain
|
|
||||||
#
|
|
||||||
# Copyright (C) 2016-2020 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU Affero General Public License as published by the
|
|
||||||
# Free Software Foundation, version 3.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License along
|
|
||||||
# with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
#
|
|
||||||
# SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
|
|
||||||
## Define default value for variable, take two arguments, $1 variable name,
|
|
||||||
## $2 default variable value, if the variable is not already define define it
|
|
||||||
## with default value.
|
|
||||||
function define_default_value()
|
|
||||||
{
|
|
||||||
VAR_NAME="${1}"
|
|
||||||
DEFAULT_VALUE="${2}"
|
|
||||||
|
|
||||||
[ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
## You are supposed to provide the following variables according to your system setup
|
|
||||||
define_default_value ANDROID_NDK_PATH "/opt/android-ndk/"
|
|
||||||
define_default_value ANDROID_NDK_ARCH "arm"
|
|
||||||
define_default_value ANDROID_PLATFORM_VER "16"
|
|
||||||
define_default_value NATIVE_LIBS_TOOLCHAIN_PATH "${HOME}/Builds/android-toolchains/retroshare-android-${ANDROID_PLATFORM_VER}-${ANDROID_NDK_ARCH}/"
|
|
||||||
define_default_value HOST_NUM_CPU $(nproc)
|
|
||||||
|
|
||||||
define_default_value BZIP2_SOURCE_VERSION "1.0.6"
|
|
||||||
define_default_value BZIP2_SOURCE_SHA256 a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd
|
|
||||||
|
|
||||||
define_default_value OPENSSL_SOURCE_VERSION "1.1.1c"
|
|
||||||
define_default_value OPENSSL_SOURCE_SHA256 f6fb3079ad15076154eda9413fed42877d668e7069d9b87396d0804fdb3f4c90
|
|
||||||
|
|
||||||
define_default_value SQLITE_SOURCE_YEAR "2018"
|
|
||||||
define_default_value SQLITE_SOURCE_VERSION "3250200"
|
|
||||||
define_default_value SQLITE_SOURCE_SHA256 da9a1484423d524d3ac793af518cdf870c8255d209e369bd6a193e9f9d0e3181
|
|
||||||
|
|
||||||
define_default_value SQLCIPHER_SOURCE_VERSION "4.2.0"
|
|
||||||
define_default_value SQLCIPHER_SOURCE_SHA256 105c1b813f848da038c03647a8bfc9d42fb46865e6aaf4edfd46ff3b18cdccfc
|
|
||||||
|
|
||||||
define_default_value LIBUPNP_SOURCE_VERSION "1.8.4"
|
|
||||||
define_default_value LIBUPNP_SOURCE_SHA256 976c3e4555604cdd8391ed2f359c08c9dead3b6bf131c24ce78e64d6669af2ed
|
|
||||||
|
|
||||||
define_default_value INSTALL_QT_ANDROID "false"
|
|
||||||
define_default_value QT_VERSION "5.12.0"
|
|
||||||
define_default_value QT_ANDROID_INSTALLER_SHA256 a214084e2295c9a9f8727e8a0131c37255bf724bfc69e80f7012ba3abeb1f763
|
|
||||||
|
|
||||||
define_default_value RESTBED_SOURCE_VERSION f74f9329dac82e662c1d570b7cd72c192b729eb4
|
|
||||||
|
|
||||||
define_default_value UDP_DISCOVERY_CPP_SOURCE "https://github.com/truvorskameikin/udp-discovery-cpp.git"
|
|
||||||
define_default_value UDP_DISCOVERY_CPP_VERSION "develop"
|
|
||||||
|
|
||||||
define_default_value XAPIAN_SOURCE_VERSION "1.4.7"
|
|
||||||
define_default_value XAPIAN_SOURCE_SHA256 13f08a0b649c7afa804fa0e85678d693fd6069dd394c9b9e7d41973d74a3b5d3
|
|
||||||
|
|
||||||
define_default_value RAPIDJSON_SOURCE_VERSION "1.1.0"
|
|
||||||
define_default_value RAPIDJSON_SOURCE_SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e
|
|
||||||
|
|
||||||
define_default_value MINIUPNPC_SOURCE_VERSION "2.1.20190625"
|
|
||||||
define_default_value MINIUPNPC_SOURCE_SHA256 8723f5d7fd7970de23635547700878cd29a5c2bb708b5e5475b2d1d2510317fb
|
|
||||||
|
|
||||||
|
|
||||||
## $1 filename, $2 sha256 hash
|
|
||||||
function check_sha256()
|
|
||||||
{
|
|
||||||
echo ${2} "${1}" | sha256sum -c &> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
## $1 filename, $2 sha256 hash, $3 url
|
|
||||||
function verified_download()
|
|
||||||
{
|
|
||||||
FILENAME="$1"
|
|
||||||
SHA256="$2"
|
|
||||||
URL="$3"
|
|
||||||
|
|
||||||
check_sha256 "${FILENAME}" "${SHA256}" ||
|
|
||||||
{
|
|
||||||
rm -rf "${FILENAME}"
|
|
||||||
|
|
||||||
wget -O "${FILENAME}" "$URL" ||
|
|
||||||
{
|
|
||||||
echo "Failed downloading ${FILENAME} from $URL"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
check_sha256 "${FILENAME}" "${SHA256}" ||
|
|
||||||
{
|
|
||||||
echo "SHA256 mismatch for ${FILENAME} from ${URL} expected sha256 ${SHA256} got $(sha256sum ${FILENAME} | awk '{print $1}')"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cArch=""
|
|
||||||
eABI=""
|
|
||||||
|
|
||||||
case "${ANDROID_NDK_ARCH}" in
|
|
||||||
"arm")
|
|
||||||
cArch="${ANDROID_NDK_ARCH}"
|
|
||||||
eABI="eabi"
|
|
||||||
;;
|
|
||||||
"arm64")
|
|
||||||
cArch="aarch64"
|
|
||||||
eABI=""
|
|
||||||
;;
|
|
||||||
"x86")
|
|
||||||
cArch="i686"
|
|
||||||
eABI=""
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
export SYSROOT="${NATIVE_LIBS_TOOLCHAIN_PATH}/sysroot/"
|
|
||||||
export PREFIX="${SYSROOT}/usr/"
|
|
||||||
export CC="${NATIVE_LIBS_TOOLCHAIN_PATH}/bin/${cArch}-linux-android${eABI}-clang"
|
|
||||||
export CXX="${NATIVE_LIBS_TOOLCHAIN_PATH}/bin/${cArch}-linux-android${eABI}-clang++"
|
|
||||||
export AR="${NATIVE_LIBS_TOOLCHAIN_PATH}/bin/${cArch}-linux-android${eABI}-ar"
|
|
||||||
export RANLIB="${NATIVE_LIBS_TOOLCHAIN_PATH}/bin/${cArch}-linux-android${eABI}-ranlib"
|
|
||||||
|
|
||||||
|
|
||||||
## More information available at https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
|
|
||||||
build_toolchain()
|
|
||||||
{
|
|
||||||
echo "build_toolchain()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
rm -rf ${NATIVE_LIBS_TOOLCHAIN_PATH}
|
|
||||||
${ANDROID_NDK_PATH}/build/tools/make_standalone_toolchain.py --verbose \
|
|
||||||
--arch ${ANDROID_NDK_ARCH} --install-dir ${NATIVE_LIBS_TOOLCHAIN_PATH} \
|
|
||||||
--api ${ANDROID_PLATFORM_VER}
|
|
||||||
find "${PREFIX}/include/" -not -type d > "${NATIVE_LIBS_TOOLCHAIN_PATH}/deletefiles"
|
|
||||||
}
|
|
||||||
|
|
||||||
## This avoid <cmath> include errors due to -isystem and -I ordering issue
|
|
||||||
delete_copied_includes()
|
|
||||||
{
|
|
||||||
echo "delete_copied_includes()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
cat "${NATIVE_LIBS_TOOLCHAIN_PATH}/deletefiles" | while read delFile ; do
|
|
||||||
rm "$delFile"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
## More information available at https://gitlab.com/relan/provisioners/merge_requests/1 and http://stackoverflow.com/a/34032216
|
|
||||||
install_qt_android()
|
|
||||||
{
|
|
||||||
echo "install_qt_android()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
QT_VERSION_CODE=$(echo $QT_VERSION | tr -d .)
|
|
||||||
QT_INSTALL_PATH=${NATIVE_LIBS_TOOLCHAIN_PATH}/Qt
|
|
||||||
QT_INSTALLER="qt-unified-linux-x64-3.0.2-online.run"
|
|
||||||
|
|
||||||
verified_download $QT_INSTALLER $QT_ANDROID_INSTALLER_SHA256 \
|
|
||||||
http://master.qt.io/archive/online_installers/3.0/${QT_INSTALLER}
|
|
||||||
|
|
||||||
chmod a+x ${QT_INSTALLER}
|
|
||||||
|
|
||||||
QT_INSTALLER_SCRIPT="qt_installer_script.js"
|
|
||||||
cat << EOF > "${QT_INSTALLER_SCRIPT}"
|
|
||||||
function Controller() {
|
|
||||||
installer.autoRejectMessageBoxes();
|
|
||||||
installer.installationFinished.connect(function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
});
|
|
||||||
|
|
||||||
var welcomePage = gui.pageWidgetByObjectName("WelcomePage");
|
|
||||||
welcomePage.completeChanged.connect(function() {
|
|
||||||
if (gui.currentPageWidget().objectName == welcomePage.objectName)
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.WelcomePageCallback = function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.CredentialsPageCallback = function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.IntroductionPageCallback = function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.TargetDirectoryPageCallback = function() {
|
|
||||||
gui.currentPageWidget().TargetDirectoryLineEdit.setText("$QT_INSTALL_PATH");
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.ComponentSelectionPageCallback = function() {
|
|
||||||
var widget = gui.currentPageWidget();
|
|
||||||
|
|
||||||
// You can get these component names by running the installer with the
|
|
||||||
// --verbose flag. It will then print out a resource tree.
|
|
||||||
|
|
||||||
widget.deselectComponent("qt.tools.qtcreator");
|
|
||||||
widget.deselectComponent("qt.tools.doc");
|
|
||||||
widget.deselectComponent("qt.tools.examples");
|
|
||||||
|
|
||||||
widget.selectComponent("qt.$QT_VERSION_CODE.android_armv7");
|
|
||||||
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.LicenseAgreementPageCallback = function() {
|
|
||||||
gui.currentPageWidget().AcceptLicenseRadioButton.setChecked(true);
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.StartMenuDirectoryPageCallback = function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.ReadyForInstallationPageCallback = function() {
|
|
||||||
gui.clickButton(buttons.NextButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.prototype.FinishedPageCallback = function() {
|
|
||||||
var checkBoxForm = gui.currentPageWidget().LaunchQtCreatorCheckBoxForm;
|
|
||||||
if (checkBoxForm && checkBoxForm.launchQtCreatorCheckBox)
|
|
||||||
checkBoxForm.launchQtCreatorCheckBox.checked = false;
|
|
||||||
gui.clickButton(buttons.FinishButton);
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
QT_QPA_PLATFORM=minimal ./${QT_INSTALLER} --script ${QT_INSTALLER_SCRIPT}
|
|
||||||
}
|
|
||||||
|
|
||||||
## More information available at retroshare://file?name=Android%20Native%20Development%20Kit%20Cookbook.pdf&size=29214468&hash=0123361c1b14366ce36118e82b90faf7c7b1b136
|
|
||||||
build_bzlib()
|
|
||||||
{
|
|
||||||
echo "build_bzlib()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="bzip2-${BZIP2_SOURCE_VERSION}"
|
|
||||||
rm -rf $B_dir
|
|
||||||
|
|
||||||
verified_download $B_dir.tar.gz $BZIP2_SOURCE_SHA256 \
|
|
||||||
http://distfiles.gentoo.org/distfiles/bzip2-${BZIP2_SOURCE_VERSION}.tar.gz
|
|
||||||
|
|
||||||
tar -xf $B_dir.tar.gz
|
|
||||||
cd $B_dir
|
|
||||||
sed -i "/^CC=.*/d" Makefile
|
|
||||||
sed -i "/^AR=.*/d" Makefile
|
|
||||||
sed -i "/^RANLIB=.*/d" Makefile
|
|
||||||
sed -i "/^LDFLAGS=.*/d" Makefile
|
|
||||||
sed -i "s/^all: libbz2.a bzip2 bzip2recover test/all: libbz2.a bzip2 bzip2recover/" Makefile
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install PREFIX=${PREFIX}
|
|
||||||
# sed -i "/^CC=.*/d" Makefile-libbz2_so
|
|
||||||
# make -f Makefile-libbz2_so -j${HOST_NUM_CPU}
|
|
||||||
# cp libbz2.so.1.0.6 ${SYSROOT}/usr/lib/libbz2.so
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
## More information available at http://doc.qt.io/qt-5/opensslsupport.html
|
|
||||||
build_openssl()
|
|
||||||
{
|
|
||||||
echo "build_openssl()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="openssl-${OPENSSL_SOURCE_VERSION}"
|
|
||||||
rm -rf $B_dir
|
|
||||||
|
|
||||||
verified_download $B_dir.tar.gz $OPENSSL_SOURCE_SHA256 \
|
|
||||||
https://www.openssl.org/source/$B_dir.tar.gz
|
|
||||||
|
|
||||||
tar -xf $B_dir.tar.gz
|
|
||||||
cd $B_dir
|
|
||||||
## We link openssl statically to avoid android silently sneaking in his own
|
|
||||||
## version of libssl.so (we noticed this because it had some missing symbol
|
|
||||||
## that made RS crash), the crash in some android version is only one of the
|
|
||||||
## possible problems the fact that android insert his own binary libssl.so pose
|
|
||||||
## non neglegible security concerns.
|
|
||||||
oBits="32"
|
|
||||||
[[ ${ANDROID_NDK_ARCH} =~ .*64.* ]] && oBits=64
|
|
||||||
|
|
||||||
ANDROID_NDK="${ANDROID_NDK_PATH}" PATH="${SYSROOT}/bin/:${PATH}" \
|
|
||||||
./Configure linux-generic${oBits} -fPIC --prefix="${PREFIX}" \
|
|
||||||
--openssldir="${SYSROOT}/etc/ssl"
|
|
||||||
# sed -i 's/LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \\/LIBNAME=$$i \\/g' Makefile
|
|
||||||
# sed -i '/LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \\/d' Makefile
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
rm -f ${PREFIX}/lib/libssl.so*
|
|
||||||
rm -f ${PREFIX}/lib/libcrypto.so*
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_sqlite()
|
|
||||||
{
|
|
||||||
echo "build_sqlite()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="sqlite-autoconf-${SQLITE_SOURCE_VERSION}"
|
|
||||||
rm -rf $B_dir
|
|
||||||
|
|
||||||
verified_download $B_dir.tar.gz $SQLITE_SOURCE_SHA256 \
|
|
||||||
https://www.sqlite.org/${SQLITE_SOURCE_YEAR}/$B_dir.tar.gz
|
|
||||||
|
|
||||||
tar -xf $B_dir.tar.gz
|
|
||||||
cd $B_dir
|
|
||||||
./configure --with-pic --prefix="${PREFIX}" --host=${cArch}-linux
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
rm -f ${PREFIX}/lib/libsqlite3.so*
|
|
||||||
# ${CC} -shared -o libsqlite3.so -fPIC sqlite3.o -ldl
|
|
||||||
# cp libsqlite3.so "${SYSROOT}/usr/lib"
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_sqlcipher()
|
|
||||||
{
|
|
||||||
echo "build_sqlcipher()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="sqlcipher-${SQLCIPHER_SOURCE_VERSION}"
|
|
||||||
rm -rf $B_dir
|
|
||||||
|
|
||||||
T_file="${B_dir}.tar.gz"
|
|
||||||
|
|
||||||
verified_download $T_file $SQLCIPHER_SOURCE_SHA256 \
|
|
||||||
https://github.com/sqlcipher/sqlcipher/archive/v${SQLCIPHER_SOURCE_VERSION}.tar.gz
|
|
||||||
|
|
||||||
tar -xf $T_file
|
|
||||||
cd $B_dir
|
|
||||||
case "${ANDROID_NDK_ARCH}" in
|
|
||||||
"arm64")
|
|
||||||
# SQLCipher config.sub is outdated and doesn't recognize newer architectures
|
|
||||||
rm config.sub
|
|
||||||
autoreconf --verbose --install --force
|
|
||||||
automake --add-missing --copy --force-missing
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
./configure --with-pic --build=$(sh ./config.guess) \
|
|
||||||
--host=${cArch}-linux \
|
|
||||||
--prefix="${PREFIX}" --with-sysroot="${SYSROOT}" \
|
|
||||||
--enable-tempstore=yes \
|
|
||||||
--disable-tcl --disable-shared \
|
|
||||||
CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="${PREFIX}/lib/libcrypto.a"
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_libupnp()
|
|
||||||
{
|
|
||||||
echo "build_libupnp()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="pupnp-release-${LIBUPNP_SOURCE_VERSION}"
|
|
||||||
B_ext=".tar.gz"
|
|
||||||
B_file="${B_dir}${B_ext}"
|
|
||||||
rm -rf $B_dir
|
|
||||||
|
|
||||||
verified_download $B_file $LIBUPNP_SOURCE_SHA256 \
|
|
||||||
https://github.com/mrjimenez/pupnp/archive/release-${LIBUPNP_SOURCE_VERSION}${B_ext}
|
|
||||||
|
|
||||||
tar -xf $B_file
|
|
||||||
cd $B_dir
|
|
||||||
./bootstrap
|
|
||||||
## liupnp must be configured as static library because if not the linker will
|
|
||||||
## look for libthreadutils.so.6 at runtime that cannot be packaged on android
|
|
||||||
## as it supports only libname.so format for libraries, thus resulting in a
|
|
||||||
## crash at startup.
|
|
||||||
./configure --with-pic --enable-static --disable-shared --disable-samples \
|
|
||||||
--disable-largefile \
|
|
||||||
--prefix="${PREFIX}" --host=${cArch}-linux
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_rapidjson()
|
|
||||||
{
|
|
||||||
echo "build_rapidjson()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="rapidjson-${RAPIDJSON_SOURCE_VERSION}"
|
|
||||||
D_file="${B_dir}.tar.gz"
|
|
||||||
verified_download $D_file $RAPIDJSON_SOURCE_SHA256 \
|
|
||||||
https://github.com/Tencent/rapidjson/archive/v${RAPIDJSON_SOURCE_VERSION}.tar.gz
|
|
||||||
tar -xf $D_file
|
|
||||||
cp -r "${B_dir}/include/rapidjson/" "${PREFIX}/include/rapidjson"
|
|
||||||
}
|
|
||||||
|
|
||||||
build_restbed()
|
|
||||||
{
|
|
||||||
echo "build_restbed()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
[ -d restbed ] || git clone --depth=2000 https://github.com/Corvusoft/restbed.git
|
|
||||||
cd restbed
|
|
||||||
# git fetch --tags
|
|
||||||
# git checkout tags/${RESTBED_SOURCE_VERSION}
|
|
||||||
git checkout ${RESTBED_SOURCE_VERSION}
|
|
||||||
git submodule update --init dependency/asio
|
|
||||||
git submodule update --init dependency/catch
|
|
||||||
git submodule update --init dependency/kashmir
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
rm -rf restbed-build; mkdir restbed-build ; cd restbed-build
|
|
||||||
cmake \
|
|
||||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON BUILD_TESTS=OFF \
|
|
||||||
-DBUILD_SSL=OFF -DCMAKE_INSTALL_PREFIX="${PREFIX}" -B. -H../restbed
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
cp "${PREFIX}/library/librestbed.a" "${PREFIX}/lib/"
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_udp-discovery-cpp()
|
|
||||||
{
|
|
||||||
echo "build_udp-discovery-cpp()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
S_dir="udp-discovery-cpp"
|
|
||||||
[ -d $S_dir ] || git clone $UDP_DISCOVERY_CPP_SOURCE $S_dir
|
|
||||||
cd $S_dir
|
|
||||||
git checkout $UDP_DISCOVERY_CPP_VERSION
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
B_dir="udp-discovery-cpp-build"
|
|
||||||
rm -rf ${B_dir}; mkdir ${B_dir}; cd ${B_dir}
|
|
||||||
cmake \
|
|
||||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
|
|
||||||
-DCMAKE_INSTALL_PREFIX="${PREFIX}" -B. -H../udp-discovery-cpp
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
cp libudp-discovery.a "${PREFIX}/lib/"
|
|
||||||
cp ../$S_dir/*.hpp "${PREFIX}/include/"
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
build_xapian()
|
|
||||||
{
|
|
||||||
echo "build_xapian()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
|
|
||||||
B_dir="xapian-core-${XAPIAN_SOURCE_VERSION}"
|
|
||||||
D_file="$B_dir.tar.xz"
|
|
||||||
verified_download $D_file $XAPIAN_SOURCE_SHA256 \
|
|
||||||
https://oligarchy.co.uk/xapian/${XAPIAN_SOURCE_VERSION}/$D_file
|
|
||||||
rm -rf $B_dir
|
|
||||||
tar -xf $D_file
|
|
||||||
cd $B_dir
|
|
||||||
B_endiannes_detection_failure_workaround="ac_cv_c_bigendian=no"
|
|
||||||
B_large_file=""
|
|
||||||
[ "${ANDROID_PLATFORM_VER}" -lt "24" ] && B_large_file="--disable-largefile"
|
|
||||||
./configure ${B_endiannes_detection_failure_workaround} ${B_large_file} \
|
|
||||||
--with-pic \
|
|
||||||
--disable-backend-inmemory --disable-backend-remote \
|
|
||||||
--disable--backend-chert --enable-backend-glass \
|
|
||||||
--host=${cArch}-linux --enable-static --disable-shared \
|
|
||||||
--prefix="${PREFIX}" --with-sysroot="${SYSROOT}"
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
}
|
|
||||||
|
|
||||||
build_miniupnpc()
|
|
||||||
{
|
|
||||||
echo "build_miniupnpc()
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
################################################################################
|
|
||||||
"
|
|
||||||
S_dir="miniupnpc-${MINIUPNPC_SOURCE_VERSION}"
|
|
||||||
B_dir="miniupnpc-${MINIUPNPC_SOURCE_VERSION}-build"
|
|
||||||
D_file="$S_dir.tar.gz"
|
|
||||||
verified_download $D_file $MINIUPNPC_SOURCE_SHA256 \
|
|
||||||
http://miniupnp.free.fr/files/${D_file}
|
|
||||||
rm -rf $S_dir $B_dir
|
|
||||||
tar -xf $D_file
|
|
||||||
mkdir $B_dir
|
|
||||||
cd $B_dir
|
|
||||||
cmake \
|
|
||||||
-DUPNPC_BUILD_STATIC=TRUE \
|
|
||||||
-DUPNPC_BUILD_SHARED=FALSE \
|
|
||||||
-DUPNPC_BUILD_TESTS=FALSE \
|
|
||||||
-DUPNPC_BUILD_SAMPLE=FALSE \
|
|
||||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
|
|
||||||
-DCMAKE_INSTALL_PREFIX="${PREFIX}" -B. -S../$S_dir
|
|
||||||
make -j${HOST_NUM_CPU}
|
|
||||||
make install
|
|
||||||
}
|
|
||||||
|
|
||||||
build_toolchain
|
|
||||||
[ "${INSTALL_QT_ANDROID}X" != "trueX" ] || install_qt_android
|
|
||||||
build_bzlib
|
|
||||||
build_openssl
|
|
||||||
build_sqlite
|
|
||||||
build_sqlcipher
|
|
||||||
build_libupnp
|
|
||||||
build_rapidjson
|
|
||||||
build_restbed
|
|
||||||
build_udp-discovery-cpp
|
|
||||||
build_xapian
|
|
||||||
build_miniupnpc
|
|
||||||
delete_copied_includes
|
|
||||||
|
|
||||||
echo NATIVE_LIBS_TOOLCHAIN_PATH=${NATIVE_LIBS_TOOLCHAIN_PATH}
|
|
|
@ -1,90 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to pull debugging sysroot from Android devices
|
|
||||||
#
|
|
||||||
# Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
||||||
# Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU Affero General Public License as published by the
|
|
||||||
# Free Software Foundation, version 3.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License along
|
|
||||||
# with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
<<"ASCIIDOC"
|
|
||||||
|
|
||||||
Pull files from Android device to prepare a debugging sysroot
|
|
||||||
Inspired by:
|
|
||||||
https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html
|
|
||||||
|
|
||||||
The goal is to have a local copy of the sysroot of the connected device.
|
|
||||||
For that we use the command `adb pull <remote_dir_or_file> <local_dir_or_file>`
|
|
||||||
|
|
||||||
We will get a copy of:
|
|
||||||
|
|
||||||
- `/system/lib/`
|
|
||||||
- `/vendor/lib/`
|
|
||||||
- `libc.so`
|
|
||||||
- `libcutils.so`
|
|
||||||
|
|
||||||
As well as the binaries `linker` and `app_process`
|
|
||||||
|
|
||||||
IMPORTANT:
|
|
||||||
from one device to another, the remote file `app_process` can be a binary file
|
|
||||||
or a symlink to a binary file - which is NOT ok for us.
|
|
||||||
That's so we will try to pull every known possible variants of `app_process`,
|
|
||||||
e.g. `app_process32` or `app_process_init`
|
|
||||||
|
|
||||||
ASCIIDOC
|
|
||||||
|
|
||||||
|
|
||||||
## Define default value for variable, take two arguments, $1 variable name,
|
|
||||||
## $2 default variable value, if the variable is not already define define it
|
|
||||||
## with default value.
|
|
||||||
function define_default_value()
|
|
||||||
{
|
|
||||||
VAR_NAME="${1}"
|
|
||||||
DEFAULT_VALUE="${2}"
|
|
||||||
|
|
||||||
[ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
define_default_value ANDROID_SERIAL "$(adb devices | head -n 2 | tail -n 1 | awk '{print $1}')"
|
|
||||||
define_default_value DEBUG_SYSROOT "${HOME}/Builds/debug_sysroot/${ANDROID_SERIAL}/"
|
|
||||||
|
|
||||||
rm -rf "${DEBUG_SYSROOT}"
|
|
||||||
|
|
||||||
for mDir in "/system/lib/" "/vendor/lib/"; do
|
|
||||||
mkdir -p "${DEBUG_SYSROOT}/${mDir}"
|
|
||||||
# adb pull doesn't behave like rsync dirA/ dirB/ so avoid nesting the
|
|
||||||
# directory by deleting last one before copying
|
|
||||||
rmdir "${DEBUG_SYSROOT}/${mDir}"
|
|
||||||
adb pull "${mDir}" "${DEBUG_SYSROOT}/${mDir}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Retrieve the specific binaries - some of these adb commands will fail, since
|
|
||||||
# some files may not exist, but that's ok.
|
|
||||||
|
|
||||||
mkdir -p "${DEBUG_SYSROOT}/system/bin/"
|
|
||||||
for mBin in "/system/bin/linker" "/system/bin/app_process" \
|
|
||||||
"/system/bin/app_process_init" "/system/bin/app_process32" \
|
|
||||||
"/system/bin/app_process64" ; do
|
|
||||||
adb pull "${mBin}" "${DEBUG_SYSROOT}/${mBin}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Verify which variants of the specific binaries could be pulled
|
|
||||||
echo
|
|
||||||
echo "Found the following specific binaries:"
|
|
||||||
echo
|
|
||||||
ls -1 "${DEBUG_SYSROOT}/system/bin/"*
|
|
||||||
ls -1 "${DEBUG_SYSROOT}/system/lib/libc.so"*
|
|
||||||
ls -1 "${DEBUG_SYSROOT}/system/lib/libcutils.so"*
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo DEBUG_SYSROOT="${DEBUG_SYSROOT}"
|
|
|
@ -1,116 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to start gdbserver on Android device and attach to retroshare-service
|
|
||||||
#
|
|
||||||
# Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
||||||
# Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU Affero General Public License as published by the
|
|
||||||
# Free Software Foundation, version 3.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
# See the GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License along
|
|
||||||
# with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
<<"ASCIIDOC"
|
|
||||||
|
|
||||||
Start gdbserver on Android device and attach it to the retroshare service
|
|
||||||
process
|
|
||||||
|
|
||||||
Inspired by:
|
|
||||||
https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html
|
|
||||||
|
|
||||||
ASCIIDOC
|
|
||||||
|
|
||||||
|
|
||||||
## Define default value for variable, take two arguments, $1 variable name,
|
|
||||||
## $2 default variable value, if the variable is not already define define it
|
|
||||||
## with default value.
|
|
||||||
function define_default_value()
|
|
||||||
{
|
|
||||||
VAR_NAME="${1}"
|
|
||||||
DEFAULT_VALUE="${2}"
|
|
||||||
|
|
||||||
[ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
define_default_value ANDROID_APK_PACKAGE "org.retroshare.service"
|
|
||||||
define_default_value ANDROID_PROCESS_NAME "org.retroshare.service:rs"
|
|
||||||
define_default_value ANDROID_INSTALL_PATH ""
|
|
||||||
define_default_value LIB_GDB_SERVER_PATH ""
|
|
||||||
define_default_value ANDROID_SERIAL "$(adb devices | head -n 2 | tail -n 1 | awk '{print $1}')"
|
|
||||||
define_default_value GDB_SERVER_PORT 5039
|
|
||||||
|
|
||||||
adb_ushell()
|
|
||||||
{
|
|
||||||
adb shell run-as ${ANDROID_APK_PACKAGE} $@
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -z "${ANDROID_INSTALL_PATH}" ] &&
|
|
||||||
{
|
|
||||||
ANDROID_INSTALL_PATH="$(adb_ushell pm path "${ANDROID_APK_PACKAGE}")"
|
|
||||||
ANDROID_INSTALL_PATH="$(dirname ${ANDROID_INSTALL_PATH#"package:"})"
|
|
||||||
[ -z "${ANDROID_INSTALL_PATH}" ] &&
|
|
||||||
cat <<EOF
|
|
||||||
Cannot find install path for ${ANDROID_APK_PACKAGE} make sure it is installed,
|
|
||||||
or manually specify ANDROID_INSTALL_PATH
|
|
||||||
|
|
||||||
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
## If not passed as environement variable try to determine gdbserver path
|
|
||||||
## shipped withing APK
|
|
||||||
[ -z "${LIB_GDB_SERVER_PATH}" ] &&
|
|
||||||
{
|
|
||||||
|
|
||||||
for mUsualPath in \
|
|
||||||
"${ANDROID_INSTALL_PATH}/lib/libgdbserver.so" \
|
|
||||||
"${ANDROID_INSTALL_PATH}/lib/arm64/libgdbserver.so"
|
|
||||||
do
|
|
||||||
adb_ushell ls "${mUsualPath}" &&
|
|
||||||
export LIB_GDB_SERVER_PATH="${mUsualPath}" && break
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -z "${LIB_GDB_SERVER_PATH}" ] &&
|
|
||||||
{
|
|
||||||
cat <<EOF
|
|
||||||
libgdbserver.so not found in any of the usual path attempting to look for it
|
|
||||||
with find, it will take a little more time. Take note of the discovered path and
|
|
||||||
define LIB_GDB_SERVER_PATH on your commandline at next run to avoid waiting
|
|
||||||
again.
|
|
||||||
|
|
||||||
|
|
||||||
EOF
|
|
||||||
tFile="$(mktemp)"
|
|
||||||
adb_ushell find ${ANDROID_INSTALL_PATH} -type f -name 'libgdbserver.so' | \
|
|
||||||
tee "${tFile}"
|
|
||||||
|
|
||||||
LIB_GDB_SERVER_PATH="$(head -n 1 "${tFile}")"
|
|
||||||
rm "${tFile}"
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -z "${LIB_GDB_SERVER_PATH}" ] &&
|
|
||||||
{
|
|
||||||
echo "Cannot find libgdbserver.so, are you sure your package ships it?"
|
|
||||||
exit -1
|
|
||||||
}
|
|
||||||
|
|
||||||
mPid="$(adb_ushell ps | grep ${ANDROID_PROCESS_NAME} | awk '{print $2}')"
|
|
||||||
[ -z "${mPid}" ] &&
|
|
||||||
{
|
|
||||||
echo "Failed ${ANDROID_PROCESS_NAME} PID retrival are you sure it is running?"
|
|
||||||
exit -2
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## Establish port forwarding so we can connect to gdbserver with gdb
|
|
||||||
adb forward tcp:${GDB_SERVER_PORT} tcp:${GDB_SERVER_PORT}
|
|
||||||
|
|
||||||
((adb_ushell ${LIB_GDB_SERVER_PATH} 127.0.0.1:${GDB_SERVER_PORT} --attach ${mPid})&)
|
|
48
build_scripts/GitlabCI/Android.Dockerfile
Normal file
48
build_scripts/GitlabCI/Android.Dockerfile
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
ARG ANDROID_NDK_ARCH=arm
|
||||||
|
FROM registry.gitlab.com/retroshare/retroshare:android_${ANDROID_NDK_ARCH}_base
|
||||||
|
|
||||||
|
ENV APT_UNAT="--assume-yes --quiet"
|
||||||
|
|
||||||
|
RUN apt-get update $APT_UNAT && apt-get upgrade $APT_UNAT --show-upgraded
|
||||||
|
|
||||||
|
ARG REPO_URL=https://gitlab.com/RetroShare/RetroShare.git
|
||||||
|
ARG REPO_BRANCH=master
|
||||||
|
|
||||||
|
WORKDIR /RetroShare
|
||||||
|
RUN git remote add testing $REPO_URL && \
|
||||||
|
git fetch --tags testing $REPO_BRANCH && \
|
||||||
|
git reset --hard testing/$REPO_BRANCH && \
|
||||||
|
git --no-pager log --max-count 1
|
||||||
|
|
||||||
|
RUN rm -rf /jsonapi-generator-build ; mkdir /jsonapi-generator-build
|
||||||
|
WORKDIR /jsonapi-generator-build/
|
||||||
|
RUN qmake ../RetroShare/jsonapi-generator/src/ \
|
||||||
|
CONFIG+=no_retroshare_plugins \
|
||||||
|
CONFIG+=no_retroshare_service CONFIG+=no_retroshare_gui \
|
||||||
|
CONFIG+=rs_jsonapi CONFIG+=no_rs_sam3_libsam3 && \
|
||||||
|
make -j$(nproc)
|
||||||
|
|
||||||
|
RUN rm -rf /retroshare-service-android-build ; mkdir /retroshare-service-android-build
|
||||||
|
WORKDIR /retroshare-service-android-build
|
||||||
|
|
||||||
|
# ARG declared before FROM get wiped after it, so we need declaring it again
|
||||||
|
ARG ANDROID_NDK_ARCH=arm
|
||||||
|
ARG RS_SERVICE_QMAKE_EXTRA_OPTS
|
||||||
|
RUN $($PREPARE_TOOLCHAIN get_qt_dir | head -n 1)/bin/qmake ../RetroShare \
|
||||||
|
-spec android-clang \
|
||||||
|
CONFIG+=retroshare_service CONFIG+=rs_jsonapi \
|
||||||
|
RS_UPNP_LIB=miniupnpc \
|
||||||
|
JSONAPI_GENERATOR_EXE=/jsonapi-generator-build/jsonapi-generator \
|
||||||
|
NATIVE_LIBS_TOOLCHAIN_PATH=$NATIVE_LIBS_TOOLCHAIN_PATH \
|
||||||
|
CONFIG+=no_retroshare_gui CONFIG+=no_rs_service_webui_terminal_password \
|
||||||
|
CONFIG+=no_rs_service_terminal_login \
|
||||||
|
CONFIG+=no_rs_sam3 CONFIG+=no_rs_sam3_libsam3 \
|
||||||
|
$RS_SERVICE_QMAKE_EXTRA_OPTS
|
||||||
|
RUN make -j$(nproc)
|
||||||
|
RUN make install INSTALL_ROOT=/retroshare-service-android-build/android-build/
|
||||||
|
|
||||||
|
ARG ANDROID_PLATFORM_VER=16
|
||||||
|
RUN $($PREPARE_TOOLCHAIN get_qt_dir | head -n 1)/bin/androiddeployqt \
|
||||||
|
--input retroshare-service/src/android-libretroshare-service.so-deployment-settings.json \
|
||||||
|
--output android-build --android-platform android-$ANDROID_PLATFORM_VER \
|
||||||
|
--jdk $JAVA_HOME --gradle
|
|
@ -2,42 +2,56 @@
|
||||||
## force cloning a new
|
## force cloning a new
|
||||||
|
|
||||||
## To prepare an image suitable as base for Gitlab CI use
|
## To prepare an image suitable as base for Gitlab CI use
|
||||||
# docker build -t "${CI_REGISTRY_IMAGE}:base" --build-arg KEEP_SOURCE=true --build-arg REPO_DEPTH="" -f base.Dockerfile .
|
# export CI_REGISTRY_IMAGE="registry.gitlab.com/retroshare/retroshare:base"
|
||||||
|
# docker build -t "${CI_REGISTRY_IMAGE}" -f base.Dockerfile .
|
||||||
## Now you need to tag it so you can later push it
|
|
||||||
# docker tag ${ID_OF_THE_CREATED_IMAGE} registry.gitlab.com/retroshare/${CI_REGISTRY_IMAGE}:base
|
|
||||||
|
|
||||||
## To push it to gitlab CI registry you need first to login and the to push
|
## To push it to gitlab CI registry you need first to login and the to push
|
||||||
# docker login registry.gitlab.com
|
# docker login registry.gitlab.com
|
||||||
# docker push registry.gitlab.com/retroshare/${CI_REGISTRY_IMAGE}:base
|
# docker push "${CI_REGISTRY_IMAGE}"
|
||||||
|
|
||||||
|
|
||||||
## To run the container
|
## To run the container
|
||||||
# docker run -it -p 127.0.0.1:9092:9092 "${CI_REGISTRY_IMAGE}:base" retroshare-service --jsonApiPort 9092 --jsonApiBindAddress 0.0.0.0
|
# docker run -it -p 127.0.0.1:9092:9092 "${CI_REGISTRY_IMAGE}" retroshare-service --jsonApiPort 9092 --jsonApiBindAddress 0.0.0.0
|
||||||
|
|
||||||
FROM ubuntu
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
ARG CACHEBUST=0
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
RUN \
|
ENV APT_UNAT="--assume-yes --quiet"
|
||||||
apt-get update -y && apt-get upgrade -y && \
|
|
||||||
apt-get install -y build-essential libssl-dev libbz2-dev libsqlite3-dev \
|
RUN apt-get update $APT_UNAT && \
|
||||||
libsqlcipher-dev libupnp-dev pkg-config libz-dev \
|
apt-get upgrade --show-upgraded $APT_UNAT && \
|
||||||
qt5-default libxapian-dev qttools5-dev doxygen rapidjson-dev \
|
apt-get clean $APT_UNAT && \
|
||||||
git cmake curl
|
apt-get install --no-install-recommends $APT_UNAT \
|
||||||
|
bash build-essential cimg-dev libssl-dev libbz2-dev \
|
||||||
|
libminiupnpc-dev \
|
||||||
|
libsqlite3-dev libsqlcipher-dev \
|
||||||
|
pkg-config libz-dev \
|
||||||
|
libxapian-dev doxygen rapidjson-dev \
|
||||||
|
git cmake curl python3
|
||||||
|
|
||||||
|
## Avoid git cloning spuriously failing with
|
||||||
|
# server certificate verification failed. CAfile: none CRLfile: none
|
||||||
|
RUN apt-get install --no-install-recommends $APT_UNAT --reinstall \
|
||||||
|
ca-certificates
|
||||||
|
|
||||||
|
RUN git clone --depth 1 https://github.com/aetilius/pHash.git && \
|
||||||
|
rm -rf pHash-build && mkdir pHash-build && cd pHash-build && \
|
||||||
|
cmake -B. -H../pHash -DCMAKE_INSTALL_PREFIX=/usr && \
|
||||||
|
make -j$(nproc) && make install && cd .. && \
|
||||||
|
rm -rf pHash-build pHash
|
||||||
|
|
||||||
ARG FRESHCLONE=0
|
ARG FRESHCLONE=0
|
||||||
ARG REPO_URL=https://gitlab.com/RetroShare/RetroShare.git
|
ARG REPO_URL=https://gitlab.com/RetroShare/RetroShare.git
|
||||||
ARG REPO_BRANCH=master
|
ARG REPO_BRANCH=master
|
||||||
ARG REPO_DEPTH="--depth 2000"
|
ARG REPO_DEPTH="--depth 2000"
|
||||||
ARG KEEP_SOURCE=false
|
|
||||||
RUN apt-get update -y && apt-get upgrade -y
|
|
||||||
RUN git clone $REPO_DEPTH $REPO_URL -b $REPO_BRANCH && cd RetroShare && \
|
RUN git clone $REPO_DEPTH $REPO_URL -b $REPO_BRANCH && cd RetroShare && \
|
||||||
git fetch --tags && cd ..
|
git fetch --tags && \
|
||||||
|
git submodule update --init --remote --force \
|
||||||
|
libbitdht/ libretroshare/ openpgpsdk/ && \
|
||||||
|
cd ..
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
mkdir RetroShare-build && cd RetroShare-build && \
|
mkdir RetroShare-build && cd RetroShare-build && \
|
||||||
qmake ../RetroShare \
|
cmake -B. -S../RetroShare/retroshare-service \
|
||||||
CONFIG+=no_retroshare_plugins CONFIG+=ipv6 \
|
-DRS_FORUM_DEEP_INDEX=ON -DRS_JSON_API=ON && \
|
||||||
CONFIG+=retroshare_service CONFIG+=no_retroshare_gui \
|
make -j$(nproc) && make install && \
|
||||||
CONFIG+=rs_jsonapi CONFIG+=rs_deep_search && \
|
cd .. && rm -rf RetroShare-build
|
||||||
(make -j$(nproc) || make -j$(nproc) || make) && make install && \
|
|
||||||
cd .. && rm -rf RetroShare-build && ($KEEP_SOURCE || rm -rf RetroShare)
|
|
||||||
|
|
9
build_scripts/GitlabCI/getRepoArgs.sh
Executable file
9
build_scripts/GitlabCI/getRepoArgs.sh
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
[ -n "$CI_MERGE_REQUEST_ID" ] &&
|
||||||
|
echo \
|
||||||
|
--build-arg REPO_URL="$CI_MERGE_REQUEST_SOURCE_PROJECT_URL" \
|
||||||
|
--build-arg REPO_BRANCH="$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" ||
|
||||||
|
echo \
|
||||||
|
--build-arg REPO_URL="$CI_REPOSITORY_URL" \
|
||||||
|
--build-arg REPO_BRANCH="$CI_COMMIT_BRANCH"
|
|
@ -8,11 +8,13 @@ RUN \
|
||||||
cd RetroShare && git remote add testing $REPO_URL && \
|
cd RetroShare && git remote add testing $REPO_URL && \
|
||||||
git fetch --tags testing $REPO_BRANCH && \
|
git fetch --tags testing $REPO_BRANCH && \
|
||||||
git reset --hard testing/$REPO_BRANCH && \
|
git reset --hard testing/$REPO_BRANCH && \
|
||||||
|
git submodule update --init --remote --force \
|
||||||
|
libbitdht/ libretroshare/ openpgpsdk/ && \
|
||||||
git --no-pager log --max-count 1
|
git --no-pager log --max-count 1
|
||||||
RUN \
|
RUN \
|
||||||
mkdir RetroShare-build && cd RetroShare-build && \
|
mkdir RetroShare-build && cd RetroShare-build && \
|
||||||
qmake ../RetroShare CONFIG+=no_retroshare_gui \
|
cmake -B. -S../RetroShare/retroshare-service \
|
||||||
CONFIG+=retroshare_service \
|
-DRS_FORUM_DEEP_INDEX=ON -DRS_JSON_API=ON \
|
||||||
CONFIG+=rs_jsonapi CONFIG+=rs_deep_search && \
|
-DRS_WARN_DEPRECATED=OFF -DRS_WARN_LESS=ON && \
|
||||||
(make -j$(nproc) || make -j$(nproc) || make) && make install && \
|
make -j$(nproc) && make install && \
|
||||||
cd .. && rm -rf RetroShare-build
|
cd .. && rm -rf RetroShare-build
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b0d7ae39fe9d9192848bbf7b8902d2188da895c9
|
Subproject commit df16cb915465d058c75277678799ce4dadeae287
|
|
@ -1,60 +0,0 @@
|
||||||
Hi there,
|
|
||||||
|
|
||||||
I heard about RetroShare recently (on Slashdot) and really like the goal of the program; it's something I've been wanting for a long time now. I'm a software developer so I figured I could help contribute to the project. I started by getting a build up and running on my mac, which was non-trivial as it looks like the Mac build hasn't been maintained (or maybe it's just targetting older OS X version?). Anyway, I have instructions and patches to get a build going on OS X 10.6, if you want to put them up on the wiki or something. The steps I used boiled down to running the following commands in a directory that also contains the retroshare-mac-build.patch file, which I posted at https://staktrace.com/pub/retroshare-mac-build.patch (you can also see the changes at https://github.com/staktrace/retroshare/commit/51f554f909086f4baca7be215d5edacab744dea4)
|
|
||||||
|
|
||||||
sudo port selfupdate
|
|
||||||
sudo port install qt4-mac
|
|
||||||
sudo port install wget
|
|
||||||
|
|
||||||
wget ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.10.tar.bz2
|
|
||||||
tar xjf libgpg-error-1.10.tar.bz2
|
|
||||||
rm libgpg-error-1.10.tar.bz2
|
|
||||||
pushd libgpg-error-1.10
|
|
||||||
./configure --prefix=$PWD/build --enable-static=yes --enable-shared=no
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
popd
|
|
||||||
|
|
||||||
wget ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-1.3.1.tar.bz2
|
|
||||||
tar xjf gpgme-1.3.1.tar.bz2
|
|
||||||
rm gpgme-1.3.1.tar.bz2
|
|
||||||
pushd gpgme-1.3.1
|
|
||||||
./configure --prefix=$PWD/build --enable-static=yes --enable-shared=no --with-gpg-error-prefix=$PWD/../libgpg-error-1.10/build
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
popd
|
|
||||||
|
|
||||||
wget http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.3.tar.gz
|
|
||||||
tar xzf miniupnpc-1.3.tar.gz
|
|
||||||
rm miniupnpc-1.3.tar.gz
|
|
||||||
pushd miniupnpc-1.3
|
|
||||||
make upnpc-static
|
|
||||||
popd
|
|
||||||
|
|
||||||
git clone https://github.com/kigeia/retroshare
|
|
||||||
pushd retroshare
|
|
||||||
git apply ../retroshare-mac-build.patch
|
|
||||||
popd
|
|
||||||
|
|
||||||
pushd retroshare/libbitdht/src
|
|
||||||
qmake
|
|
||||||
make
|
|
||||||
popd
|
|
||||||
|
|
||||||
pushd retroshare/libretroshare/src
|
|
||||||
qmake
|
|
||||||
make
|
|
||||||
popd
|
|
||||||
|
|
||||||
pushd retroshare/retroshare-gui/src
|
|
||||||
qmake
|
|
||||||
make
|
|
||||||
popd
|
|
||||||
|
|
||||||
At the end there is a RetroShare.App in the retroshare/retroshare-gui/ folder which seems to work as expected.
|
|
||||||
|
|
||||||
Now that I've gotten it building and working, I'd like to start working on adding features. One that I would like to see is taking advantage of the RetroShare platform to enable F2F games. A while back I wrote a P2P collaborative crossword solver app in Java; porting that to work as a RetroShare plugin would probably be a good start for me. I looked briefly at the existing plugins in the source tree but haven't yet had time to peruse the rsplugin.h API in detail; if you have any tips or pointers before I dive in, please do let me know. I'll probably start work on it in a couple of days and progress might be a little slow because I'm also fairly busy with other things right now.
|
|
||||||
|
|
||||||
Cheers,
|
|
||||||
kats
|
|
||||||
|
|
|
@ -8,10 +8,28 @@ Use default options. And add Qt Script support.
|
||||||
|
|
||||||
Add to the PATH environment variable by editing your *~/.profile* file.
|
Add to the PATH environment variable by editing your *~/.profile* file.
|
||||||
|
|
||||||
export PATH="/users/$USER/Qt/5.5/clang_64/bin:$PATH"
|
export PATH="/users/$USER/Qt/5.14.1/clang_64/bin:$PATH"
|
||||||
|
|
||||||
Depends on which version of Qt you use.
|
Depends on which version of Qt you use.
|
||||||
|
|
||||||
|
## Get RetroShare
|
||||||
|
|
||||||
|
In Qt Creator Projects -> New -> Import Project -> Git Clone -> Choose
|
||||||
|
Add Repository and Continoue
|
||||||
|
|
||||||
|
Repository: https://github.com/RetroShare/RetroShare.git
|
||||||
|
|
||||||
|
via Terminal:
|
||||||
|
|
||||||
|
cd <your development directory>
|
||||||
|
git clone https://github.com/RetroShare/RetroShare.git retroshare
|
||||||
|
|
||||||
|
via GitHub Desktop: [GitHub Desktop Download](https://central.github.com/deployments/desktop/desktop/latest/darwin)
|
||||||
|
|
||||||
|
In GitHub Desktop -> Clone Repository -> URL
|
||||||
|
|
||||||
|
Add Repository URL: https://github.com/RetroShare/RetroShare.git and Clone
|
||||||
|
|
||||||
## ***Choose if you use MacPort or HomeBrew***
|
## ***Choose if you use MacPort or HomeBrew***
|
||||||
|
|
||||||
### MacPort Installation
|
### MacPort Installation
|
||||||
|
@ -22,15 +40,16 @@ Start XCode to get it updated and to able C compiler to create executables.
|
||||||
|
|
||||||
#### Install libraries
|
#### Install libraries
|
||||||
|
|
||||||
$sudo port -v selfupdate
|
$ sudo port -v selfupdate
|
||||||
$sudo port install openssl
|
$ sudo port install openssl
|
||||||
$sudo port install miniupnpc
|
$ sudo port install miniupnpc
|
||||||
$sudo port install libmicrohttpd
|
$ sudo port install libmicrohttpd
|
||||||
|
|
||||||
For VOIP Plugin:
|
For VOIP Plugin:
|
||||||
|
|
||||||
$sudo port install speex-devel
|
$ sudo port install speex-devel
|
||||||
$sudo port install opencv
|
$ sudo port install opencv
|
||||||
|
$ sudo port install ffmpeg
|
||||||
|
|
||||||
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
|
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
|
||||||
|
|
||||||
|
@ -46,9 +65,11 @@ Start XCode to get it updated and to able C compiler to create executables.
|
||||||
|
|
||||||
#### Install libraries
|
#### Install libraries
|
||||||
|
|
||||||
$brew install openssl
|
$ brew install openssl
|
||||||
$brew install miniupnpc
|
$ brew install miniupnpc
|
||||||
$brew install libmicrohttpd
|
$ brew install libmicrohttpd
|
||||||
|
$ brew install rapidjson
|
||||||
|
$ brew install sqlcipher
|
||||||
|
|
||||||
If you have error in linking, run this:
|
If you have error in linking, run this:
|
||||||
|
|
||||||
|
@ -56,37 +77,99 @@ If you have error in linking, run this:
|
||||||
|
|
||||||
For VOIP Plugin:
|
For VOIP Plugin:
|
||||||
|
|
||||||
$brew install speex
|
$ brew install speex
|
||||||
$brew install speexdsp
|
$ brew install speexdsp
|
||||||
$brew install homebrew/science/opencv
|
$ brew install opencv
|
||||||
$brew install ffmpeg
|
$ brew install ffmpeg
|
||||||
|
|
||||||
|
For FeedReader Plugin:
|
||||||
|
|
||||||
|
$ brew install libxslt
|
||||||
|
|
||||||
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
|
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
|
||||||
|
|
||||||
## Last Settings
|
## Last Settings
|
||||||
|
|
||||||
In QtCreator Option Git select "Pull" with "Rebase"
|
In QtCreator Projects -> Manage Kits > Version Control > Git:
|
||||||
|
|
||||||
## Compil missing libraries
|
select "Pull with rebase"
|
||||||
### SQLCipher
|
|
||||||
|
|
||||||
cd <your development directory>
|
In QtCreator Projects -> Build -> Build Settings -> Build Environment -> Add this path:
|
||||||
git clone https://github.com/sqlcipher/sqlcipher.git
|
|
||||||
cd sqlcipher
|
|
||||||
./configure --disable-shared --disable-tcl --enable-static --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I/opt/local/include" LDFLAGS="-lcrypto"
|
|
||||||
make
|
|
||||||
sudo make install
|
|
||||||
|
|
||||||
NOTE, might be necessary to *chmod 000 /usr/local/ssl* temporarily during *./configure* if
|
/usr/local/bin
|
||||||
homebrew uses newer, non-stock ssl dependencies found there. Configure might get confused.
|
|
||||||
|
|
||||||
You can now compile RS into Qt Creator or with terminal
|
In QtCreator Projects -> Build -> Build Settings -> Build Steps -> Add Additional arguments:
|
||||||
|
|
||||||
|
"CONFIG+=rs_autologin" "CONFIG+=rs_use_native_dialogs"
|
||||||
|
|
||||||
|
## Set your Mac OS SDK version
|
||||||
|
|
||||||
|
Edit RetroShare.pro
|
||||||
|
|
||||||
|
CONFIG += c++14 rs_macos11.1
|
||||||
|
|
||||||
|
and then retroshare.pri
|
||||||
|
|
||||||
|
macx:CONFIG *= rs_macos11.1
|
||||||
|
rs_macos10.8:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.9:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.10:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.12:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.13:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.14:CONFIG -= rs_macos11.1
|
||||||
|
rs_macos10.15:CONFIG -= rs_macos11.1
|
||||||
|
|
||||||
|
|
||||||
|
## Link Include & Libraries
|
||||||
|
|
||||||
|
Edit your retroshare.pri and add to macx-* section
|
||||||
|
|
||||||
|
INCLUDEPATH += "/usr/local/opt/openssl/include"
|
||||||
|
QMAKE_LIBDIR += "/usr/local/opt/openssl/lib"
|
||||||
|
QMAKE_LIBDIR += "/usr/local/opt/sqlcipher/lib"
|
||||||
|
QMAKE_LIBDIR += "/usr/local/opt/miniupnpc/lib"
|
||||||
|
|
||||||
|
alternative via Terminal
|
||||||
|
|
||||||
|
$ qmake INCLUDEPATH+="/usr/local/opt/openssl/include" QMAKE_LIBDIR+="/usr/local/opt/openssl/lib" QMAKE_LIBDIR+="/usr/local/opt/sqlcipher/lib" QMAKE_LIBDIR+="/usr/local/opt/miniupnpc/lib"
|
||||||
|
|
||||||
|
For FeedReader Plugin:
|
||||||
|
|
||||||
|
INCLUDEPATH += "/usr/local/opt/libxml2/include/libxml2"
|
||||||
|
|
||||||
|
For building RetroShare with plugins:
|
||||||
|
|
||||||
|
$ qmake \
|
||||||
|
INCLUDEPATH+="/usr/local/opt/openssl/include" QMAKE_LIBDIR+="/usr/local/opt/openssl/lib" \
|
||||||
|
QMAKE_LIBDIR+="/usr/local/opt/sqlcipher/lib" \
|
||||||
|
QMAKE_LIBDIR+="/usr/local/opt/miniupnpc/lib" \
|
||||||
|
INCLUDEPATH+="/usr/local/opt/opencv/include/opencv4" QMAKE_LIBDIR+="/usr/local/opt/opencv/lib" \
|
||||||
|
INCLUDEPATH+="/usr/local/opt/speex/include" QMAKE_LIBDIR+="/usr/local/opt/speex/lib/" \
|
||||||
|
INCLUDEPATH+="/usr/local/opt/speexdsp/include" QMAKE_LIBDIR+="/usr/local/opt/speexdsp/lib/" \
|
||||||
|
INCLUDEPATH+="/usr/local/opt/libxslt/include" QMAKE_LIBDIR+="/usr/local/opt/libxslt/lib" \
|
||||||
|
QMAKE_LIBDIR+="/usr/local/opt/ffmpeg/lib" \
|
||||||
|
LIBS+=-lopencv_videoio \
|
||||||
|
CONFIG+=retroshare_plugins \
|
||||||
|
CONFIG+=rs_autologin \
|
||||||
|
CONFIG+=rs_use_native_dialogs \
|
||||||
|
CONFIG+=release \
|
||||||
|
..
|
||||||
|
|
||||||
|
## Compile RetroShare
|
||||||
|
|
||||||
|
You can now compile RetroShare into Qt Creator or with Terminal
|
||||||
|
|
||||||
cd <your development directory>
|
|
||||||
git clone https://github.com/RetroShare/RetroShare.git retroshare
|
|
||||||
cd retroshare
|
cd retroshare
|
||||||
qmake; make
|
qmake; make
|
||||||
|
|
||||||
You can change Target and SDK in *./retroshare.pri:82* changing value of QMAKE_MACOSX_DEPLOYMENT_TARGET and QMAKE_MAC_SDK
|
You can change Target and SDK in *./retroshare.pri:82* changing value of QMAKE_MACOSX_DEPLOYMENT_TARGET and QMAKE_MAC_SDK
|
||||||
|
|
||||||
You can find compiled application on *./retroshare/retroshare-gui/src/retroshare.app*
|
You can find the compiled application at *./retroshare/retroshare-gui/src/retroshare.app*
|
||||||
|
|
||||||
|
## Copy Plugins
|
||||||
|
|
||||||
|
$ cp \
|
||||||
|
./plugins/FeedReader/lib/libFeedReader.dylib \
|
||||||
|
./plugins/VOIP/lib/libVOIP.dylib \
|
||||||
|
./plugins/RetroChess/lib/libRetroChess.dylib \
|
||||||
|
./retroshare-gui/src/RetroShare.app/Contents/Resources/
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
|
|
||||||
Mac OSX Build Instructions.
|
|
||||||
-------------------------------------------
|
|
||||||
|
|
||||||
There are several complications with building Retroshare under OSX.
|
|
||||||
1) Support Libraries must be built and installed seperately.
|
|
||||||
2) Universal and OSX 10.5 support is a little tricky, mainly due to the support libraries.
|
|
||||||
|
|
||||||
Additional Libraries
|
|
||||||
---------------------
|
|
||||||
|
|
||||||
* GnuPG Package, that comes with Retroshare OSX install image. (GnuPG-1.4.9.dmg)
|
|
||||||
|
|
||||||
GPG Development libraries
|
|
||||||
* libassuan (I'm using 2.0.1)
|
|
||||||
* libgpg-error (I'm using 1.9)
|
|
||||||
* libgpgme (I'm using 1.3.0)
|
|
||||||
|
|
||||||
These libraries use standard UNIX installation systems: AUTOCONF/AUTOMAKE (configure, make, etc)
|
|
||||||
Unfortunately, this makes it difficult and a little manual to compile Universal and 10.5 libraries.
|
|
||||||
|
|
||||||
UPNPC (for OSX and windows)
|
|
||||||
* miniupnpc (I'm using 1.0)
|
|
||||||
|
|
||||||
You will also need to install
|
|
||||||
* XCode (available on the Apple Install CDs)
|
|
||||||
* Qt4 (from trolltech.com)
|
|
||||||
|
|
||||||
First Compilation...
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
The First challenge is to build Retroshare on your Mac. For this first compilation,
|
|
||||||
we only build for your specific machine, and not attempt a Generic / 10.5 / Univeral build.
|
|
||||||
|
|
||||||
|
|
||||||
1) Install / Compile all the packages listed above.
|
|
||||||
be sure to use a configure command like this where applicable to only create a static library.
|
|
||||||
./configure --enable-static=yes --enable-shared=no CFLAGS="-arch i386" CPPFLAGS="-arch i386"
|
|
||||||
|
|
||||||
2) Check out the Retroshare SVN.
|
|
||||||
|
|
||||||
3) compile libbitdht:
|
|
||||||
cd libbitdht/src
|
|
||||||
qmake
|
|
||||||
|
|
||||||
This recreates a xcodeproj file for compilation using XCode.
|
|
||||||
Open with Xcode, and build.
|
|
||||||
|
|
||||||
4) compile libretroshare: same way.
|
|
||||||
5) compile retroshare-gui: same way.
|
|
||||||
|
|
||||||
|
|
||||||
Creating Retroshare OSX Distribution Packages.
|
|
||||||
-----------------------------------------------
|
|
||||||
TODO, once I've got feedback on First Compilation!
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
commit 51f554f909086f4baca7be215d5edacab744dea4
|
|
||||||
Author: Kartikaya Gupta <kats@calvin.staktrace.com>
|
|
||||||
Date: Wed Mar 7 23:30:48 2012 -0500
|
|
||||||
|
|
||||||
Modifications needed to get build working on Mac OS X 10.6
|
|
||||||
|
|
||||||
diff --git a/.gitignore b/.gitignore
|
|
||||||
new file mode 100644
|
|
||||||
index 0000000..3e90033
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/.gitignore
|
|
||||||
@@ -0,0 +1,6 @@
|
|
||||||
+*.o
|
|
||||||
+Makefile
|
|
||||||
+libbitdht/src/lib/
|
|
||||||
+libretroshare/src/lib/
|
|
||||||
+retroshare-gui/src/RetroShare.app/
|
|
||||||
+retroshare-gui/src/temp/
|
|
||||||
diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro
|
|
||||||
index 6f35e01..267cc91 100644
|
|
||||||
--- a/libretroshare/src/libretroshare.pro
|
|
||||||
+++ b/libretroshare/src/libretroshare.pro
|
|
||||||
@@ -312,7 +312,7 @@ mac {
|
|
||||||
OBJECTS_DIR = temp/obj
|
|
||||||
MOC_DIR = temp/moc
|
|
||||||
#DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW
|
|
||||||
- #DEFINES *= MINIUPNPC_VERSION=13
|
|
||||||
+ DEFINES *= MINIUPNPC_VERSION=13
|
|
||||||
DESTDIR = lib
|
|
||||||
|
|
||||||
#miniupnp implementation files
|
|
||||||
@@ -326,12 +326,11 @@ mac {
|
|
||||||
# Beautiful Hack to fix 64bit file access.
|
|
||||||
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
|
|
||||||
|
|
||||||
- UPNPC_DIR = ../../../miniupnpc-1.0
|
|
||||||
- GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
|
||||||
- GPGME_DIR = ../../../../gpgme-1.1.8
|
|
||||||
+ UPNPC_DIR = ../../../miniupnpc-1.3
|
|
||||||
+ GPG_ERROR_DIR = ../../../libgpg-error-1.10
|
|
||||||
+ GPGME_DIR = ../../../gpgme-1.3.1
|
|
||||||
|
|
||||||
- INCLUDEPATH += . $${UPNPC_DIR}
|
|
||||||
- #INCLUDEPATH += . $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
|
|
||||||
+ INCLUDEPATH += . $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
|
|
||||||
}
|
|
||||||
|
|
||||||
################################# FreeBSD ##########################################
|
|
||||||
diff --git a/libretroshare/src/pqi/sslfns.cc b/libretroshare/src/pqi/sslfns.cc
|
|
||||||
index 2588cb8..305433f 100644
|
|
||||||
--- a/libretroshare/src/pqi/sslfns.cc
|
|
||||||
+++ b/libretroshare/src/pqi/sslfns.cc
|
|
||||||
@@ -586,8 +586,8 @@ X509 *loadX509FromDER(const uint8_t *ptr, uint32_t len)
|
|
||||||
X509 *tmp = NULL;
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// This depends on which version you are compiling for... OSX10.5 doesn't have consts (old OpenSSL!)
|
|
||||||
- unsigned char **certptr = (unsigned char **) &ptr;
|
|
||||||
- //const unsigned char **certptr = (const unsigned char **) &ptr;
|
|
||||||
+ //unsigned char **certptr = (unsigned char **) &ptr;
|
|
||||||
+ const unsigned char **certptr = (const unsigned char **) &ptr;
|
|
||||||
#else
|
|
||||||
const unsigned char **certptr = (const unsigned char **) &ptr;
|
|
||||||
#endif
|
|
||||||
diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro
|
|
||||||
index adcb5a0..ffbf669 100644
|
|
||||||
--- a/retroshare-gui/src/RetroShare.pro
|
|
||||||
+++ b/retroshare-gui/src/RetroShare.pro
|
|
||||||
@@ -140,19 +140,21 @@ win32 {
|
|
||||||
|
|
||||||
macx {
|
|
||||||
# ENABLE THIS OPTION FOR Univeral Binary BUILD.
|
|
||||||
- CONFIG += ppc x86
|
|
||||||
- QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4
|
|
||||||
+ # CONFIG += ppc x86
|
|
||||||
+ QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
|
|
||||||
|
|
||||||
CONFIG += version_detail_bash_script
|
|
||||||
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
|
||||||
- LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan
|
|
||||||
- LIBS += ../../../miniupnpc-1.0/libminiupnpc.a
|
|
||||||
+ LIBS += ../../../libgpg-error-1.10/build/lib/libgpg-error.a
|
|
||||||
+ LIBS += ../../../gpgme-1.3.1/build/lib/libgpgme.a
|
|
||||||
+ LIBS += ../../../miniupnpc-1.3/libminiupnpc.a
|
|
||||||
+ LIBS += -lssl -lcrypto -lz -lassuan
|
|
||||||
LIBS += -framework CoreFoundation
|
|
||||||
LIBS += -framework Security
|
|
||||||
|
|
||||||
# LIBS += -framework CoreServices
|
|
||||||
|
|
||||||
- INCLUDEPATH += .
|
|
||||||
+ INCLUDEPATH += . ../../../gpgme-1.3.1/src
|
|
||||||
#DEFINES* = MAC_IDLE # for idle feature
|
|
||||||
CONFIG -= uitools
|
|
||||||
|
|
|
@ -32,6 +32,16 @@ if not "%ParamNoupdate%"=="1" (
|
||||||
if "%ParamIndexing%"=="1" %EnvMSYS2Cmd% "pacman --noconfirm --needed -S mingw-w64-%RsMSYS2Architecture%-xapian-core mingw-w64-%RsMSYS2Architecture%-libvorbis mingw-w64-%RsMSYS2Architecture%-flac mingw-w64-%RsMSYS2Architecture%-taglib"
|
if "%ParamIndexing%"=="1" %EnvMSYS2Cmd% "pacman --noconfirm --needed -S mingw-w64-%RsMSYS2Architecture%-xapian-core mingw-w64-%RsMSYS2Architecture%-libvorbis mingw-w64-%RsMSYS2Architecture%-flac mingw-w64-%RsMSYS2Architecture%-taglib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
:: Fix webui compilation (TODO: remove when whole RS switched to cmake)
|
||||||
|
if "%ParamWebui%"=="1" (
|
||||||
|
pushd "%SourcePath%"
|
||||||
|
copy "%SourcePath%\libretroshare\src\jsonapi\jsonapi-generator-doxygen.conf" "%SourcePath%\jsonapi-generator\src\jsonapi-generator-doxygen.conf" %Quite%
|
||||||
|
copy "%SourcePath%\libretroshare\src\jsonapi\async-method-wrapper-template.cpp.tmpl" "%SourcePath%\jsonapi-generator\src\async-method-wrapper-template.cpp.tmpl" %Quite%
|
||||||
|
copy "%SourcePath%\libretroshare\src\jsonapi\method-wrapper-template.cpp.tmpl" "%SourcePath%\jsonapi-generator\src\method-wrapper-template.cpp.tmpl" %Quite%
|
||||||
|
git update-index --assume-unchanged "jsonapi-generator\src\jsonapi-generator-doxygen.conf" "jsonapi-generator\src\async-method-wrapper-template.cpp.tmpl" "jsonapi-generator\src\method-wrapper-template.cpp.tmpl"
|
||||||
|
popd
|
||||||
|
)
|
||||||
|
|
||||||
:: Initialize environment
|
:: Initialize environment
|
||||||
call "%~dp0env.bat" %*
|
call "%~dp0env.bat" %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
|
@ -66,6 +76,7 @@ echo %RS_QMAKE_CONFIG% > buildinfo.txt
|
||||||
echo %RsBuildConfig% >> buildinfo.txt
|
echo %RsBuildConfig% >> buildinfo.txt
|
||||||
echo %RsArchitecture% >> buildinfo.txt
|
echo %RsArchitecture% >> buildinfo.txt
|
||||||
echo Qt %QtVersion% >> buildinfo.txt
|
echo Qt %QtVersion% >> buildinfo.txt
|
||||||
|
echo %RsToolchain% >> buildinfo.txt
|
||||||
echo %RsCompiler% >> buildinfo.txt
|
echo %RsCompiler% >> buildinfo.txt
|
||||||
|
|
||||||
call "%ToolsPath%\msys2-path.bat" "%SourcePath%" MSYS2SourcePath
|
call "%ToolsPath%\msys2-path.bat" "%SourcePath%" MSYS2SourcePath
|
||||||
|
@ -86,11 +97,6 @@ title Build - %SourceName%-%RsBuildConfig% [make]
|
||||||
%EnvMSYS2Cmd% "make -j %CoreCount%"
|
%EnvMSYS2Cmd% "make -j %CoreCount%"
|
||||||
if errorlevel 1 goto error
|
if errorlevel 1 goto error
|
||||||
|
|
||||||
:: Webui
|
|
||||||
if "%ParamWebui%"=="1" (
|
|
||||||
call "%~dp0..\tools\webui.bat"
|
|
||||||
)
|
|
||||||
|
|
||||||
:error
|
:error
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
:: Process commandline parameter
|
:: Process commandline parameter
|
||||||
set Param32=0
|
|
||||||
set Param64=0
|
|
||||||
set ParamRelease=0
|
set ParamRelease=0
|
||||||
set ParamDebug=0
|
set ParamDebug=0
|
||||||
set ParamAutologin=0
|
set ParamAutologin=0
|
||||||
|
@ -9,17 +7,40 @@ set ParamTor=0
|
||||||
set ParamWebui=0
|
set ParamWebui=0
|
||||||
set ParamClang=0
|
set ParamClang=0
|
||||||
set ParamIndexing=0
|
set ParamIndexing=0
|
||||||
|
set ParamFriendserver=0
|
||||||
set ParamNoupdate=0
|
set ParamNoupdate=0
|
||||||
set CoreCount=%NUMBER_OF_PROCESSORS%
|
set CoreCount=%NUMBER_OF_PROCESSORS%
|
||||||
set RS_QMAKE_CONFIG=
|
set RS_QMAKE_CONFIG=
|
||||||
|
set RsToolchain=
|
||||||
|
set tcc=0
|
||||||
|
|
||||||
:parameter_loop
|
:parameter_loop
|
||||||
if "%~1" NEQ "" (
|
if "%~1" NEQ "" (
|
||||||
for /f "tokens=1,2 delims==" %%a in ("%~1") do (
|
for /f "tokens=1,2 delims==" %%a in ("%~1") do (
|
||||||
if "%%~a"=="32" (
|
if "%%~a"=="32" (
|
||||||
set Param32=1
|
set RsToolchain=mingw32
|
||||||
|
set /A tcc=tcc+1
|
||||||
) else if "%%~a"=="64" (
|
) else if "%%~a"=="64" (
|
||||||
set Param64=1
|
set RsToolchain=mingw64
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="mingw32" (
|
||||||
|
set RsToolchain=mingw32
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="mingw64" (
|
||||||
|
set RsToolchain=mingw64
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="ucrt64" (
|
||||||
|
set RsToolchain=ucrt64
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="clang64" (
|
||||||
|
set RsToolchain=clang64
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="clang32" (
|
||||||
|
set RsToolchain=clang32
|
||||||
|
set /A tcc=tcc+1
|
||||||
|
) else if "%%~a"=="clangarm64" (
|
||||||
|
set RsToolchain=clangarm64
|
||||||
|
set /A tcc=tcc+1
|
||||||
) else if "%%~a"=="release" (
|
) else if "%%~a"=="release" (
|
||||||
set ParamRelease=1
|
set ParamRelease=1
|
||||||
) else if "%%~a"=="debug" (
|
) else if "%%~a"=="debug" (
|
||||||
|
@ -38,6 +59,8 @@ if "%~1" NEQ "" (
|
||||||
set ParamClang=1
|
set ParamClang=1
|
||||||
) else if "%%~a"=="indexing" (
|
) else if "%%~a"=="indexing" (
|
||||||
set ParamIndexing=1
|
set ParamIndexing=1
|
||||||
|
) else if "%%~a"=="friendserver" (
|
||||||
|
set ParamFriendserver=1
|
||||||
) else if "%%~a"=="noupdate" (
|
) else if "%%~a"=="noupdate" (
|
||||||
set ParamNoupdate=1
|
set ParamNoupdate=1
|
||||||
) else if "%%~a"=="CONFIG+" (
|
) else if "%%~a"=="CONFIG+" (
|
||||||
|
@ -52,22 +75,37 @@ if "%~1" NEQ "" (
|
||||||
goto parameter_loop
|
goto parameter_loop
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%Param32%"=="1" (
|
if %tcc% NEQ 1 (
|
||||||
if "%Param64%"=="1" (
|
echo Multiple or no toolchain specified
|
||||||
echo.
|
|
||||||
echo 32-bit or 64-bit?
|
|
||||||
goto :usage
|
goto :usage
|
||||||
)
|
|
||||||
|
|
||||||
set RsBit=32
|
|
||||||
set RsArchitecture=x86
|
|
||||||
set RsMSYS2Architecture=i686
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%Param64%"=="1" (
|
if "%RsToolchain%"=="mingw32" (
|
||||||
set RsBit=64
|
set RsArchitecture=x86
|
||||||
|
set RsMSYS2Architecture=i686
|
||||||
|
set MSYSTEM=MINGW32
|
||||||
|
) else if "%RsToolchain%"=="mingw64" (
|
||||||
set RsArchitecture=x64
|
set RsArchitecture=x64
|
||||||
set RsMSYS2Architecture=x86_64
|
set RsMSYS2Architecture=x86_64
|
||||||
|
set MSYSTEM=MINGW64
|
||||||
|
) else if "%RsToolchain%"=="ucrt64" (
|
||||||
|
set RsArchitecture=x64
|
||||||
|
set RsMSYS2Architecture=ucrt-x86_64
|
||||||
|
set MSYSTEM=UCRT64
|
||||||
|
) else if "%RsToolchain%"=="clang64" (
|
||||||
|
set RsArchitecture=x64
|
||||||
|
set RsMSYS2Architecture=clang-x86_64
|
||||||
|
set MSYSTEM=CLANG64
|
||||||
|
set ParamClang=1
|
||||||
|
) else if "%RsToolchain%"=="clang32" (
|
||||||
|
set RsArchitecture=x86
|
||||||
|
set RsMSYS2Architecture=clang-i686
|
||||||
|
set MSYSTEM=CLANG32
|
||||||
|
set ParamClang=1
|
||||||
|
) else if "%RsToolchain%"=="clangarm64" (
|
||||||
|
set RsArchitecture=arm64
|
||||||
|
set RsMSYS2Architecture=clang-aarch64
|
||||||
|
set MSYSTEM=CLANGARM64
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%ParamClang%"=="1" (
|
if "%ParamClang%"=="1" (
|
||||||
|
@ -76,8 +114,6 @@ if "%ParamClang%"=="1" (
|
||||||
set RsCompiler=GCC
|
set RsCompiler=GCC
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%RsBit%"=="" goto :usage
|
|
||||||
|
|
||||||
if "%ParamRelease%"=="1" (
|
if "%ParamRelease%"=="1" (
|
||||||
if "%ParamDebug%"=="1" (
|
if "%ParamDebug%"=="1" (
|
||||||
echo.
|
echo.
|
||||||
|
@ -104,14 +140,21 @@ if "%ParamIndexing%"=="1" (
|
||||||
set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=rs_deep_channels_index" "CONFIG+=rs_deep_files_index" "CONFIG+=rs_deep_files_index_ogg" "CONFIG+=rs_deep_files_index_flac" "CONFIG+=rs_deep_files_index_taglib"
|
set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=rs_deep_channels_index" "CONFIG+=rs_deep_files_index" "CONFIG+=rs_deep_files_index_ogg" "CONFIG+=rs_deep_files_index_flac" "CONFIG+=rs_deep_files_index_taglib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "%ParamFriendserver%"=="1" (
|
||||||
|
set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% "CONFIG+=rs_efs"
|
||||||
|
)
|
||||||
|
|
||||||
exit /B 0
|
exit /B 0
|
||||||
|
|
||||||
:usage
|
:usage
|
||||||
echo.
|
echo.
|
||||||
echo Usage: 32^|64 release^|debug [autologin plugins webui singlethread clang indexing noupdate] ["CONFIG+=..."]
|
echo Usage: 32^|64^|other release^|debug [autologin plugins webui singlethread clang indexing friendserver noupdate] ["CONFIG+=..."]
|
||||||
echo.
|
echo.
|
||||||
echo Mandatory parameter
|
echo Mandatory parameter
|
||||||
echo 32^|64 32-bit or 64-bit Version
|
echo 32^|64 32-bit or 64-bit version (same as mingw32 or mingw64)
|
||||||
|
echo Or you can specify any other toolchain supported by msys2:
|
||||||
|
echo mingw32^|mingw64^|clang32^|clang64^|ucrt64^|clangarm64
|
||||||
|
echo More info: https://www.msys2.org/docs/environments
|
||||||
echo release^|debug Build release or debug version
|
echo release^|debug Build release or debug version
|
||||||
echo.
|
echo.
|
||||||
echo Optional parameter (need clean when changed)
|
echo Optional parameter (need clean when changed)
|
||||||
|
@ -121,6 +164,7 @@ echo webui Enable JsonAPI and pack webui files
|
||||||
echo singlethread Use only 1 thread for building
|
echo singlethread Use only 1 thread for building
|
||||||
echo clang Use clang compiler instead of GCC
|
echo clang Use clang compiler instead of GCC
|
||||||
echo indexing Build with deep channel and file indexing support
|
echo indexing Build with deep channel and file indexing support
|
||||||
|
echo friendserver Enable friendserver support
|
||||||
echo noupdate Skip updating the libraries
|
echo noupdate Skip updating the libraries
|
||||||
echo "CONFIG+=..." Enable some extra features, you can find the almost complete list in retroshare.pri
|
echo "CONFIG+=..." Enable some extra features, you can find the almost complete list in retroshare.pri
|
||||||
echo.
|
echo.
|
||||||
|
|
|
@ -2,8 +2,6 @@ call "%~dp0env-base.bat" %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
set MSYSTEM=MINGW%RsBit%
|
|
||||||
|
|
||||||
set BuildPath=%EnvRootPath%\builds
|
set BuildPath=%EnvRootPath%\builds
|
||||||
set DeployPath=%EnvRootPath%\deploy
|
set DeployPath=%EnvRootPath%\deploy
|
||||||
|
|
||||||
|
@ -14,13 +12,13 @@ if not exist "%DeployPath%" mkdir "%DeployPath%"
|
||||||
call "%ToolsPath%\get-qt-version.bat" QtVersion
|
call "%ToolsPath%\get-qt-version.bat" QtVersion
|
||||||
if "%QtVersion%"=="" %cecho% error "Cannot get Qt version." & exit /B 1
|
if "%QtVersion%"=="" %cecho% error "Cannot get Qt version." & exit /B 1
|
||||||
|
|
||||||
set RsMinGWPath=%EnvMSYS2BasePath%\mingw%RsBit%
|
set RsMinGWPath=%EnvMSYS2BasePath%\%RsToolchain%
|
||||||
|
|
||||||
set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%RsArchitecture%-%RsCompiler%-%RsBuildConfig%
|
set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%RsToolchain%-%RsCompiler%-%RsBuildConfig%
|
||||||
set RsDeployPath=%DeployPath%\Qt-%QtVersion%%RsType%-%RsArchitecture%-%RsCompiler%-%RsBuildConfig%
|
set RsDeployPath=%DeployPath%\Qt-%QtVersion%%RsType%-%RsToolchain%-%RsCompiler%-%RsBuildConfig%
|
||||||
set RsPackPath=%DeployPath%
|
set RsPackPath=%DeployPath%
|
||||||
set RsArchiveAdd=
|
set RsArchiveAdd=
|
||||||
set RsWebuiPath=%RootPath%\%SourceName%-webui
|
set RsWebuiBuildPath=%RsBuildPath%\retroshare-webui\webui
|
||||||
|
|
||||||
if not exist "%~dp0env-mod.bat" goto no_mod
|
if not exist "%~dp0env-mod.bat" goto no_mod
|
||||||
call "%~dp0env-mod.bat"
|
call "%~dp0env-mod.bat"
|
||||||
|
|
|
@ -105,6 +105,9 @@ copy "%RsBuildPath%\retroshare-nogui\src\%RsBuildConfig%\retroshare*-nogui.exe"
|
||||||
copy "%RsBuildPath%\retroshare-service\src\%RsBuildConfig%\retroshare*-service.exe" "%RsDeployPath%" %Quite%
|
copy "%RsBuildPath%\retroshare-service\src\%RsBuildConfig%\retroshare*-service.exe" "%RsDeployPath%" %Quite%
|
||||||
copy "%RsBuildPath%\supportlibs\cmark\build\src\libcmark.dll" "%RsDeployPath%" %Quite%
|
copy "%RsBuildPath%\supportlibs\cmark\build\src\libcmark.dll" "%RsDeployPath%" %Quite%
|
||||||
if exist "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" copy "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" "%RsDeployPath%" %Quite%
|
if exist "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" copy "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" "%RsDeployPath%" %Quite%
|
||||||
|
if exist "%RsBuildPath%\retroshare-friendserver\src\%RsBuildConfig%\retroshare-friendserver.exe" (
|
||||||
|
copy "%RsBuildPath%\retroshare-friendserver\src\%RsBuildConfig%\retroshare-friendserver.exe" "%RsDeployPath%" %Quite%
|
||||||
|
)
|
||||||
|
|
||||||
echo copy extensions
|
echo copy extensions
|
||||||
for /D %%D in ("%RsBuildPath%\plugins\*") do (
|
for /D %%D in ("%RsBuildPath%\plugins\*") do (
|
||||||
|
@ -132,8 +135,14 @@ del /Q "%RsDeployPath%\imageformats\*d?.dll" %Quite%
|
||||||
|
|
||||||
if "%ParamTor%"=="1" (
|
if "%ParamTor%"=="1" (
|
||||||
echo copy tor
|
echo copy tor
|
||||||
copy "%RsMinGWPath%\bin\tor.exe" "%RsDeployPath%" %Quite%
|
if not exist "%RsDeployPath%\tor" mkdir "%RsDeployPath%\tor"
|
||||||
copy "%RsMinGWPath%\bin\tor-gencert.exe" "%RsDeployPath%" %Quite%
|
copy "%RsMinGWPath%\bin\tor.exe" "%RsDeployPath%\tor" %Quite%
|
||||||
|
copy "%RsMinGWPath%\bin\tor-gencert.exe" "%RsDeployPath%\tor" %Quite%
|
||||||
|
|
||||||
|
echo copy tor dependencies
|
||||||
|
for /R "%RsDeployPath%\tor" %%D in (*.exe) do (
|
||||||
|
call :copy_dependencies "%%D" "%RsDeployPath%\tor"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
echo copy dependencies
|
echo copy dependencies
|
||||||
|
@ -141,14 +150,15 @@ for /R "%RsDeployPath%" %%D in (*.dll, *.exe) do (
|
||||||
call :copy_dependencies "%%D" "%RsDeployPath%"
|
call :copy_dependencies "%%D" "%RsDeployPath%"
|
||||||
)
|
)
|
||||||
|
|
||||||
echo copy qss
|
if exist "%SourcePath%\retroshare-gui\src\qss" (
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite%
|
echo copy qss
|
||||||
|
xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite%
|
||||||
|
)
|
||||||
|
|
||||||
echo copy stylesheets
|
echo copy stylesheets
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite%
|
xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite%
|
rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite%
|
rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\__MACOSX__Bubble" %Quite%
|
|
||||||
|
|
||||||
echo copy sounds
|
echo copy sounds
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite%
|
xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite%
|
||||||
|
@ -177,12 +187,12 @@ echo copy buildinfo.txt
|
||||||
copy "%RsBuildPath%\buildinfo.txt" "%RsDeployPath%" %Quite%
|
copy "%RsBuildPath%\buildinfo.txt" "%RsDeployPath%" %Quite%
|
||||||
|
|
||||||
if "%ParamWebui%"=="1" (
|
if "%ParamWebui%"=="1" (
|
||||||
if exist "%RsWebuiPath%\webui" (
|
if exist "%RsWebuiBuildPath%" (
|
||||||
echo copy webui
|
echo copy webui
|
||||||
mkdir "%RsDeployPath%\webui"
|
mkdir "%RsDeployPath%\webui"
|
||||||
xcopy /S "%RsWebuiPath%\webui" "%RsDeployPath%\webui" %Quite%
|
xcopy /S "%RsWebuiBuildPath%" "%RsDeployPath%\webui" %Quite%
|
||||||
) else (
|
) else (
|
||||||
%cecho% error "Webui is enabled, but no webui data found at %RsWebuiPath%\webui"
|
%cecho% error "Webui is enabled, but no webui data found at %RsWebuiBuildPath%"
|
||||||
goto error
|
goto error
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,8 +25,11 @@ if exist "%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\pacman.exe" (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
set MSYS2Install=msys2-base-%MSYS2Architecture%-20200720.tar.xz
|
if "%MSYS2Architecture%"=="i686" set MSYS2Version=20210705
|
||||||
set MSYS2Url=http://sourceforge.net/projects/msys2/files/Base/%MSYS2Architecture%/%MSYS2Install%/download
|
if "%MSYS2Architecture%"=="x86_64" set MSYS2Version=20210725
|
||||||
|
|
||||||
|
set MSYS2Install=msys2-base-%MSYS2Architecture%-%MSYS2Version%.tar.xz
|
||||||
|
set MSYS2Url=https://repo.msys2.org/distrib/%MSYS2Architecture%/%MSYS2Install%
|
||||||
|
|
||||||
%cecho% info "Remove previous MSYS2 version"
|
%cecho% info "Remove previous MSYS2 version"
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%"
|
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%"
|
||||||
|
@ -41,12 +44,11 @@ if not exist "%EnvDownloadPath%\%MSYS2Install%" %cecho% error "Cannot download M
|
||||||
set MSYS2SH=%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\sh
|
set MSYS2SH=%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\sh
|
||||||
|
|
||||||
%cecho% info "Initialize MSYS2"
|
%cecho% info "Initialize MSYS2"
|
||||||
"%MSYS2SH%" -lc "pacman -Sy"
|
"%MSYS2SH%" -lc "yes | pacman --noconfirm -Syuu msys2-keyring"
|
||||||
"%MSYS2SH%" -lc "pacman --noconfirm --needed -S bash pacman pacman-mirrors msys2-runtime"
|
"%MSYS2SH%" -lc "pacman --noconfirm -Sy"
|
||||||
|
"%MSYS2SH%" -lc "pacman --noconfirm -Su"
|
||||||
|
|
||||||
call "%EnvMSYS2Path%\msys%MSYS2Base%\autorebase.bat"
|
call "%EnvMSYS2Path%\msys%MSYS2Base%\autorebase.bat"
|
||||||
call "%EnvRootPath%\update-msys2.bat"
|
|
||||||
call "%EnvRootPath%\update-msys2.bat"
|
|
||||||
|
|
||||||
:exit
|
:exit
|
||||||
endlocal
|
endlocal
|
||||||
|
|
|
@ -8,11 +8,11 @@ if exist "%~dp0msys2\msys64" call :update 64
|
||||||
goto :EOF
|
goto :EOF
|
||||||
|
|
||||||
:update
|
:update
|
||||||
set MSYSSH=%~dp0msys2\msys%~1\usr\bin\sh
|
set MSYS2SH=%~dp0msys2\msys%~1\usr\bin\sh
|
||||||
|
|
||||||
echo Update MSYS2 %~1
|
echo Update MSYS2 %~1
|
||||||
"%MSYSSH%" -lc "pacman -Sy"
|
"%MSYS2SH%" -lc "yes | pacman --noconfirm -Syuu msys2-keyring"
|
||||||
"%MSYSSH%" -lc "pacman --noconfirm -Su"
|
"%MSYS2SH%" -lc "pacman --noconfirm -Su"
|
||||||
|
|
||||||
:exit
|
:exit
|
||||||
endlocal
|
endlocal
|
||||||
|
|
|
@ -218,7 +218,7 @@ Section $(Section_Data) Section_Data
|
||||||
|
|
||||||
; Stylesheets
|
; Stylesheets
|
||||||
SetOutPath "$INSTDIR\qss"
|
SetOutPath "$INSTDIR\qss"
|
||||||
File /r "${DEPLOYDIR}\qss\*.*"
|
File /nonfatal /r "${DEPLOYDIR}\qss\*.*"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
;Section $(Section_Link) Section_Link
|
;Section $(Section_Link) Section_Link
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
setlocal
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo === webui
|
|
||||||
echo.
|
|
||||||
title Build webui
|
|
||||||
|
|
||||||
if not exist "%RsWebuiPath%" (
|
|
||||||
echo Checking out webui source into %RsWebuiPath%
|
|
||||||
if not "%ParamNoupdate%"=="1" (
|
|
||||||
%EnvMSYS2Cmd% "pacman --noconfirm --needed -S git"
|
|
||||||
)
|
|
||||||
git clone https://github.com/RetroShare/RSNewWebUI.git "%RsWebuiPath%"
|
|
||||||
) else (
|
|
||||||
echo Webui source found at %RsWebuiPath%
|
|
||||||
)
|
|
||||||
|
|
||||||
pushd "%RsWebuiPath%\webui-src\make-src"
|
|
||||||
%EnvMSYS2Cmd% "sh build.sh"
|
|
||||||
popd
|
|
||||||
|
|
||||||
endlocal
|
|
|
@ -1,25 +1,24 @@
|
||||||
ZLIB_VERSION=1.2.3
|
ZLIB_VERSION=1.2.11
|
||||||
BZIP2_VERSION=1.0.6
|
BZIP2_VERSION=1.0.8
|
||||||
MINIUPNPC_VERSION=2.0
|
MINIUPNPC_VERSION=2.2.3
|
||||||
OPENSSL_VERSION=1.1.1h
|
OPENSSL_VERSION=1.1.1p
|
||||||
SPEEX_VERSION=1.2.0
|
SPEEX_VERSION=1.2.0
|
||||||
SPEEXDSP_VERSION=1.2rc3
|
SPEEXDSP_VERSION=1.2.0
|
||||||
OPENCV_VERSION=4.5.0
|
LIBXML2_VERSION=2.9.12
|
||||||
LIBXML2_VERSION=2.9.7
|
LIBXSLT_VERSION=1.1.34
|
||||||
LIBXSLT_VERSION=1.1.32
|
CURL_VERSION=7.81.0
|
||||||
CURL_VERSION=7.58.0
|
|
||||||
TCL_VERSION=8.6.10
|
TCL_VERSION=8.6.10
|
||||||
SQLCIPHER_VERSION=4.4.0
|
SQLCIPHER_VERSION=4.5.0
|
||||||
LIBMICROHTTPD_VERSION=0.9.59
|
LIBMICROHTTPD_VERSION=0.9.75
|
||||||
FFMPEG_VERSION=3.4
|
FFMPEG_VERSION=4.4
|
||||||
RAPIDJSON_VERSION=1.1.0
|
RAPIDJSON_VERSION=1.1.0
|
||||||
XAPIAN_VERSION=1.4.7
|
XAPIAN_VERSION=1.4.19
|
||||||
|
|
||||||
DOWNLOAD_PATH?=download
|
DOWNLOAD_PATH?=download
|
||||||
BUILD_PATH=build
|
BUILD_PATH=build
|
||||||
LIBS_PATH?=libs
|
LIBS_PATH?=libs
|
||||||
|
|
||||||
all: dirs zlib bzip2 miniupnpc openssl speex speexdsp opencv libxml2 libxslt curl sqlcipher libmicrohttpd ffmpeg rapidjson xapian copylibs
|
all: dirs zlib bzip2 miniupnpc openssl speex speexdsp libxml2 libxslt curl sqlcipher libmicrohttpd ffmpeg rapidjson xapian copylibs
|
||||||
|
|
||||||
download: \
|
download: \
|
||||||
$(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz \
|
||||||
|
@ -28,7 +27,6 @@ download: \
|
||||||
$(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/openssl-$(OPENSSL_VERSION).tar.gz \
|
||||||
$(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/speex-$(SPEEX_VERSION).tar.gz \
|
||||||
$(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tar.gz \
|
||||||
$(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz \
|
|
||||||
$(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz \
|
||||||
$(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/libxslt-$(LIBXSLT_VERSION).tar.gz \
|
||||||
$(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz \
|
$(DOWNLOAD_PATH)/curl-$(CURL_VERSION).tar.gz \
|
||||||
|
@ -58,8 +56,7 @@ $(BUILD_PATH)/zlib-$(ZLIB_VERSION): $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz
|
||||||
rm -r -f $(BUILD_PATH)/zlib-*
|
rm -r -f $(BUILD_PATH)/zlib-*
|
||||||
tar xvf $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz
|
tar xvf $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz
|
||||||
# build
|
# build
|
||||||
cd zlib-$(ZLIB_VERSION) && ./configure
|
cd zlib-$(ZLIB_VERSION) && make -f win32/Makefile.gcc libz.a
|
||||||
#cd zlib-$(ZLIB_VERSION) && make install prefix="`pwd`/../$(BUILD_PATH)"
|
|
||||||
cd zlib-$(ZLIB_VERSION) && make
|
cd zlib-$(ZLIB_VERSION) && make
|
||||||
# copy files
|
# copy files
|
||||||
mkdir -p $(BUILD_PATH)/zlib-$(ZLIB_VERSION).tmp/include
|
mkdir -p $(BUILD_PATH)/zlib-$(ZLIB_VERSION).tmp/include
|
||||||
|
@ -74,7 +71,7 @@ $(BUILD_PATH)/zlib-$(ZLIB_VERSION): $(DOWNLOAD_PATH)/zlib-$(ZLIB_VERSION).tar.gz
|
||||||
bzip2: $(BUILD_PATH)/bzip2-$(BZIP2_VERSION)
|
bzip2: $(BUILD_PATH)/bzip2-$(BZIP2_VERSION)
|
||||||
|
|
||||||
$(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz:
|
$(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz:
|
||||||
wget https://sourceforge.net/projects/bzip2/files/bzip2-$(BZIP2_VERSION).tar.gz/download -O $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz
|
wget https://www.sourceware.org/pub/bzip2/bzip2-$(BZIP2_VERSION).tar.gz -O $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz
|
||||||
|
|
||||||
$(BUILD_PATH)/bzip2-$(BZIP2_VERSION): $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz
|
$(BUILD_PATH)/bzip2-$(BZIP2_VERSION): $(DOWNLOAD_PATH)/bzip2-$(BZIP2_VERSION).tar.gz
|
||||||
# prepare
|
# prepare
|
||||||
|
@ -102,10 +99,10 @@ $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION): $(DOWNLOAD_PATH)/miniupnpc-$(MINIU
|
||||||
rm -r -f $(BUILD_PATH)/miniupnpc-*
|
rm -r -f $(BUILD_PATH)/miniupnpc-*
|
||||||
tar xvf $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz
|
tar xvf $(DOWNLOAD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tar.gz
|
||||||
# build
|
# build
|
||||||
cd miniupnpc-$(MINIUPNPC_VERSION) && export CC=gcc && export PATH=.:$$PATH && make -f Makefile.mingw init libminiupnpc.a miniupnpc.dll
|
cd miniupnpc-$(MINIUPNPC_VERSION) && export CC=gcc && export PATH=.:$$PATH && make -f Makefile.mingw libminiupnpc.a miniupnpc.dll
|
||||||
# copy files
|
# copy files
|
||||||
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc
|
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc
|
||||||
cp miniupnpc-$(MINIUPNPC_VERSION)/*.h $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc/
|
cp miniupnpc-$(MINIUPNPC_VERSION)/include/*.h $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/include/miniupnpc/
|
||||||
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib
|
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib
|
||||||
cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.lib $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib/
|
cp miniupnpc-$(MINIUPNPC_VERSION)/miniupnpc.lib $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/lib/
|
||||||
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/bin
|
mkdir -p $(BUILD_PATH)/miniupnpc-$(MINIUPNPC_VERSION).tmp/bin
|
||||||
|
@ -187,31 +184,6 @@ $(BUILD_PATH)/speexdsp-$(SPEEXDSP_VERSION): $(DOWNLOAD_PATH)/speexdsp-$(SPEEXDSP
|
||||||
rm -r -f speexdsp-$(SPEEXDSP_VERSION)
|
rm -r -f speexdsp-$(SPEEXDSP_VERSION)
|
||||||
mv $(BUILD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tmp $(BUILD_PATH)/speexdsp-$(SPEEXDSP_VERSION)
|
mv $(BUILD_PATH)/speexdsp-$(SPEEXDSP_VERSION).tmp $(BUILD_PATH)/speexdsp-$(SPEEXDSP_VERSION)
|
||||||
|
|
||||||
opencv: $(BUILD_PATH)/opencv-$(OPENCV_VERSION)
|
|
||||||
|
|
||||||
$(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz:
|
|
||||||
wget --no-check-certificate https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz -O $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz
|
|
||||||
|
|
||||||
$(BUILD_PATH)/opencv-$(OPENCV_VERSION): $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz
|
|
||||||
# prepare
|
|
||||||
rm -r -f $(BUILD_PATH)/opencv-*
|
|
||||||
tar xvf $(DOWNLOAD_PATH)/opencv-$(OPENCV_VERSION).tar.gz
|
|
||||||
# Remove version numbers from libraries. Is there a switch?
|
|
||||||
sed -i -e's/\(ocv_update(OPENCV_DLLVERSION \).*$$/\1"")/' opencv-$(OPENCV_VERSION)/CMakeLists.txt
|
|
||||||
# build
|
|
||||||
mkdir -p opencv-$(OPENCV_VERSION)/build
|
|
||||||
#cd opencv-$(OPENCV_VERSION)/build && cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="`pwd`/../../build"
|
|
||||||
cd opencv-$(OPENCV_VERSION)/build && cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DENABLE_CXX11=ON -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -DSTRSAFE_NO_DEPRECATE" -DCMAKE_INSTALL_PREFIX="`pwd`/install"
|
|
||||||
cd opencv-$(OPENCV_VERSION)/build && make install
|
|
||||||
# copy files
|
|
||||||
mkdir -p $(BUILD_PATH)/opencv-$(OPENCV_VERSION).tmp/include
|
|
||||||
cp -r opencv-$(OPENCV_VERSION)/build/install/include/* $(BUILD_PATH)/opencv-$(OPENCV_VERSION).tmp/include/
|
|
||||||
mkdir -p $(BUILD_PATH)/opencv-$(OPENCV_VERSION).tmp/lib/opencv
|
|
||||||
cp -r opencv-$(OPENCV_VERSION)/build/install/x64/mingw/staticlib/* $(BUILD_PATH)/opencv-$(OPENCV_VERSION).tmp/lib/opencv/
|
|
||||||
# cleanup
|
|
||||||
rm -r -f opencv-$(OPENCV_VERSION)
|
|
||||||
mv $(BUILD_PATH)/opencv-$(OPENCV_VERSION).tmp $(BUILD_PATH)/opencv-$(OPENCV_VERSION)
|
|
||||||
|
|
||||||
libxml2: $(BUILD_PATH)/libxml2-$(LIBXML2_VERSION)
|
libxml2: $(BUILD_PATH)/libxml2-$(LIBXML2_VERSION)
|
||||||
|
|
||||||
$(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz:
|
$(DOWNLOAD_PATH)/libxml2-$(LIBXML2_VERSION).tar.gz:
|
||||||
|
@ -341,7 +313,7 @@ $(BUILD_PATH)/ffmpeg-$(FFMPEG_VERSION): $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION
|
||||||
rm -r -f $(BUILD_PATH)/ffmpeg-*
|
rm -r -f $(BUILD_PATH)/ffmpeg-*
|
||||||
tar xvf $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz
|
tar xvf $(DOWNLOAD_PATH)/ffmpeg-$(FFMPEG_VERSION).tar.gz
|
||||||
# build
|
# build
|
||||||
cd ffmpeg-$(FFMPEG_VERSION) && ./configure --disable-shared --enable-static --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-yasm --disable-everything --enable-encoder=mpeg4 --enable-decoder=mpeg4 --prefix="`pwd`/../$(BUILD_PATH)/ffmpeg-$(FFMPEG_VERSION).tmp"
|
cd ffmpeg-$(FFMPEG_VERSION) && ./configure --disable-shared --enable-static --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-yasm --disable-everything --enable-encoder=mpeg4 --enable-decoder=mpeg4 --prefix="`pwd`/../$(BUILD_PATH)/ffmpeg-$(FFMPEG_VERSION).tmp"
|
||||||
cd ffmpeg-$(FFMPEG_VERSION) && make install
|
cd ffmpeg-$(FFMPEG_VERSION) && make install
|
||||||
# cleanup
|
# cleanup
|
||||||
rm -r -f ffmpeg-$(FFMPEG_VERSION)
|
rm -r -f ffmpeg-$(FFMPEG_VERSION)
|
||||||
|
|
|
@ -13,11 +13,11 @@ call "%~dp0build-libs\build-libs.bat"
|
||||||
if errorlevel 1 %cecho% error "Failed to build libraries." & exit /B %ERRORLEVEL%
|
if errorlevel 1 %cecho% error "Failed to build libraries." & exit /B %ERRORLEVEL%
|
||||||
|
|
||||||
%cecho% info "Build %SourceName%"
|
%cecho% info "Build %SourceName%"
|
||||||
call "%~dp0build\build.bat" release autologin jsonapi plugins nativedialogs
|
call "%~dp0build\build.bat" release autologin webui plugins nativedialogs service
|
||||||
if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL%
|
if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL%
|
||||||
|
|
||||||
%cecho% info "Pack %SourceName%"
|
%cecho% info "Pack %SourceName%"
|
||||||
call "%~dp0build\pack.bat" release plugins
|
call "%~dp0build\pack.bat" release webui plugins service
|
||||||
if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL%
|
if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL%
|
||||||
|
|
||||||
%cecho% info "Build installer"
|
%cecho% info "Build installer"
|
||||||
|
|
|
@ -9,7 +9,7 @@ call "%EnvPath%\env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
:: Initialize environment
|
:: Initialize environment
|
||||||
call "%~dp0env.bat" release
|
call "%~dp0env.bat" installer release
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ set NSIS_PARAM=%NSIS_PARAM% /DARCHITECTURE="%GCCArchitecture%"
|
||||||
set NSIS_PARAM=%NSIS_PARAM% /DDATE="%RsDate%"
|
set NSIS_PARAM=%NSIS_PARAM% /DDATE="%RsDate%"
|
||||||
|
|
||||||
if exist "%EnvTorPath%\Tor\tor.exe" set NSIS_PARAM=%NSIS_PARAM% /DTORDIR="%EnvTorPath%\Tor"
|
if exist "%EnvTorPath%\Tor\tor.exe" set NSIS_PARAM=%NSIS_PARAM% /DTORDIR="%EnvTorPath%\Tor"
|
||||||
|
if exist "%RsWebuiBuildPath%" set NSIS_PARAM=%NSIS_PARAM% /DWEBUIDIR="%RsWebuiBuildPath%"
|
||||||
|
|
||||||
:: Get compiled version
|
:: Get compiled version
|
||||||
call "%ToolsPath%\get-rs-version.bat" "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\retroshare.exe" RsVersion
|
call "%ToolsPath%\get-rs-version.bat" "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\retroshare.exe" RsVersion
|
||||||
|
|
|
@ -9,7 +9,7 @@ call "%EnvPath%\env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
:: Initialize environment
|
:: Initialize environment
|
||||||
call "%~dp0env.bat" %*
|
call "%~dp0env.bat" build %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
|
@ -49,11 +49,15 @@ echo.
|
||||||
|
|
||||||
title Build - %SourceName%-%RsBuildConfig% [qmake]
|
title Build - %SourceName%-%RsBuildConfig% [qmake]
|
||||||
|
|
||||||
set RS_QMAKE_CONFIG=%RsBuildConfig% no_rs_cppwarning
|
set RS_QMAKE_CONFIG=%RsBuildConfig%
|
||||||
if "%ParamAutologin%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_autologin
|
if "%ParamAutologin%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_autologin
|
||||||
if "%ParamJsonApi%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_jsonapi
|
if "%ParamJsonApi%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_jsonapi
|
||||||
|
if "%ParamWebui%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_webui
|
||||||
if "%ParamPlugins%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% retroshare_plugins
|
if "%ParamPlugins%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% retroshare_plugins
|
||||||
if "%ParamUseNativeDialogs%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_use_native_dialogs
|
if "%ParamUseNativeDialogs%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_use_native_dialogs
|
||||||
|
if "%ParamService%" NEQ "1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% no_retroshare_service
|
||||||
|
if "%ParamFriendServer%" NEQ "1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% no_rs_friendserver
|
||||||
|
if "%ParamEmbeddedFriendServer%"=="1" set RS_QMAKE_CONFIG=%RS_QMAKE_CONFIG% rs_efs
|
||||||
|
|
||||||
qmake "%SourcePath%\RetroShare.pro" -r -spec win32-g++ "CONFIG+=%RS_QMAKE_CONFIG%" "EXTERNAL_LIB_DIR=%BuildLibsPath%\libs"
|
qmake "%SourcePath%\RetroShare.pro" -r -spec win32-g++ "CONFIG+=%RS_QMAKE_CONFIG%" "EXTERNAL_LIB_DIR=%BuildLibsPath%\libs"
|
||||||
if errorlevel 1 goto error
|
if errorlevel 1 goto error
|
||||||
|
|
|
@ -8,7 +8,7 @@ if errorlevel 1 goto error_env
|
||||||
call "%EnvPath%\env.bat"
|
call "%EnvPath%\env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
call "%~dp0env.bat" %*
|
call "%~dp0env.bat" clean %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,18 @@ set ParamDebug=0
|
||||||
set ParamAutologin=0
|
set ParamAutologin=0
|
||||||
set ParamPlugins=0
|
set ParamPlugins=0
|
||||||
set ParamJsonApi=0
|
set ParamJsonApi=0
|
||||||
|
set ParamWebui=0
|
||||||
|
set ParamService=0
|
||||||
|
set ParamFriendServer=0
|
||||||
|
set ParamEmbeddedFriendServer=0
|
||||||
set ParamUseNativeDialogs=0
|
set ParamUseNativeDialogs=0
|
||||||
set ParamTor=0
|
set ParamTor=0
|
||||||
set NonInteractive=0
|
set NonInteractive=0
|
||||||
set CoreCount=%NUMBER_OF_PROCESSORS%
|
set CoreCount=%NUMBER_OF_PROCESSORS%
|
||||||
|
|
||||||
|
set Module=%~1
|
||||||
|
shift /1
|
||||||
|
|
||||||
:parameter_loop
|
:parameter_loop
|
||||||
if "%~1" NEQ "" (
|
if "%~1" NEQ "" (
|
||||||
for /f "tokens=1,2 delims==" %%a in ("%~1") do (
|
for /f "tokens=1,2 delims==" %%a in ("%~1") do (
|
||||||
|
@ -20,6 +27,15 @@ if "%~1" NEQ "" (
|
||||||
set ParamAutologin=1
|
set ParamAutologin=1
|
||||||
) else if "%%~a"=="jsonapi" (
|
) else if "%%~a"=="jsonapi" (
|
||||||
set ParamJsonApi=1
|
set ParamJsonApi=1
|
||||||
|
) else if "%%~a"=="webui" (
|
||||||
|
set ParamJsonApi=1
|
||||||
|
set ParamWebui=1
|
||||||
|
) else if "%%~a"=="service" (
|
||||||
|
set ParamService=1
|
||||||
|
) else if "%%~a"=="friendserver" (
|
||||||
|
set ParamFriendServer=1
|
||||||
|
) else if "%%~a"=="embedded-friendserver" (
|
||||||
|
set ParamEmbeddedFriendServer=1
|
||||||
) else if "%%~a"=="plugins" (
|
) else if "%%~a"=="plugins" (
|
||||||
set ParamPlugins=1
|
set ParamPlugins=1
|
||||||
) else if "%%~a"=="tor" (
|
) else if "%%~a"=="tor" (
|
||||||
|
@ -32,7 +48,7 @@ if "%~1" NEQ "" (
|
||||||
set ParamUseNativeDialogs=1
|
set ParamUseNativeDialogs=1
|
||||||
) else (
|
) else (
|
||||||
echo.
|
echo.
|
||||||
echo Unknown parameter %1
|
echo Unknown parameter %1 for %Module%
|
||||||
goto :usage
|
goto :usage
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -89,6 +105,7 @@ set RsBuildPath=%BuildPath%\Qt-%QtVersion%-%GCCArchitecture%-%RsBuildConfig%
|
||||||
set RsDeployPath=%DeployPath%\Qt-%QtVersion%-%GCCArchitecture%%RsType%-%RsBuildConfig%
|
set RsDeployPath=%DeployPath%\Qt-%QtVersion%-%GCCArchitecture%%RsType%-%RsBuildConfig%
|
||||||
set RsPackPath=%DeployPath%
|
set RsPackPath=%DeployPath%
|
||||||
set RsArchiveAdd=
|
set RsArchiveAdd=
|
||||||
|
set RsWebuiBuildPath=%RsBuildPath%\retroshare-webui\webui
|
||||||
|
|
||||||
if not exist "%~dp0env-mod.bat" goto no_mod
|
if not exist "%~dp0env-mod.bat" goto no_mod
|
||||||
call "%~dp0env-mod.bat"
|
call "%~dp0env-mod.bat"
|
||||||
|
@ -104,19 +121,31 @@ echo.
|
||||||
echo Mandatory parameter
|
echo Mandatory parameter
|
||||||
echo release^|debug Build release or debug version
|
echo release^|debug Build release or debug version
|
||||||
echo.
|
echo.
|
||||||
echo Optional parameter (need clean when changed)
|
if "%Module%"=="build" (
|
||||||
echo autologin Build with autologin
|
echo Optional parameter ^(need clean when changed^)
|
||||||
echo jsonapi Build with jsonapi
|
echo autologin Build with autologin
|
||||||
echo plugins Build plugins
|
echo jsonapi Build with jsonapi
|
||||||
echo nativedialogs Build with native dialogs
|
echo webui Build with jsonapi and webui
|
||||||
echo.
|
echo service Build service
|
||||||
echo Optional parameter
|
echo friendserver Build Friend Server
|
||||||
echo singlethread Use only 1 thread for building
|
echo embedded-friendserver Build with embedded Friend Server
|
||||||
echo.
|
echo plugins Build plugins
|
||||||
echo Parameter for pack
|
echo nativedialogs Build with native dialogs
|
||||||
echo tor Pack tor version
|
echo.
|
||||||
echo.
|
echo Optional parameter
|
||||||
echo Parameter for git-log
|
echo singlethread Use only 1 thread for building
|
||||||
echo non-interactive Non-interactive mode
|
)
|
||||||
|
if "%Module%"=="pack" (
|
||||||
|
echo Optional parameter
|
||||||
|
echo webui Pack webui
|
||||||
|
echo service Pack service
|
||||||
|
echo friendserver Pack Friend Server ^(needs Tor^)
|
||||||
|
echo tor Pack Tor version
|
||||||
|
echo plugins Pack plugins
|
||||||
|
)
|
||||||
|
if "%Module%"=="git-log" (
|
||||||
|
echo Optional parameter
|
||||||
|
echo non-interactive Non-interactive mode
|
||||||
|
)
|
||||||
echo.
|
echo.
|
||||||
exit /B 2
|
exit /B 2
|
||||||
|
|
|
@ -8,7 +8,7 @@ if errorlevel 1 goto error_env
|
||||||
call "%EnvPath%\env.bat"
|
call "%EnvPath%\env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
call "%~dp0env.bat" %*
|
call "%~dp0env.bat" git-log %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
|
@ -88,6 +88,10 @@ echo %RsRef%>"%RsLastRefFile%"
|
||||||
|
|
||||||
exit /B %ERRORLEVEL%
|
exit /B %ERRORLEVEL%
|
||||||
|
|
||||||
|
:error
|
||||||
|
%cecho% error "\n%~n0 failed\n"
|
||||||
|
exit /B 1
|
||||||
|
|
||||||
:error_env
|
:error_env
|
||||||
echo Failed to initialize environment.
|
echo Failed to initialize environment.
|
||||||
endlocal
|
endlocal
|
||||||
|
|
|
@ -11,7 +11,7 @@ call "%EnvPath%\env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
:: Initialize environment
|
:: Initialize environment
|
||||||
call "%~dp0env.bat" %*
|
call "%~dp0env.bat" pack %*
|
||||||
if errorlevel 2 exit /B 2
|
if errorlevel 2 exit /B 2
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
|
@ -95,9 +95,23 @@ copy nul "%RsDeployPath%\portable" %Quite%
|
||||||
|
|
||||||
echo copy binaries
|
echo copy binaries
|
||||||
copy "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\retroshare*.exe" "%RsDeployPath%" %Quite%
|
copy "%RsBuildPath%\retroshare-gui\src\%RsBuildConfig%\retroshare*.exe" "%RsDeployPath%" %Quite%
|
||||||
copy "%RsBuildPath%\retroshare-service\src\%RsBuildConfig%\retroshare*-service.exe" "%RsDeployPath%" %Quite%
|
|
||||||
if exist "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" copy "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" "%RsDeployPath%" %Quite%
|
if exist "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" copy "%RsBuildPath%\libretroshare\src\lib\retroshare.dll" "%RsDeployPath%" %Quite%
|
||||||
|
|
||||||
|
if "%ParamService%"=="1" (
|
||||||
|
copy "%RsBuildPath%\retroshare-service\src\%RsBuildConfig%\retroshare*-service.exe" "%RsDeployPath%" %Quite%
|
||||||
|
if errorlevel 1 %cecho% error "Service not found"& goto error
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%ParamFriendServer%"=="1" (
|
||||||
|
if "%ParamTor%"=="1" (
|
||||||
|
copy "%RsBuildPath%\retroshare-friendserver\src\%RsBuildConfig%\retroshare-friendserver.exe" "%RsDeployPath%" %Quite%
|
||||||
|
if errorlevel 1 %cecho% error "Friend Server not found"& goto error
|
||||||
|
) else (
|
||||||
|
%cecho% error "Friend Server needs Tor"
|
||||||
|
goto error
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
echo copy extensions
|
echo copy extensions
|
||||||
if "%ParamPlugins%"=="1" (
|
if "%ParamPlugins%"=="1" (
|
||||||
for /D %%D in ("%RsBuildPath%\plugins\*") do (
|
for /D %%D in ("%RsBuildPath%\plugins\*") do (
|
||||||
|
@ -132,14 +146,15 @@ if exist "%QtPath%\..\plugins\styles\qwindowsvistastyle.dll" (
|
||||||
copy "%QtPath%\..\plugins\imageformats\*.dll" "%RsDeployPath%\imageformats" %Quite%
|
copy "%QtPath%\..\plugins\imageformats\*.dll" "%RsDeployPath%\imageformats" %Quite%
|
||||||
del /Q "%RsDeployPath%\imageformats\*d?.dll" %Quite%
|
del /Q "%RsDeployPath%\imageformats\*d?.dll" %Quite%
|
||||||
|
|
||||||
echo copy qss
|
if exist "%SourcePath%\retroshare-gui\src\qss" (
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite%
|
echo copy qss
|
||||||
|
xcopy /S "%SourcePath%\retroshare-gui\src\qss" "%RsDeployPath%\qss" %Quite%
|
||||||
|
)
|
||||||
|
|
||||||
echo copy stylesheets
|
echo copy stylesheets
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite%
|
xcopy /S "%SourcePath%\retroshare-gui\src\gui\qss\chat" "%RsDeployPath%\stylesheets" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite%
|
rmdir /S /Q "%RsDeployPath%\stylesheets\compact" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite%
|
rmdir /S /Q "%RsDeployPath%\stylesheets\standard" %Quite%
|
||||||
rmdir /S /Q "%RsDeployPath%\stylesheets\__MACOSX__Bubble" %Quite%
|
|
||||||
|
|
||||||
echo copy sounds
|
echo copy sounds
|
||||||
xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite%
|
xcopy /S "%SourcePath%\retroshare-gui\src\sounds" "%RsDeployPath%\sounds" %Quite%
|
||||||
|
@ -166,15 +181,17 @@ copy "%SourcePath%\libbitdht\src\bitdht\bdboot.txt" "%RsDeployPath%" %Quite%
|
||||||
echo copy changelog.txt
|
echo copy changelog.txt
|
||||||
copy "%RsBuildPath%\changelog.txt" "%RsDeployPath%" %Quite%
|
copy "%RsBuildPath%\changelog.txt" "%RsDeployPath%" %Quite%
|
||||||
|
|
||||||
if exist "%SourcePath%\libresapi\src\webui" (
|
if defined ParamWebui (
|
||||||
echo copy webui
|
echo copy webui
|
||||||
mkdir "%RsDeployPath%\webui"
|
mkdir "%RsDeployPath%\webui"
|
||||||
xcopy /S "%SourcePath%\libresapi\src\webui" "%RsDeployPath%\webui" %Quite%
|
xcopy /S "%RsWebuiBuildPath%" "%RsDeployPath%\webui" %Quite%
|
||||||
|
if errorlevel 1 %cecho% error "WebUi not found"& goto error
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%ParamTor%"=="1" (
|
if "%ParamTor%"=="1" (
|
||||||
echo copy tor
|
echo copy tor
|
||||||
echo n | copy /-y "%EnvTorPath%\Tor\*.*" "%RsDeployPath%" %Quite%
|
if not exist "%RsDeployPath%\tor" mkdir "%RsDeployPath%\tor"
|
||||||
|
echo n | copy /-y "%EnvTorPath%\Tor\*.*" "%RsDeployPath%\tor" %Quite%
|
||||||
)
|
)
|
||||||
|
|
||||||
rem pack files
|
rem pack files
|
||||||
|
|
3
build_scripts/Windows/env/env-msys2.bat
vendored
3
build_scripts/Windows/env/env-msys2.bat
vendored
|
@ -5,7 +5,6 @@
|
||||||
call "%~dp0env.bat"
|
call "%~dp0env.bat"
|
||||||
if errorlevel 1 goto error_env
|
if errorlevel 1 goto error_env
|
||||||
|
|
||||||
rem openssl x86 doesn't compile with mingw64 x64
|
|
||||||
:: Get gcc versions
|
:: Get gcc versions
|
||||||
call "%ToolsPath%\get-gcc-version.bat" GCCVersion GCCArchitecture
|
call "%ToolsPath%\get-gcc-version.bat" GCCVersion GCCArchitecture
|
||||||
if "%GCCVersion%"=="" %cecho% error "Cannot get gcc version." & exit /B 1
|
if "%GCCVersion%"=="" %cecho% error "Cannot get gcc version." & exit /B 1
|
||||||
|
@ -27,7 +26,7 @@ set EnvMSYS2Path=%EnvRootPath%\msys2
|
||||||
call "%~dp0tools\prepare-msys2.bat" %1
|
call "%~dp0tools\prepare-msys2.bat" %1
|
||||||
if errorlevel 1 exit /B %ERRORLEVEL%
|
if errorlevel 1 exit /B %ERRORLEVEL%
|
||||||
|
|
||||||
set EnvMSYS2SH=%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\sh.exe
|
set EnvMSYS2SH=%EnvMSYS2Path%\msys64\usr\bin\sh.exe
|
||||||
if not exist "%EnvMSYS2SH%" if errorlevel 1 goto error_env
|
if not exist "%EnvMSYS2SH%" if errorlevel 1 goto error_env
|
||||||
|
|
||||||
set EnvMSYS2Cmd="%EnvMSYS2SH%" -lc
|
set EnvMSYS2Cmd="%EnvMSYS2SH%" -lc
|
||||||
|
|
3
build_scripts/Windows/env/env.bat
vendored
3
build_scripts/Windows/env/env.bat
vendored
|
@ -28,6 +28,9 @@ if errorlevel 1 exit /B %ERRORLEVEL%
|
||||||
set PATH=%EnvToolsPath%\MinGit\cmd;%EnvToolsPath%\cmake\bin;%PATH%
|
set PATH=%EnvToolsPath%\MinGit\cmd;%EnvToolsPath%\cmake\bin;%PATH%
|
||||||
set HOME=%EnvToolsPath%\MinGit\home
|
set HOME=%EnvToolsPath%\MinGit\home
|
||||||
|
|
||||||
|
:: Add Doxygen to PATH
|
||||||
|
set PATH=%EnvToolsPath%\doxygen;%PATH%
|
||||||
|
|
||||||
exit /B 0
|
exit /B 0
|
||||||
|
|
||||||
:error_env
|
:error_env
|
||||||
|
|
|
@ -16,7 +16,15 @@ if "%~1"=="clean" (
|
||||||
goto exit
|
goto exit
|
||||||
)
|
)
|
||||||
|
|
||||||
if exist "%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\pacman.exe" (
|
set MSYS2Version=20230318
|
||||||
|
|
||||||
|
set MSYS2Install=msys2-base-x86_64-%MSYS2Version%.sfx.exe
|
||||||
|
set MSYS2Url=https://github.com/msys2/msys2-installer/releases/download/%MSYS2Version:~0,4%-%MSYS2Version:~4,2%-%MSYS2Version:~6,2%/%MSYS2Install%
|
||||||
|
set CMakeInstall=cmake-3.19.0-win32-x86.zip
|
||||||
|
set CMakeUrl=https://github.com/Kitware/CMake/releases/download/v3.19.0/%CMakeInstall%
|
||||||
|
set CMakeUnpackPath=%EnvMSYS2Path%\msys64
|
||||||
|
|
||||||
|
if exist "%CMakeUnpackPath%\usr\bin\pacman.exe" (
|
||||||
if "%~1"=="reinstall" (
|
if "%~1"=="reinstall" (
|
||||||
choice /M "Found existing MSYS2 version. Do you want to proceed?"
|
choice /M "Found existing MSYS2 version. Do you want to proceed?"
|
||||||
if !ERRORLEVEL!==2 goto exit
|
if !ERRORLEVEL!==2 goto exit
|
||||||
|
@ -25,15 +33,10 @@ if exist "%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\pacman.exe" (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
set MSYS2Install=msys2-base-%MSYS2Architecture%-20190524.tar.xz
|
|
||||||
set MSYS2Url=http://sourceforge.net/projects/msys2/files/Base/%MSYS2Architecture%/%MSYS2Install%/download
|
|
||||||
set CMakeInstall=cmake-3.19.0-win32-x86.zip
|
|
||||||
set CMakeUrl=https://github.com/Kitware/CMake/releases/download/v3.19.0/%CMakeInstall%
|
|
||||||
set CMakeUnpackPath=%EnvMSYS2Path%\msys%MSYS2Base%
|
|
||||||
|
|
||||||
if exist "%EnvMSYS2Path%\msys%MSYS2Base%" (
|
if exist "%CMakeUnpackPath%" (
|
||||||
%cecho% info "Remove previous MSYS2 version"
|
%cecho% info "Remove previous MSYS2 version"
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvMSYS2Path%\msys%MSYS2Base%"
|
call "%ToolsPath%\remove-dir.bat" "%CMakeUnpackPath%"
|
||||||
)
|
)
|
||||||
|
|
||||||
%cecho% info "Download installation files"
|
%cecho% info "Download installation files"
|
||||||
|
@ -44,7 +47,7 @@ if not exist "%EnvDownloadPath%\%CMakeInstall%" call "%ToolsPath%\download-file.
|
||||||
if not exist "%EnvDownloadPath%\%CMakeInstall%" %cecho% error "Cannot download CMake" & goto error
|
if not exist "%EnvDownloadPath%\%CMakeInstall%" %cecho% error "Cannot download CMake" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack MSYS2"
|
%cecho% info "Unpack MSYS2"
|
||||||
"%EnvSevenZipExe%" x -so "%EnvDownloadPath%\%MSYS2Install%" | "%EnvSevenZipExe%" x -y -si -ttar -o"%EnvMSYS2Path%"
|
"%EnvDownloadPath%\%MSYS2Install%" -y -o"%EnvMSYS2Path%"
|
||||||
|
|
||||||
%cecho% info "Unpack CMake"
|
%cecho% info "Unpack CMake"
|
||||||
"%EnvSevenZipExe%" x -o"%CMakeUnpackPath%" "%EnvDownloadPath%\%CMakeInstall%"
|
"%EnvSevenZipExe%" x -o"%CMakeUnpackPath%" "%EnvDownloadPath%\%CMakeInstall%"
|
||||||
|
@ -56,25 +59,20 @@ if "%CMakeVersion%"=="" %cecho% error "CMake version not found." & goto :exit
|
||||||
%cecho% info "Found CMake version %CMakeVersion%"
|
%cecho% info "Found CMake version %CMakeVersion%"
|
||||||
|
|
||||||
set FoundProfile=
|
set FoundProfile=
|
||||||
for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%EnvMSYS2Path%\msys%MSYS2Base%\etc\profile"') do set FoundProfile=%%F
|
for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%CMakeUnpackPath%\etc\profile"') do set FoundProfile=%%F
|
||||||
|
|
||||||
if "%FoundProfile%"=="0" (
|
if "%FoundProfile%"=="0" (
|
||||||
echo export PATH="${PATH}:/%CMakeVersion%/bin">>"%EnvMSYS2Path%\msys%MSYS2Base%\etc\profile"
|
echo export PATH="${PATH}:/%CMakeVersion%/bin">>"%CMakeUnpackPath%\etc\profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
set MSYS2SH=%EnvMSYS2Path%\msys%MSYS2Base%\usr\bin\sh
|
set MSYS2SH=%CMakeUnpackPath%\usr\bin\sh
|
||||||
|
|
||||||
%cecho% info "Update keyring"
|
|
||||||
"%MSYS2SH%" -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
|
|
||||||
"%MSYS2SH%" -lc "pacman --noconfirm -U msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
|
|
||||||
|
|
||||||
%cecho% info "Initialize MSYS2"
|
%cecho% info "Initialize MSYS2"
|
||||||
"%MSYS2SH%" -lc "pacman -Sy"
|
"%MSYS2SH%" -lc "yes | pacman --noconfirm -Syuu msys2-keyring"
|
||||||
"%MSYS2SH%" -lc "pacman --noconfirm --needed -S bash pacman pacman-mirrors msys2-runtime"
|
"%MSYS2SH%" -lc "pacman --noconfirm -Sy"
|
||||||
|
"%MSYS2SH%" -lc "pacman --noconfirm -Su"
|
||||||
|
|
||||||
call "%EnvMSYS2Path%\msys%MSYS2Base%\autorebase.bat"
|
call "%CMakeUnpackPath%\autorebase.bat"
|
||||||
call "%EnvRootPath%\update-msys2.bat"
|
|
||||||
call "%EnvRootPath%\update-msys2.bat"
|
|
||||||
|
|
||||||
:exit
|
:exit
|
||||||
endlocal
|
endlocal
|
||||||
|
|
|
@ -16,6 +16,9 @@ set NSISInstallPath=%EnvToolsPath%\NSIS
|
||||||
set MinGitInstall=MinGit-2.28.0-32-bit.zip
|
set MinGitInstall=MinGit-2.28.0-32-bit.zip
|
||||||
set MinGitUrl=https://github.com/git-for-windows/git/releases/download/v2.28.0.windows.1/%MinGitInstall%
|
set MinGitUrl=https://github.com/git-for-windows/git/releases/download/v2.28.0.windows.1/%MinGitInstall%
|
||||||
set MinGitInstallPath=%EnvToolsPath%\MinGit
|
set MinGitInstallPath=%EnvToolsPath%\MinGit
|
||||||
|
set DoxygenInstall=doxygen-1.9.6.windows.x64.bin.zip
|
||||||
|
set DoxygenUrl=https://github.com/doxygen/doxygen/releases/download/Release_1_9_6/%DoxygenInstall%
|
||||||
|
set DoxygenInstallPath=%EnvToolsPath%\doxygen
|
||||||
set CMakeVersion=cmake-3.19.0-win32-x86
|
set CMakeVersion=cmake-3.19.0-win32-x86
|
||||||
set CMakeInstall=%CMakeVersion%.zip
|
set CMakeInstall=%CMakeVersion%.zip
|
||||||
set CMakeUrl=https://github.com/Kitware/CMake/releases/download/v3.19.0/%CMakeInstall%
|
set CMakeUrl=https://github.com/Kitware/CMake/releases/download/v3.19.0/%CMakeInstall%
|
||||||
|
@ -135,6 +138,19 @@ if not exist "%MinGitInstallPath%\cmd\git.exe" (
|
||||||
"%EnvSevenZipExe%" x -o"%MinGitInstallPath%" "%EnvDownloadPath%\%MinGitInstall%"
|
"%EnvSevenZipExe%" x -o"%MinGitInstallPath%" "%EnvDownloadPath%\%MinGitInstall%"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not exist "%EnvDownloadPath%\%DoxygenInstall%" call "%ToolsPath%\remove-dir.bat" "%DoxygenInstallPath%"
|
||||||
|
if not exist "%DoxygenInstallPath%\doxygen.exe" (
|
||||||
|
if exist "%DoxygenInstallPath%" call "%ToolsPath%\remove-dir.bat" "%DoxygenInstallPath%"
|
||||||
|
|
||||||
|
%cecho% info "Download Doxygen installation"
|
||||||
|
|
||||||
|
if not exist "%EnvDownloadPath%\%DoxygenInstall%" call "%ToolsPath%\download-file.bat" "%DoxygenUrl%" "%EnvDownloadPath%\%DoxygenInstall%"
|
||||||
|
if not exist "%EnvDownloadPath%\%DoxygenInstall%" %cecho% error "Cannot download doxygen installation" & goto error
|
||||||
|
|
||||||
|
%cecho% info "Unpack Doxygen"
|
||||||
|
"%EnvSevenZipExe%" x -o"%DoxygenInstallPath%" "%EnvDownloadPath%\%DoxygenInstall%"
|
||||||
|
)
|
||||||
|
|
||||||
if not exist "%EnvDownloadPath%\%CMakeInstall%" call "%ToolsPath%\remove-dir.bat" "%CMakeInstallPath%"
|
if not exist "%EnvDownloadPath%\%CMakeInstall%" call "%ToolsPath%\remove-dir.bat" "%CMakeInstallPath%"
|
||||||
if not exist "%CMakeInstallPath%\bin\cmake.exe" (
|
if not exist "%CMakeInstallPath%\bin\cmake.exe" (
|
||||||
%cecho% info "Download CMake installation"
|
%cecho% info "Download CMake installation"
|
||||||
|
@ -160,7 +176,7 @@ mkdir "%EnvTempPath%"
|
||||||
call "%ToolsPath%\download-file.bat" "%TorDownloadIndexUrl%" "%EnvTempPath%\index.html"
|
call "%ToolsPath%\download-file.bat" "%TorDownloadIndexUrl%" "%EnvTempPath%\index.html"
|
||||||
if not exist "%EnvTempPath%\index.html" %cecho% error "Cannot download Tor installation" & goto error
|
if not exist "%EnvTempPath%\index.html" %cecho% error "Cannot download Tor installation" & goto error
|
||||||
|
|
||||||
for /F "tokens=1,2 delims= " %%A in ('%EnvSedExe% -r -n -e"s/.*href=\"^(.*^)^(tor-win32.*\.zip^)\".*/\2 \1\2/p" "%EnvTempPath%\index.html"') do set TorInstall=%%A& set TorDownloadUrl=%TorProjectUrl%%%B
|
for /F "tokens=1,2 delims= " %%A in ('%EnvSedExe% -r -n -e"s/.*href=\"^(.*^)^(tor-.*windows-i686\.tar\.gz^)\".*/\2 \1\2/p" "%EnvTempPath%\index.html"') do set TorInstall=%%A& set TorDownloadUrl=%%B
|
||||||
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
|
||||||
if "%TorInstall%"=="" %cecho% error "Cannot download Tor installation" & goto error
|
if "%TorInstall%"=="" %cecho% error "Cannot download Tor installation" & goto error
|
||||||
if "%TorDownloadUrl%"=="" %cecho% error "Cannot download Tor installation" & goto error
|
if "%TorDownloadUrl%"=="" %cecho% error "Cannot download Tor installation" & goto error
|
||||||
|
@ -173,7 +189,7 @@ if not exist "%EnvTorPath%\Tor\tor.exe" (
|
||||||
if not exist "%EnvDownloadPath%\%TorInstall%" %cecho% error "Cannot download Tor installation" & goto error
|
if not exist "%EnvDownloadPath%\%TorInstall%" %cecho% error "Cannot download Tor installation" & goto error
|
||||||
|
|
||||||
%cecho% info "Unpack Tor"
|
%cecho% info "Unpack Tor"
|
||||||
"%EnvSevenZipExe%" x -o"%EnvTorPath%" "%EnvDownloadPath%\%TorInstall%"
|
"%EnvSevenZipExe%" x -so "%EnvDownloadPath%\%TorInstall%" | "%EnvSevenZipExe%" x -si -ttar -o"%EnvTorPath%"
|
||||||
)
|
)
|
||||||
|
|
||||||
:exit
|
:exit
|
||||||
|
|
|
@ -2,18 +2,13 @@
|
||||||
|
|
||||||
setlocal
|
setlocal
|
||||||
|
|
||||||
if exist "%~dp0msys2\msys32" call :update 32
|
if not exist "%~dp0msys2\msys64" goto :EOF
|
||||||
if exist "%~dp0msys2\msys64" call :update 64
|
|
||||||
|
|
||||||
goto :EOF
|
set MSYS2SH=%~dp0msys2\msys64\usr\bin\sh
|
||||||
|
|
||||||
:update
|
echo Update MSYS2
|
||||||
set MSYSSH=%~dp0msys2\msys%~1\usr\bin\sh
|
"%MSYS2SH%" -lc "yes | pacman --noconfirm -Syuu msys2-keyring"
|
||||||
|
"%MSYS2SH%" -lc "pacman --noconfirm -Su"
|
||||||
|
|
||||||
echo Update MSYS2 %~1
|
|
||||||
"%MSYSSH%" -lc "pacman -Sy"
|
|
||||||
"%MSYSSH%" -lc "pacman --noconfirm -Su"
|
|
||||||
|
|
||||||
:exit
|
|
||||||
endlocal
|
endlocal
|
||||||
goto :EOF
|
goto :EOF
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Instal·la ${APPNAME} i els components necessaris."
|
!insertmacro LANG_STRING Section_Main_Desc "Instal·la ${APPNAME} i els components necessaris."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Pells"
|
!insertmacro LANG_STRING Section_Data "Pells"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Instal·la pells."
|
!insertmacro LANG_STRING Section_Data_Desc "Instal·la pells."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Icones d'accés directe"
|
!insertmacro LANG_STRING Section_Shortcuts "Icones d'accés directe"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Installiert ${APPNAME} und die benötigten Komponenten."
|
!insertmacro LANG_STRING Section_Main_Desc "Installiert ${APPNAME} und die benötigten Komponenten."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installiert Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installiert Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installiert WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installiert Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installiert Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Skins"
|
!insertmacro LANG_STRING Section_Data "Skins"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Skins installieren."
|
!insertmacro LANG_STRING Section_Data_Desc "Skins installieren."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Verknüpfungssymbole"
|
!insertmacro LANG_STRING Section_Shortcuts "Verknüpfungssymbole"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Installs ${APPNAME} and required components."
|
!insertmacro LANG_STRING Section_Main_Desc "Installs ${APPNAME} and required components."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Skins"
|
!insertmacro LANG_STRING Section_Data "Skins"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Installs skins."
|
!insertmacro LANG_STRING Section_Data_Desc "Installs skins."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Shortcut icons"
|
!insertmacro LANG_STRING Section_Shortcuts "Shortcut icons"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Instala ${APPNAME} y los componentes requeridos."
|
!insertmacro LANG_STRING Section_Main_Desc "Instala ${APPNAME} y los componentes requeridos."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Coberturas (skins)"
|
!insertmacro LANG_STRING Section_Data "Coberturas (skins)"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Instalar coberturas"
|
!insertmacro LANG_STRING Section_Data_Desc "Instalar coberturas"
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Iconos de accesos directos"
|
!insertmacro LANG_STRING Section_Shortcuts "Iconos de accesos directos"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Installe ${APPNAME} et les composants requis."
|
!insertmacro LANG_STRING Section_Main_Desc "Installe ${APPNAME} et les composants requis."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Habillages"
|
!insertmacro LANG_STRING Section_Data "Habillages"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Installe des habillages."
|
!insertmacro LANG_STRING Section_Data_Desc "Installe des habillages."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Icônes de raccourci"
|
!insertmacro LANG_STRING Section_Shortcuts "Icônes de raccourci"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Instaluje ${APPNAME} oraz wymagane komponenty."
|
!insertmacro LANG_STRING Section_Main_Desc "Instaluje ${APPNAME} oraz wymagane komponenty."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Skórki"
|
!insertmacro LANG_STRING Section_Data "Skórki"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Instaluje skórki."
|
!insertmacro LANG_STRING Section_Data_Desc "Instaluje skórki."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Ikony skrótów"
|
!insertmacro LANG_STRING Section_Shortcuts "Ikony skrótów"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Установка ${APPNAME} и необходимых компонентов."
|
!insertmacro LANG_STRING Section_Main_Desc "Установка ${APPNAME} и необходимых компонентов."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Оболочки"
|
!insertmacro LANG_STRING Section_Data "Оболочки"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Установка оболочек."
|
!insertmacro LANG_STRING Section_Data_Desc "Установка оболочек."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Ярлыки"
|
!insertmacro LANG_STRING Section_Shortcuts "Ярлыки"
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "${APPNAME} ve gerekli bileşenleri kurar."
|
!insertmacro LANG_STRING Section_Main_Desc "${APPNAME} ve gerekli bileşenleri kurar."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "Temalar"
|
!insertmacro LANG_STRING Section_Data "Temalar"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "Tema yükleyin."
|
!insertmacro LANG_STRING Section_Data_Desc "Tema yükleyin."
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "Kısayol simgeleri"
|
!insertmacro LANG_STRING Section_Shortcuts "Kısayol simgeleri"
|
||||||
|
|
|
@ -22,6 +22,48 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_WebUI</name>
|
||||||
|
<message>
|
||||||
|
<source>WebUI</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_WebUI_Desc</name>
|
||||||
|
<message>
|
||||||
|
<source>Installs WebUI.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_Service</name>
|
||||||
|
<message>
|
||||||
|
<source>Service</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_Service_Desc</name>
|
||||||
|
<message>
|
||||||
|
<source>Installs Service.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_FriendServer</name>
|
||||||
|
<message>
|
||||||
|
<source>Friend Server</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>Section_FriendServer_Desc</name>
|
||||||
|
<message>
|
||||||
|
<source>Installs Friend Server.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>Section_Data</name>
|
<name>Section_Data</name>
|
||||||
<message>
|
<message>
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
!insertmacro LANG_STRING Section_Main_Desc "Installs ${APPNAME} and required components."
|
!insertmacro LANG_STRING Section_Main_Desc "Installs ${APPNAME} and required components."
|
||||||
!insertmacro LANG_STRING Section_Tor "Tor"
|
!insertmacro LANG_STRING Section_Tor "Tor"
|
||||||
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
!insertmacro LANG_STRING Section_Tor_Desc "Installs Tor."
|
||||||
|
!insertmacro LANG_STRING Section_WebUI "WebUI"
|
||||||
|
!insertmacro LANG_STRING Section_WebUI_Desc "Installs WebUI."
|
||||||
|
!insertmacro LANG_STRING Section_Service "Service"
|
||||||
|
!insertmacro LANG_STRING Section_Service_Desc "Installs Service."
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer "Friend Server"
|
||||||
|
!insertmacro LANG_STRING Section_FriendServer_Desc "Installs Friend Server."
|
||||||
!insertmacro LANG_STRING Section_Data "皮肤"
|
!insertmacro LANG_STRING Section_Data "皮肤"
|
||||||
!insertmacro LANG_STRING Section_Data_Desc "安装皮肤"
|
!insertmacro LANG_STRING Section_Data_Desc "安装皮肤"
|
||||||
!insertmacro LANG_STRING Section_Shortcuts "快捷方式图标"
|
!insertmacro LANG_STRING Section_Shortcuts "快捷方式图标"
|
||||||
|
|
|
@ -60,6 +60,9 @@
|
||||||
!define /date DATE "%Y%m%d"
|
!define /date DATE "%Y%m%d"
|
||||||
!endif
|
!endif
|
||||||
|
|
||||||
|
# Service
|
||||||
|
${!defineifexist} SERVICE_EXISTS "${RELEASEDIR}\retroshare-service\src\release\retroshare-service.exe"
|
||||||
|
|
||||||
# Tor
|
# Tor
|
||||||
!ifdef TORDIR
|
!ifdef TORDIR
|
||||||
${!defineifexist} TOR_EXISTS "${TORDIR}\tor.exe"
|
${!defineifexist} TOR_EXISTS "${TORDIR}\tor.exe"
|
||||||
|
@ -68,6 +71,20 @@ ${!defineifexist} TOR_EXISTS "${TORDIR}\tor.exe"
|
||||||
!endif
|
!endif
|
||||||
!endif
|
!endif
|
||||||
|
|
||||||
|
# WebUI
|
||||||
|
!ifdef WEBUIDIR
|
||||||
|
${!defineifexist} WEBUI_EXISTS "${WEBUIDIR}\index.html"
|
||||||
|
!ifndef WEBUI_EXISTS
|
||||||
|
!error "WebUI files not found"
|
||||||
|
!endif
|
||||||
|
!endif
|
||||||
|
|
||||||
|
# Friend Server
|
||||||
|
!ifdef TOR_EXISTS
|
||||||
|
# Add Friend Server with Tor only
|
||||||
|
#${!defineifexist} FRIENDSERVER_EXISTS "${RELEASEDIR}\retroshare-friendserver\src\release\retroshare-friendserver.exe"
|
||||||
|
!endif
|
||||||
|
|
||||||
# Application name and version
|
# Application name and version
|
||||||
!define APPNAME "RetroShare"
|
!define APPNAME "RetroShare"
|
||||||
!define APPNAMEANDVERSION "${APPNAME} ${VERSION}"
|
!define APPNAMEANDVERSION "${APPNAME} ${VERSION}"
|
||||||
|
@ -193,7 +210,6 @@ Section $(Section_Main) Section_Main
|
||||||
; Main binaries
|
; Main binaries
|
||||||
SetOutPath "$INSTDIR"
|
SetOutPath "$INSTDIR"
|
||||||
File "${RELEASEDIR}\retroshare-gui\src\release\retroshare.exe"
|
File "${RELEASEDIR}\retroshare-gui\src\release\retroshare.exe"
|
||||||
File "${RELEASEDIR}\retroshare-service\src\release\retroshare-service.exe"
|
|
||||||
File /nonfatal "${RELEASEDIR}\libretroshare\src\lib\retroshare.dll"
|
File /nonfatal "${RELEASEDIR}\libretroshare\src\lib\retroshare.dll"
|
||||||
|
|
||||||
; Qt binaries
|
; Qt binaries
|
||||||
|
@ -282,14 +298,38 @@ Section $(Section_Main) Section_Main
|
||||||
File /r "${SOURCEDIR}\retroshare-gui\src\license\*.*"
|
File /r "${SOURCEDIR}\retroshare-gui\src\license\*.*"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
# Service
|
||||||
|
!ifdef SERVICE_EXISTS
|
||||||
|
Section /o $(Section_Service) Section_Service
|
||||||
|
SetOutPath "$INSTDIR"
|
||||||
|
File "${RELEASEDIR}\retroshare-service\src\release\retroshare-service.exe"
|
||||||
|
SectionEnd
|
||||||
|
!endif
|
||||||
|
|
||||||
|
# Friend Server
|
||||||
|
!ifdef FRIENDSERVER_EXISTS
|
||||||
|
Section /o $(Section_FriendServer) Section_FriendServer
|
||||||
|
SetOutPath "$INSTDIR"
|
||||||
|
File "${RELEASEDIR}\retroshare-friendserver\src\release\retroshare-friendserver.exe"
|
||||||
|
SectionEnd
|
||||||
|
!endif
|
||||||
|
|
||||||
# Tor
|
# Tor
|
||||||
!ifdef TOR_EXISTS
|
!ifdef TOR_EXISTS
|
||||||
Section /o $(Section_Tor) Section_Tor
|
Section /o $(Section_Tor) Section_Tor
|
||||||
SetOutPath "$INSTDIR"
|
SetOutPath "$INSTDIR\tor"
|
||||||
File /r "${TORDIR}\*"
|
File /r "${TORDIR}\*"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
!endif
|
!endif
|
||||||
|
|
||||||
|
# WebUI
|
||||||
|
!ifdef WEBUI_EXISTS
|
||||||
|
Section /o $(Section_WebUI) Section_WebUI
|
||||||
|
SetOutPath "$INSTDIR\webui"
|
||||||
|
File /r "${WEBUIDIR}\*"
|
||||||
|
SectionEnd
|
||||||
|
!endif
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
${!defineifexist} PLUGIN_FEEDREADER_EXISTS "${RELEASEDIR}\plugins\FeedReader\lib\FeedReader.dll"
|
${!defineifexist} PLUGIN_FEEDREADER_EXISTS "${RELEASEDIR}\plugins\FeedReader\lib\FeedReader.dll"
|
||||||
${!defineifexist} PLUGIN_VOIP_EXISTS "${RELEASEDIR}\plugins\VOIP\lib\VOIP.dll"
|
${!defineifexist} PLUGIN_VOIP_EXISTS "${RELEASEDIR}\plugins\VOIP\lib\VOIP.dll"
|
||||||
|
@ -334,7 +374,7 @@ Section $(Section_Data) Section_Data
|
||||||
|
|
||||||
; Stylesheets
|
; Stylesheets
|
||||||
SetOutPath "$INSTDIR\qss"
|
SetOutPath "$INSTDIR\qss"
|
||||||
File /r "${SOURCEDIR}\retroshare-gui\src\qss\*.*"
|
File /nonfatal /r "${SOURCEDIR}\retroshare-gui\src\qss\*.*"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
;Section $(Section_Link) Section_Link
|
;Section $(Section_Link) Section_Link
|
||||||
|
@ -355,6 +395,22 @@ Section $(Section_StartMenu) Section_StartMenu
|
||||||
CreateDirectory "$SMPROGRAMS\${APPNAME}"
|
CreateDirectory "$SMPROGRAMS\${APPNAME}"
|
||||||
CreateShortCut "$SMPROGRAMS\${APPNAME}\$(Link_Uninstall).lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
|
CreateShortCut "$SMPROGRAMS\${APPNAME}\$(Link_Uninstall).lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
|
||||||
CreateShortCut "$SMPROGRAMS\${APPNAME}\${APPNAME}.lnk" "$INSTDIR\retroshare.exe" "" "$INSTDIR\retroshare.exe" 0
|
CreateShortCut "$SMPROGRAMS\${APPNAME}\${APPNAME}.lnk" "$INSTDIR\retroshare.exe" "" "$INSTDIR\retroshare.exe" 0
|
||||||
|
|
||||||
|
!ifdef SERVICE_EXISTS
|
||||||
|
SectionGetFlags ${Section_Service} $0
|
||||||
|
IntOp $0 $0 & ${SF_SELECTED}
|
||||||
|
${If} $0 == ${SF_SELECTED}
|
||||||
|
CreateShortCut "$SMPROGRAMS\${APPNAME}\${APPNAME} Service.lnk" "$INSTDIR\retroshare-service.exe" "" "$INSTDIR\retroshare-service.exe" 0
|
||||||
|
${EndIf}
|
||||||
|
!endif
|
||||||
|
|
||||||
|
!ifdef FRIENDSERVER_EXISTS
|
||||||
|
SectionGetFlags ${Section_FriendServer} $0
|
||||||
|
IntOp $0 $0 & ${SF_SELECTED}
|
||||||
|
${If} $0 == ${SF_SELECTED}
|
||||||
|
CreateShortCut "$SMPROGRAMS\${APPNAME}\${APPNAME} Friend Server.lnk" "$INSTDIR\retroshare-friendserver.exe" "" "$INSTDIR\retroshare-friendserver.exe" 0
|
||||||
|
${EndIf}
|
||||||
|
!endif
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section $(Section_Desktop) Section_Desktop
|
Section $(Section_Desktop) Section_Desktop
|
||||||
|
@ -407,6 +463,9 @@ SectionEnd
|
||||||
; !insertmacro MUI_DESCRIPTION_TEXT ${Section_Link} $(Section_Link_Desc)
|
; !insertmacro MUI_DESCRIPTION_TEXT ${Section_Link} $(Section_Link_Desc)
|
||||||
!insertmacro MUI_DESCRIPTION_TEXT ${Section_AutoStart} $(Section_AutoStart_Desc)
|
!insertmacro MUI_DESCRIPTION_TEXT ${Section_AutoStart} $(Section_AutoStart_Desc)
|
||||||
!insertmacro MUI_DESCRIPTION_TEXT ${Section_Tor} $(Section_Tor_Desc)
|
!insertmacro MUI_DESCRIPTION_TEXT ${Section_Tor} $(Section_Tor_Desc)
|
||||||
|
!insertmacro MUI_DESCRIPTION_TEXT ${Section_WebUI} $(Section_WebUI_Desc)
|
||||||
|
!insertmacro MUI_DESCRIPTION_TEXT ${Section_Service} $(Section_Service_Desc)
|
||||||
|
!insertmacro MUI_DESCRIPTION_TEXT ${Section_FriendServer} $(Section_FriendServer_Desc)
|
||||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||||
|
|
||||||
# Uninstall
|
# Uninstall
|
||||||
|
@ -461,6 +520,26 @@ Function .onInit
|
||||||
!insertmacro MUI_LANGDLL_DISPLAY
|
!insertmacro MUI_LANGDLL_DISPLAY
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
|
||||||
|
!ifdef FRIENDSERVER_EXISTS
|
||||||
|
Function .onSelChange
|
||||||
|
SectionGetFlags ${Section_FriendServer} $0
|
||||||
|
IntOp $0 $0 & ${SF_SELECTED}
|
||||||
|
${If} $0 == ${SF_SELECTED}
|
||||||
|
# Activate Tor and set readonly
|
||||||
|
SectionGetFlags ${Section_Tor} $1
|
||||||
|
IntOp $1 $1 | ${SF_SELECTED}
|
||||||
|
IntOp $1 $1 | ${SF_RO}
|
||||||
|
SectionSetFlags ${Section_Tor} $1
|
||||||
|
${Else}
|
||||||
|
# Remove readonly from Tor
|
||||||
|
SectionGetFlags ${Section_Tor} $1
|
||||||
|
IntOp $2 ${SF_RO} ~
|
||||||
|
IntOp $1 $1 & $2
|
||||||
|
SectionSetFlags ${Section_Tor} $1
|
||||||
|
${EndIf}
|
||||||
|
FunctionEnd
|
||||||
|
!endif
|
||||||
|
|
||||||
# Installation mode
|
# Installation mode
|
||||||
|
|
||||||
Function RequireAdmin
|
Function RequireAdmin
|
||||||
|
|
|
@ -18,6 +18,8 @@ copy nul %logfile% > nul
|
||||||
|
|
||||||
pushd %~1
|
pushd %~1
|
||||||
|
|
||||||
|
set Percent=%%
|
||||||
|
|
||||||
set last=HEAD
|
set last=HEAD
|
||||||
for /f %%t in ('git tag --sort=-taggerdate --merged ^| findstr v') do (
|
for /f %%t in ('git tag --sort=-taggerdate --merged ^| findstr v') do (
|
||||||
echo generating changelog for !last!..%%t
|
echo generating changelog for !last!..%%t
|
||||||
|
@ -30,7 +32,7 @@ for /f %%t in ('git tag --sort=-taggerdate --merged ^| findstr v') do (
|
||||||
rem echo !last! ---^> %%t >> %logfile%
|
rem echo !last! ---^> %%t >> %logfile%
|
||||||
echo ----------------------------------------------- >> %logfile%
|
echo ----------------------------------------------- >> %logfile%
|
||||||
echo. >> %logfile%
|
echo. >> %logfile%
|
||||||
git log %%t..!last! --no-merges "--pretty=format:%%h %%ai %%<(10,trunc)%%an %%s" >> %logfile%
|
git log %%t..!last! --no-merges "--pretty=format:!Percent!h !Percent!ai !Percent!<(10,trunc)!Percent!an !Percent!s" >> %logfile%
|
||||||
echo. >> %logfile%
|
echo. >> %logfile%
|
||||||
echo. >> %logfile%
|
echo. >> %logfile%
|
||||||
set last=%%t
|
set last=%%t
|
||||||
|
|
|
@ -1,447 +1,10 @@
|
||||||
// SPDX-FileCopyrightText: (C) 2004-2019 Retroshare Team <contact@retroshare.cc>
|
// SPDX-FileCopyrightText: (C) 2021 Retroshare Team <contact@retroshare.cc>
|
||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
RetroShare JSON API
|
= Moved
|
||||||
===================
|
|
||||||
|
|
||||||
:Cxx: C++
|
JSON API generator is now part of `libretroshare` look under `src/jsonapi/`
|
||||||
|
directory in `libretroshare` repository.
|
||||||
|
|
||||||
== How to use RetroShare JSON API
|
This directory and all it's content is kept as is only for retro-compatibility
|
||||||
|
with the old, deprecated `qmake` build system.
|
||||||
Look for methods marked with +@jsonapi+ doxygen custom command into
|
|
||||||
+libretroshare/src/retroshare+. The method path is composed by service instance
|
|
||||||
pointer name like +rsGxsChannels+ for +RsGxsChannels+, and the method name like
|
|
||||||
+createGroup+ and pass the input paramethers as a JSON object.
|
|
||||||
|
|
||||||
.Service instance pointer in rsgxschannels.h
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Pointer to global instance of RsGxsChannels service implementation
|
|
||||||
* @jsonapi{development}
|
|
||||||
*/
|
|
||||||
extern RsGxsChannels* rsGxsChannels;
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.Method declaration in rsgxschannels.h
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief Request channel creation.
|
|
||||||
* The action is performed asyncronously, so it could fail in a subsequent
|
|
||||||
* phase even after returning true.
|
|
||||||
* @jsonapi{development}
|
|
||||||
* @param[out] token Storage for RsTokenService token to track request
|
|
||||||
* status.
|
|
||||||
* @param[in] group Channel data (name, description...)
|
|
||||||
* @return false on error, true otherwise
|
|
||||||
*/
|
|
||||||
virtual bool createGroup(uint32_t& token, RsGxsChannelGroup& group) = 0;
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.paramethers.json
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
{
|
|
||||||
"group":{
|
|
||||||
"mMeta":{
|
|
||||||
"mGroupName":"JSON test group",
|
|
||||||
"mGroupFlags":4,
|
|
||||||
"mSignFlags":520
|
|
||||||
},
|
|
||||||
"mDescription":"JSON test group description"
|
|
||||||
},
|
|
||||||
"caller_data":"Here can go any kind of JSON data (even objects) that the caller want to get back together with the response"
|
|
||||||
}
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.Calling the JSON API with curl on the terminal
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
curl -u $API_USER --data @paramethers.json http://127.0.0.1:9092/rsGxsChannels/createGroup
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.JSON API call result
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
{
|
|
||||||
"caller_data": "Here can go any kind of JSON data (even objects) that the caller want to get back together with the response",
|
|
||||||
"retval": true,
|
|
||||||
"token": 3
|
|
||||||
}
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Even if it is less efficient because of URL encoding HTTP +GET+ method is
|
|
||||||
supported too, so in cases where the client cannot use +POST+ she can still use
|
|
||||||
+GET+ taking care of encoding the JSON data. With +curl+ this can be done at
|
|
||||||
least in two different ways.
|
|
||||||
|
|
||||||
.Calling the JSON API with GET method with curl on the terminal
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
curl -u $API_USER --get --data-urlencode jsonData@paramethers.json \
|
|
||||||
http://127.0.0.1:9092/rsGxsChannels/createGroup
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Letting +curl+ do the encoding is much more elegant but it is semantically
|
|
||||||
equivalent to the following.
|
|
||||||
|
|
||||||
.Calling the JSON API with GET method and pre-encoded data with curl on the terminal
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
curl -u $API_USER http://127.0.0.1:9092/rsGxsChannels/createGroup?jsonData=%7B%0A%20%20%20%20%22group%22%3A%7B%0A%20%20%20%20%20%20%20%20%22mMeta%22%3A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22mGroupName%22%3A%22JSON%20test%20group%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22mGroupFlags%22%3A4%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22mSignFlags%22%3A520%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22mDescription%22%3A%22JSON%20test%20group%20description%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22caller_data%22%3A%22Here%20can%20go%20any%20kind%20of%20JSON%20data%20%28even%20objects%29%20that%20the%20caller%20want%20to%20get%20back%20together%20with%20the%20response%22%0A%7D
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Note that using +GET+ method +?jsonData=+ and then the JSON data URL encoded are
|
|
||||||
added after the path in the HTTP request.
|
|
||||||
|
|
||||||
|
|
||||||
== JSON API authentication
|
|
||||||
|
|
||||||
Most of JSON API methods require authentication as they give access to
|
|
||||||
RetroShare user data, and we don't want any application running on the system
|
|
||||||
eventually by other users be able to access private data indiscriminately.
|
|
||||||
JSON API support HTTP Basic as authentication scheme, this is enough as JSON API
|
|
||||||
server is intented for usage on the same system (127.0.0.1) not over an
|
|
||||||
untrusted network.
|
|
||||||
If you need to use JSON API over an untrusted network consider using a reverse
|
|
||||||
proxy with HTTPS such as NGINX in front of JSON API server.
|
|
||||||
If RetroShare login has been effectuated through the JSON API you can use your
|
|
||||||
location SSLID as username and your PGP password as credential for the JSON API,
|
|
||||||
but we suggests you use specific meaningful and human readable credentials for
|
|
||||||
each JSON API client so the human user can have better control over which client
|
|
||||||
can access the JSON API.
|
|
||||||
|
|
||||||
.NewToken.json
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
{
|
|
||||||
"token": "myNewUser:myNewPassword"
|
|
||||||
}
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.An authenticated client can authorize new tokens like this
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
curl -u $API_USER --data @NewToken.json http://127.0.0.1:9092/jsonApiServer/authorizeToken
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.An unauthenticated JSON API client can request access with
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
curl --data @NewToken.json http://127.0.0.1:9092/jsonApiServer/requestNewTokenAutorization
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
When an unauthenticated client request his token to be authorized, JSON API
|
|
||||||
server will try to ask confirmation to the human user if possible through
|
|
||||||
+mNewAccessRequestCallback+, if it is not possible or the user didn't authorized
|
|
||||||
the token +false+ is returned.
|
|
||||||
|
|
||||||
|
|
||||||
== Offer new RetroShare services through JSON API
|
|
||||||
|
|
||||||
To offer a retroshare service through the JSON API, first of all one need find
|
|
||||||
the global pointer to the service instance and document it in doxygen syntax,
|
|
||||||
plus marking with the custom doxygen command +@jsonapi{RS_VERSION}+ where
|
|
||||||
+RS_VERSION+ is the retroshare version in which this service became available
|
|
||||||
with the current semantic (major changes to the service semantic, changes the
|
|
||||||
meaning of the service itself, so the version should be updated in the
|
|
||||||
documentation in that case).
|
|
||||||
|
|
||||||
.Service instance pointer in rsgxschannels.h
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Pointer to global instance of RsGxsChannels service implementation
|
|
||||||
* @jsonapi{development}
|
|
||||||
*/
|
|
||||||
extern RsGxsChannels* rsGxsChannels;
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Once the service instance itself is known to the JSON API you need to document
|
|
||||||
in doxygen syntax and mark with the custom doxygen command
|
|
||||||
+@jsonapi{RS_VERSION}+ the methods of the service that you want to make
|
|
||||||
available through JSON API.
|
|
||||||
|
|
||||||
.Offering RsGxsChannels::getChannelDownloadDirectory in rsgxschannels.h
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Get download directory for the given channel
|
|
||||||
* @jsonapi{development}
|
|
||||||
* @param[in] channelId id of the channel
|
|
||||||
* @param[out] directory reference to string where to store the path
|
|
||||||
* @return false on error, true otherwise
|
|
||||||
*/
|
|
||||||
virtual bool getChannelDownloadDirectory( const RsGxsGroupId& channelId,
|
|
||||||
std::string& directory ) = 0;
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
For each paramether you must specify if it is used as input +@param[in]+ as
|
|
||||||
output +@param[out]+ or both +@param[inout]+. Paramethers and return value
|
|
||||||
types must be of a type supported by +RsTypeSerializer+ which already support
|
|
||||||
most basic types (+bool+, +std::string+...), +RsSerializable+ and containers of
|
|
||||||
them like +std::vector<std::string>+. Paramethers passed by value and by
|
|
||||||
reference of those types are both supported, while passing by pointer is not
|
|
||||||
supported. If your paramether or return +class+/+struct+ type is not supported
|
|
||||||
yet by +RsTypeSerializer+ most convenient approach is to make it derive from
|
|
||||||
+RsSerializable+ and implement +serial_process+ method like I did with
|
|
||||||
+RsGxsChannelGroup+.
|
|
||||||
|
|
||||||
.Deriving RsGxsChannelGroup from RsSerializable in rsgxschannels.h
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
struct RsGxsChannelGroup : RsSerializable
|
|
||||||
{
|
|
||||||
RsGroupMetaData mMeta;
|
|
||||||
std::string mDescription;
|
|
||||||
RsGxsImage mImage;
|
|
||||||
|
|
||||||
bool mAutoDownload;
|
|
||||||
|
|
||||||
/// @see RsSerializable
|
|
||||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
|
||||||
RsGenericSerializer::SerializeContext& ctx )
|
|
||||||
{
|
|
||||||
RS_SERIAL_PROCESS(mMeta);
|
|
||||||
RS_SERIAL_PROCESS(mDescription);
|
|
||||||
RS_SERIAL_PROCESS(mImage);
|
|
||||||
RS_SERIAL_PROCESS(mAutoDownload);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
You can do the same recursively for any member of your +struct+ that is not yet
|
|
||||||
supported by +RsTypeSerializer+.
|
|
||||||
|
|
||||||
Some Retroshare {Cxx} API functions are asyncronous, historically RetroShare
|
|
||||||
didn't follow a policy on how to expose asyncronous API so differents services
|
|
||||||
and some times even differents method of the same service follow differents
|
|
||||||
asyncronous patterns, thus making automatic generation of JSON API wrappers for
|
|
||||||
those methods impractical. Instead of dealing with all those differents patterns
|
|
||||||
I have chosed to support only one new pattern taking advantage of modern {Cxx}11
|
|
||||||
and restbed features. On the {Cxx}11 side lambdas and +std::function+s are used,
|
|
||||||
on the restbed side Server Side Events are used to send asyncronous results.
|
|
||||||
|
|
||||||
Lets see an example so it will be much esier to understand.
|
|
||||||
|
|
||||||
.RsGxsChannels::turtleSearchRequest asyncronous API
|
|
||||||
[source,cpp]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief Request remote channels search
|
|
||||||
* @jsonapi{development}
|
|
||||||
* @param[in] matchString string to look for in the search
|
|
||||||
* @param multiCallback function that will be called each time a search
|
|
||||||
* result is received
|
|
||||||
* @param[in] maxWait maximum wait time in seconds for search results
|
|
||||||
* @return false on error, true otherwise
|
|
||||||
*/
|
|
||||||
virtual bool turtleSearchRequest(
|
|
||||||
const std::string& matchString,
|
|
||||||
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
|
||||||
std::time_t maxWait = 300 ) = 0;
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
+RsGxsChannels::turtleSearchRequest(...)+ is an asyncronous method because it
|
|
||||||
send a channel search request on turtle network and then everytime a result is
|
|
||||||
received from the network +multiCallback+ is called and the result is passed as
|
|
||||||
parameter. To be supported by the automatic JSON API wrappers generator an
|
|
||||||
asyncronous method need a parameter of type +std::function<void (...)>+ called
|
|
||||||
+callback+ if the callback will be called only once or +multiCallback+ if the
|
|
||||||
callback is expected to be called more then once like in this case.
|
|
||||||
A second mandatory parameter is +maxWait+ of type +std::time_t+ it indicates the
|
|
||||||
maximum amount of time in seconds for which the caller is willing to wait for
|
|
||||||
results, in case the timeout is reached the callback will not be called anymore.
|
|
||||||
|
|
||||||
[IMPORTANT]
|
|
||||||
================================================================================
|
|
||||||
+callback+ and +multiCallback+ parameters documentation must *not* specify
|
|
||||||
+[in]+, +[out]+, +[inout]+, in Doxygen documentation as this would fool the
|
|
||||||
automatic wrapper generator, and ultimately break the compilation.
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
.RsFiles::turtleSearchRequest asyncronous JSON API usage example
|
|
||||||
[source,bash]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
$ cat turtle_search.json
|
|
||||||
{
|
|
||||||
"matchString":"linux"
|
|
||||||
}
|
|
||||||
$ curl --data @turtle_search.json http://127.0.0.1:9092/rsFiles/turtleSearchRequest
|
|
||||||
data: {"retval":true}
|
|
||||||
|
|
||||||
data: {"results":[{"size":157631,"hash":"69709b4d01025584a8def5cd78ebbd1a3cf3fd05","name":"kill_bill_linux_1024x768.jpg"},{"size":192560,"hash":"000000000000000000009a93e5be8486c496f46c","name":"coffee_box_linux2.jpg"},{"size":455087,"hash":"9a93e5be8486c496f46c00000000000000000000","name":"Linux.png"},{"size":182004,"hash":"e8845280912ebf3779e400000000000000000000","name":"Linux_2_6.png"}]}
|
|
||||||
|
|
||||||
data: {"results":[{"size":668,"hash":"e8845280912ebf3779e400000000000000000000","name":"linux.png"},{"size":70,"hash":"e8845280912ebf3779e400000000000000000000","name":"kali-linux-2016.2-amd64.txt.sha1sum"},{"size":3076767744,"hash":"e8845280912ebf3779e400000000000000000000","name":"kali-linux-2016.2-amd64.iso"},{"size":2780872,"hash":"e8845280912ebf3779e400000000000000000000","name":"openwrt-ar71xx-generic-vmlinux.bin"},{"size":917504,"hash":"e8845280912ebf3779e400000000000000000000","name":"openwrt-ar71xx-generic-vmlinux.lzma"},{"size":2278404096,"hash":"e8845280912ebf3779e400000000000000000000","name":"gentoo-linux-livedvd-amd64-multilib-20160704.iso"},{"size":151770333,"hash":"e8845280912ebf3779e400000000000000000000","name":"flashtool-0.9.23.0-linux.tar.7z"},{"size":2847372,"hash":"e8845280912ebf3779e400000000000000000000","name":"openwrt-ar71xx-generic-vmlinux.elf"},{"size":1310720,"hash":"e8845280912ebf3779e400000000000000000000","name":"openwrt-ar71xx-generic-vmlinux.gz"},{"size":987809,"hash":"e8845280912ebf3779e400000000000000000000","name":"openwrt-ar71xx-generic-vmlinux-lzma.elf"}]}
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
By default JSON API methods requires client authentication and their wrappers
|
|
||||||
are automatically generated by +json-api-generator+.
|
|
||||||
In some cases methods need do be accessible without authentication such as
|
|
||||||
+rsLoginHelper/getLocations+ so in the doxygen documentaion they have the custom
|
|
||||||
command +@jsonapi{RS_VERSION,unauthenticated}+.
|
|
||||||
Other methods such as +/rsControl/rsGlobalShutDown+ need special care so they
|
|
||||||
are marked with the custom doxygen command +@jsonapi{RS_VERSION,manualwrapper}+
|
|
||||||
and their wrappers are not automatically generated but written manually into
|
|
||||||
+JsonApiServer::JsonApiServer(...)+.
|
|
||||||
|
|
||||||
== Quirks
|
|
||||||
|
|
||||||
=== 64 bits integers handling
|
|
||||||
|
|
||||||
While JSON doesn't have problems representing 64 bits integers JavaScript, Dart
|
|
||||||
and other languages are not capable to handle those numbers natively.
|
|
||||||
To overcome this limitation JSON API output 64 bit integers as an object with
|
|
||||||
two keys, one as proper integer and one as string representation.
|
|
||||||
|
|
||||||
.JSON API 64 bit integer output example
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
"lobby_id": { "xint64": 6215642878098695544, "xstr64": "6215642878098695544" }
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
So from languages that have proper 64bit integers support like Python or C++ one
|
|
||||||
better read from `xint64` which is represented as a JSON integer, from languages
|
|
||||||
where there is no proper 64bit integers support like JavaScript one can read from
|
|
||||||
`xstr64` which is represented as JSON string (note that the first is not wrapped
|
|
||||||
in "" while the latter is).
|
|
||||||
|
|
||||||
When one input a 64bit integer into the JSON API it first try to parse it as if
|
|
||||||
it was sent the old way for retrocompatibility.
|
|
||||||
|
|
||||||
.JSON API 64 bit integer deprecated format input example
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
"lobby_id":6215642878098695544
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
This way is *DEPRECATED* and may disappear in the future, it is TEMPORALLY kept
|
|
||||||
only for retrocompatibiliy with old clients.
|
|
||||||
|
|
||||||
If retrocompatible parsing attempt fail then it try to parse with the new way
|
|
||||||
with proper JSON integer format.
|
|
||||||
|
|
||||||
.JSON API 64 bit integer new proper integer format input example
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
lobby_id": { "xint64": 6215642878098695544 }
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
If this fails then it try to parse with the new way with JSON string format.
|
|
||||||
|
|
||||||
.JSON API 64 bit integer new string format input example
|
|
||||||
[source,json]
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
"lobby_id": { "xstr64": "6215642878098695544" }
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
[WARNING]
|
|
||||||
================================================================================
|
|
||||||
Clients written in languages without proper 64bit integers support must
|
|
||||||
use *ONLY* the string format otherwise they will send approximated values and
|
|
||||||
get unexpected results from the JSON API, because parsing will success but the
|
|
||||||
value will not be exactly the one you believe you sent.
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
== A bit of history
|
|
||||||
|
|
||||||
=== First writings about this
|
|
||||||
|
|
||||||
The previous attempt of exposing a RetroShare JSON API is called +libresapi+ and
|
|
||||||
unfortunatley it requires a bunch of boilerplate code when we want to expose
|
|
||||||
something present in the {Cxx} API in the JSON API.
|
|
||||||
|
|
||||||
As an example here you can see the libresapi that exposes part of the retroshare
|
|
||||||
chat {Cxx} API and lot of boilerplate code just to convert {Cxx} objects to JSON
|
|
||||||
|
|
||||||
https://github.com/RetroShare/RetroShare/blob/v0.6.4/libresapi/src/api/ChatHandler.cpp#L44
|
|
||||||
|
|
||||||
To avoid the {Cxx} to JSON and back conversion boilerplate code I have worked out
|
|
||||||
an extension to our {Cxx} serialization code so it is capable to serialize and
|
|
||||||
deserialize to JSON you can see it in this pull request
|
|
||||||
|
|
||||||
https://github.com/RetroShare/RetroShare/pull/1155
|
|
||||||
|
|
||||||
So first step toward having a good API is to take advantage of the fact that RS
|
|
||||||
is now capable of converting C++ objects from and to JSON.
|
|
||||||
|
|
||||||
The current API is accessible via HTTP and unix socket, there is no
|
|
||||||
authentication in both of them, so anyone having access to the HTTP server or to
|
|
||||||
the unix socket can access the API without extra restrictions.
|
|
||||||
Expecially for the HTTP API this is a big risk because also if the http server
|
|
||||||
listen on 127.0.0.1 every application on the machine (even rogue javascript
|
|
||||||
running on your web browser) can access that and for example on android it is
|
|
||||||
not safe at all (because of that I implemented the unix socket access so at
|
|
||||||
least in android API was reasonably safe) because of this.
|
|
||||||
|
|
||||||
A second step to improve the API would be to implement some kind of API
|
|
||||||
authentication mechanism (it would be nice that the mechanism is handled at API
|
|
||||||
level and not at transport level so we can use it for any API trasport not just
|
|
||||||
HTTP for example)
|
|
||||||
|
|
||||||
The HTTP server used by libresapi is libmicrohttpd server that is very minimal,
|
|
||||||
it doesn't provide HTTPS nor modern HTTP goodies, like server notifications,
|
|
||||||
websockets etc. because the lack of support we have a token polling mechanism in
|
|
||||||
libresapi to avoid polling for every thing but it is still ugly, so if we can
|
|
||||||
completely get rid of polling in the API that would be really nice.
|
|
||||||
I have done a crawl to look for a replacement and briefly looked at
|
|
||||||
|
|
||||||
- https://www.gnu.org/software/libmicrohttpd/
|
|
||||||
- http://wolkykim.github.io/libasyncd/
|
|
||||||
- https://github.com/corvusoft/restbed
|
|
||||||
- https://code.facebook.com/posts/1503205539947302/introducing-proxygen-facebook-s-c-http-framework/
|
|
||||||
- https://github.com/cmouse/yahttp
|
|
||||||
|
|
||||||
taking in account a few metrics like modern HTTP goodies support, license,
|
|
||||||
platform support, external dependencies and documentation it seemed to me that
|
|
||||||
restbed is the more appropriate.
|
|
||||||
|
|
||||||
Another source of boilerplate code into libresapi is the mapping between JSON
|
|
||||||
API requests and C++ API methods as an example you can look at this
|
|
||||||
|
|
||||||
https://github.com/RetroShare/RetroShare/blob/v0.6.4/libresapi/src/api/ChatHandler.cpp#L158
|
|
||||||
|
|
||||||
and this
|
|
||||||
|
|
||||||
https://github.com/RetroShare/RetroShare/blob/v0.6.4/libresapi/src/api/ApiServer.cpp#L253
|
|
||||||
|
|
||||||
The abstract logic of this thing is, when libreasapi get a request like
|
|
||||||
+/chat/initiate_distant_chat+ then call
|
|
||||||
+ChatHandler::handleInitiateDistantChatConnexion+ which in turn is just a
|
|
||||||
wrapper of +RsMsgs::initiateDistantChatConnexion+ all this process is basically
|
|
||||||
implemented as boilerplate code and would be unnecessary in a smarter design of
|
|
||||||
the API because almost all the information needed is already present in the
|
|
||||||
C++ API +libretroshare/src/retroshare+.
|
|
||||||
|
|
||||||
So a third step to improve the JSON API would be to remove this source of
|
|
||||||
boilerplate code by automatizing the mapping between C++ and JSON API call.
|
|
||||||
|
|
||||||
This may result a little tricky as language parsing or other adevanced things
|
|
||||||
may be required.
|
|
||||||
|
|
||||||
Hope this dive is useful for you +
|
|
||||||
Cheers +
|
|
||||||
G10h4ck
|
|
||||||
|
|
||||||
=== Second writings about this
|
|
||||||
|
|
||||||
I have been investigating a bit more about:
|
|
||||||
[verse, G10h4ck]
|
|
||||||
________________________________________________________________________________
|
|
||||||
So a third step to improve the JSON API would be to remove this source of
|
|
||||||
boilerplate code by automatizing the mapping between C++ and JSON API call
|
|
||||||
________________________________________________________________________________
|
|
||||||
|
|
||||||
After spending some hours investigating this topic the most reasonable approach
|
|
||||||
seems to:
|
|
||||||
|
|
||||||
1. Properly document headers in +libretroshare/src/retroshare/+ in doxygen syntax
|
|
||||||
specifying wihich params are input and/or output (doxygen sysntax for this is
|
|
||||||
+@param[in/out/inout]+) this will be the API documentation too.
|
|
||||||
|
|
||||||
2. At compile time use doxygen to generate XML description of the headers and use
|
|
||||||
the XML to generate the JSON api server stub.
|
|
||||||
http://www.stack.nl/~dimitri/doxygen/manual/customize.html#xmlgenerator
|
|
||||||
|
|
||||||
3. Enjoy
|
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* RetroShare JSON API *
|
|
||||||
* *
|
|
||||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License version 3 as *
|
|
||||||
* published by the Free Software Foundation. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
registerHandler( "$%apiPath%$",
|
|
||||||
[this](const std::shared_ptr<rb::Session> session)
|
|
||||||
{
|
|
||||||
const std::multimap<std::string, std::string> headers
|
|
||||||
{
|
|
||||||
{ "Connection", "keep-alive" },
|
|
||||||
{ "Content-Type", "text/event-stream" }
|
|
||||||
};
|
|
||||||
session->yield(rb::OK, headers);
|
|
||||||
|
|
||||||
size_t reqSize = session->get_request()->get_header("Content-Length", 0);
|
|
||||||
session->fetch( reqSize, [this](
|
|
||||||
const std::shared_ptr<rb::Session> session,
|
|
||||||
const rb::Bytes& body )
|
|
||||||
{
|
|
||||||
INITIALIZE_API_CALL_JSON_CONTEXT;
|
|
||||||
|
|
||||||
if( !checkRsServicePtrReady(
|
|
||||||
$%instanceName%$, "$%instanceName%$", cAns, session ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
$%paramsDeclaration%$
|
|
||||||
|
|
||||||
$%inputParamsDeserialization%$
|
|
||||||
|
|
||||||
const std::weak_ptr<rb::Service> weakService(mService);
|
|
||||||
const std::weak_ptr<rb::Session> weakSession(session);
|
|
||||||
$%callbackName%$ = [weakService, weakSession]($%callbackParams%$)
|
|
||||||
{
|
|
||||||
auto session = weakSession.lock();
|
|
||||||
if(!session || session->is_closed()) return;
|
|
||||||
|
|
||||||
auto lService = weakService.lock();
|
|
||||||
if(!lService || lService->is_down()) return;
|
|
||||||
|
|
||||||
$%callbackParamsSerialization%$
|
|
||||||
|
|
||||||
std::stringstream sStream;
|
|
||||||
sStream << "data: " << compactJSON << ctx.mJson << "\n\n";
|
|
||||||
const std::string message = sStream.str();
|
|
||||||
|
|
||||||
lService->schedule( [weakSession, message]()
|
|
||||||
{
|
|
||||||
auto session = weakSession.lock();
|
|
||||||
if(!session || session->is_closed()) return;
|
|
||||||
session->yield(message);
|
|
||||||
$%sessionEarlyClose%$
|
|
||||||
} );
|
|
||||||
};
|
|
||||||
|
|
||||||
$%functionCall%$
|
|
||||||
|
|
||||||
$%outputParamsSerialization%$
|
|
||||||
|
|
||||||
// return them to the API caller
|
|
||||||
std::stringstream message;
|
|
||||||
message << "data: " << compactJSON << cAns.mJson << "\n\n";
|
|
||||||
session->yield(message.str());
|
|
||||||
$%sessionDelayedClose%$
|
|
||||||
} );
|
|
||||||
}, $%requiresAuth%$ );
|
|
1
jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl
Symbolic link
1
jsonapi-generator/src/async-method-wrapper-template.cpp.tmpl
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../libretroshare/src/jsonapi/async-method-wrapper-template.cpp.tmpl
|
|
@ -1,230 +0,0 @@
|
||||||
DOXYFILE_ENCODING = UTF-8
|
|
||||||
PROJECT_NAME = "libretroshare"
|
|
||||||
|
|
||||||
ALIASES += jsonapi{1}="\xmlonly<jsonapi minversion=\"\1\"/>\endxmlonly"
|
|
||||||
ALIASES += jsonapi{2}="\xmlonly<jsonapi minversion=\"\1\" access=\"\2\"/>\endxmlonly"
|
|
||||||
|
|
||||||
# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
|
|
||||||
# documentation from any documented member that it re-implements.
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
INHERIT_DOCS = YES
|
|
||||||
|
|
||||||
# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
|
|
||||||
# according to the Markdown format, which allows for more readable
|
|
||||||
# documentation. See http://daringfireball.net/projects/markdown/ for details.
|
|
||||||
# The output of markdown processing is further processed by doxygen, so you can
|
|
||||||
# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
|
|
||||||
# case of backward compatibilities issues.
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
MARKDOWN_SUPPORT = YES
|
|
||||||
|
|
||||||
# When enabled doxygen tries to link words that correspond to documented
|
|
||||||
# classes, or namespaces to their corresponding documentation. Such a link can
|
|
||||||
# be prevented in individual cases by putting a % sign in front of the word or
|
|
||||||
# globally by setting AUTOLINK_SUPPORT to NO.
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
AUTOLINK_SUPPORT = YES
|
|
||||||
|
|
||||||
|
|
||||||
# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
|
|
||||||
# documentation are documented, even if no documentation was available. Private
|
|
||||||
# class members and static file members will be hidden unless the
|
|
||||||
# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
|
|
||||||
# Note: This will also disable the warnings about undocumented members that are
|
|
||||||
# normally produced when WARNINGS is set to YES.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
EXTRACT_ALL = YES
|
|
||||||
|
|
||||||
|
|
||||||
# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
|
|
||||||
# undocumented members inside documented classes or files. If set to NO these
|
|
||||||
# members will be included in the various overviews, but no documentation
|
|
||||||
# section is generated. This option has no effect if EXTRACT_ALL is enabled.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
HIDE_UNDOC_MEMBERS = NO
|
|
||||||
|
|
||||||
# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
|
|
||||||
# undocumented classes that are normally visible in the class hierarchy. If set
|
|
||||||
# to NO, these classes will be included in the various overviews. This option
|
|
||||||
# has no effect if EXTRACT_ALL is enabled.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
HIDE_UNDOC_CLASSES = NO
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
# Configuration options related to the input files
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# The INPUT tag is used to specify the files and/or directories that contain
|
|
||||||
# documented source files. You may enter file names like myfile.cpp or
|
|
||||||
# directories like /usr/src/myproject. Separate the files or directories with
|
|
||||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
|
||||||
# Note: If this tag is empty the current directory is searched.
|
|
||||||
|
|
||||||
#INPUT =
|
|
||||||
|
|
||||||
# This tag can be used to specify the character encoding of the source files
|
|
||||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
|
||||||
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
|
|
||||||
# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
|
|
||||||
# possible encodings.
|
|
||||||
# The default value is: UTF-8.
|
|
||||||
|
|
||||||
INPUT_ENCODING = UTF-8
|
|
||||||
|
|
||||||
# If the value of the INPUT tag contains directories, you can use the
|
|
||||||
# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
|
|
||||||
# *.h) to filter out the source-files in the directories.
|
|
||||||
#
|
|
||||||
# Note that for custom extensions or not directly supported extensions you also
|
|
||||||
# need to set EXTENSION_MAPPING for the extension otherwise the files are not
|
|
||||||
# read by doxygen.
|
|
||||||
#
|
|
||||||
# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
|
|
||||||
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
|
|
||||||
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
|
|
||||||
# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
|
|
||||||
# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf.
|
|
||||||
|
|
||||||
FILE_PATTERNS = *.c \
|
|
||||||
*.cc \
|
|
||||||
*.cxx \
|
|
||||||
*.cpp \
|
|
||||||
*.c++ \
|
|
||||||
*.java \
|
|
||||||
*.ii \
|
|
||||||
*.ixx \
|
|
||||||
*.ipp \
|
|
||||||
*.i++ \
|
|
||||||
*.inl \
|
|
||||||
*.idl \
|
|
||||||
*.ddl \
|
|
||||||
*.odl \
|
|
||||||
*.h \
|
|
||||||
*.hh \
|
|
||||||
*.hxx \
|
|
||||||
*.hpp \
|
|
||||||
*.h++ \
|
|
||||||
*.cs \
|
|
||||||
*.d \
|
|
||||||
*.php \
|
|
||||||
*.php4 \
|
|
||||||
*.php5 \
|
|
||||||
*.phtml \
|
|
||||||
*.inc \
|
|
||||||
*.m \
|
|
||||||
*.markdown \
|
|
||||||
*.md \
|
|
||||||
*.mm \
|
|
||||||
*.dox \
|
|
||||||
*.py \
|
|
||||||
*.pyw \
|
|
||||||
*.f90 \
|
|
||||||
*.f95 \
|
|
||||||
*.f03 \
|
|
||||||
*.f08 \
|
|
||||||
*.f \
|
|
||||||
*.for \
|
|
||||||
*.tcl \
|
|
||||||
*.vhd \
|
|
||||||
*.vhdl \
|
|
||||||
*.ucf \
|
|
||||||
*.qsf
|
|
||||||
|
|
||||||
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
|
||||||
# be searched for input files as well.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
RECURSIVE = YES
|
|
||||||
|
|
||||||
# The EXCLUDE tag can be used to specify files and/or directories that should be
|
|
||||||
# excluded from the INPUT source files. This way you can easily exclude a
|
|
||||||
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
|
||||||
#
|
|
||||||
# Note that relative paths are relative to the directory from which doxygen is
|
|
||||||
# run.
|
|
||||||
|
|
||||||
EXCLUDE =
|
|
||||||
|
|
||||||
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
|
|
||||||
# directories that are symbolic links (a Unix file system feature) are excluded
|
|
||||||
# from the input.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
EXCLUDE_SYMLINKS = NO
|
|
||||||
|
|
||||||
# If the value of the INPUT tag contains directories, you can use the
|
|
||||||
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
|
|
||||||
# certain files from those directories.
|
|
||||||
#
|
|
||||||
# Note that the wildcards are matched against the file with absolute path, so to
|
|
||||||
# exclude all test directories for example use the pattern */test/*
|
|
||||||
|
|
||||||
EXCLUDE_PATTERNS =
|
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
|
||||||
# output. The symbol name can be a fully qualified name, a word, or if the
|
|
||||||
# wildcard * is used, a substring. Examples: ANamespace, AClass,
|
|
||||||
# AClass::ANamespace, ANamespace::*Test
|
|
||||||
#
|
|
||||||
# Note that the wildcards are matched against the file with absolute path, so to
|
|
||||||
# exclude all test directories use the pattern */test/*
|
|
||||||
|
|
||||||
EXCLUDE_SYMBOLS =
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
# Configuration options related to the HTML output
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
GENERATE_HTML = NO
|
|
||||||
|
|
||||||
# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
GENERATE_LATEX = NO
|
|
||||||
|
|
||||||
# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
|
|
||||||
# captures the structure of the code including all documentation.
|
|
||||||
# The default value is: NO.
|
|
||||||
|
|
||||||
GENERATE_XML = YES
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
# Configuration options related to the preprocessor
|
|
||||||
#---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
|
|
||||||
# C-preprocessor directives found in the sources and include files.
|
|
||||||
# The default value is: YES.
|
|
||||||
|
|
||||||
ENABLE_PREPROCESSING = YES
|
|
||||||
|
|
||||||
# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
|
|
||||||
# in the source code. If set to NO, only conditional compilation will be
|
|
||||||
# performed. Macro expansion can be done in a controlled way by setting
|
|
||||||
# EXPAND_ONLY_PREDEF to YES.
|
|
||||||
# The default value is: NO.
|
|
||||||
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
|
||||||
|
|
||||||
MACRO_EXPANSION = NO
|
|
||||||
|
|
||||||
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
|
|
||||||
# the macro expansion is limited to the macros specified with the PREDEFINED and
|
|
||||||
# EXPAND_AS_DEFINED tags.
|
|
||||||
# The default value is: NO.
|
|
||||||
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
|
||||||
|
|
||||||
EXPAND_ONLY_PREDEF = NO
|
|
||||||
|
|
1
jsonapi-generator/src/jsonapi-generator-doxygen.conf
Symbolic link
1
jsonapi-generator/src/jsonapi-generator-doxygen.conf
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../libretroshare/src/jsonapi/jsonapi-generator-doxygen.conf
|
|
@ -1,50 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* RetroShare JSON API *
|
|
||||||
* *
|
|
||||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
registerHandler( "$%apiPath%$",
|
|
||||||
[](const std::shared_ptr<rb::Session> session)
|
|
||||||
{
|
|
||||||
size_t reqSize = session->get_request()->get_header("Content-Length", 0);
|
|
||||||
session->fetch( reqSize, [](
|
|
||||||
const std::shared_ptr<rb::Session> session,
|
|
||||||
const rb::Bytes& body )
|
|
||||||
{
|
|
||||||
INITIALIZE_API_CALL_JSON_CONTEXT;
|
|
||||||
|
|
||||||
if( !checkRsServicePtrReady(
|
|
||||||
$%instanceName%$, "$%instanceName%$", cAns, session ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
$%paramsDeclaration%$
|
|
||||||
|
|
||||||
// deserialize input parameters from JSON
|
|
||||||
$%inputParamsDeserialization%$
|
|
||||||
|
|
||||||
// call retroshare C++ API
|
|
||||||
$%functionCall%$
|
|
||||||
|
|
||||||
// serialize out parameters and return value to JSON
|
|
||||||
$%outputParamsSerialization%$
|
|
||||||
|
|
||||||
// return them to the API caller
|
|
||||||
DEFAULT_API_CALL_JSON_RETURN(rb::OK);
|
|
||||||
} );
|
|
||||||
}, $%requiresAuth%$ );
|
|
||||||
|
|
1
jsonapi-generator/src/method-wrapper-template.cpp.tmpl
Symbolic link
1
jsonapi-generator/src/method-wrapper-template.cpp.tmpl
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../libretroshare/src/jsonapi/method-wrapper-template.cpp.tmpl
|
1
libbitdht
Submodule
1
libbitdht
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 659423769541169457c41f71c8a038e2d64ba079
|
|
@ -1,25 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: (C) 2004-2019 Retroshare Team <contact@retroshare.cc>
|
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
|
||||||
|
|
||||||
What's in the Package
|
|
||||||
---------------------------------------------------------------
|
|
||||||
bitdht - base BitDHT Code.
|
|
||||||
util - generic utils for networking and threading.
|
|
||||||
udp - UDP interfacing code.
|
|
||||||
lib - Where the library is created.
|
|
||||||
tests - basic unit tests.
|
|
||||||
example - example code of how to use libbitdht.
|
|
||||||
libbitdht.pro - build script for Qt's qmake.
|
|
||||||
README.txt - this file.
|
|
||||||
|
|
||||||
|
|
||||||
HOWTO libbitdht.
|
|
||||||
----------------------------------------------
|
|
||||||
This version is build using Qt's qmake system.
|
|
||||||
|
|
||||||
1) Install Qt's qmake system: libqt-dev
|
|
||||||
2) type ./qmake
|
|
||||||
3) type ./make
|
|
||||||
4) check out the example and tests to learn how to interface with libbitdht.
|
|
||||||
|
|
||||||
|
|
|
@ -1,133 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdaccount.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdaccount.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
|
|
||||||
#define LPF_FACTOR (0.90)
|
|
||||||
|
|
||||||
bdAccount::bdAccount()
|
|
||||||
:mNoStats(BDACCOUNT_NUM_ENTRIES),
|
|
||||||
mCountersOut(BDACCOUNT_NUM_ENTRIES), mCountersRecv(BDACCOUNT_NUM_ENTRIES),
|
|
||||||
mLpfOut(BDACCOUNT_NUM_ENTRIES), mLpfRecv(BDACCOUNT_NUM_ENTRIES),
|
|
||||||
mLabel(BDACCOUNT_NUM_ENTRIES)
|
|
||||||
{
|
|
||||||
|
|
||||||
mLabel[BDACCOUNT_MSG_OUTOFDATEPING] = "OUTOFDATEPING ";
|
|
||||||
mLabel[BDACCOUNT_MSG_PING] = "PING ";
|
|
||||||
mLabel[BDACCOUNT_MSG_PONG] = "PONG ";
|
|
||||||
mLabel[BDACCOUNT_MSG_QUERYNODE] = "QUERYNODE ";
|
|
||||||
mLabel[BDACCOUNT_MSG_QUERYHASH] = "QUERYHASH ";
|
|
||||||
mLabel[BDACCOUNT_MSG_REPLYFINDNODE] = "REPLYFINDNODE ";
|
|
||||||
mLabel[BDACCOUNT_MSG_REPLYQUERYHASH] = "REPLYQUERYHASH ";
|
|
||||||
|
|
||||||
mLabel[BDACCOUNT_MSG_POSTHASH] = "POSTHASH ";
|
|
||||||
mLabel[BDACCOUNT_MSG_REPLYPOSTHASH] = "REPLYPOSTHASH ";
|
|
||||||
|
|
||||||
mLabel[BDACCOUNT_MSG_CONNECTREQUEST] = "CONNECTREQUEST ";
|
|
||||||
mLabel[BDACCOUNT_MSG_CONNECTREPLY] = "CONNECTREPLY ";
|
|
||||||
mLabel[BDACCOUNT_MSG_CONNECTSTART] = "CONNECTSTART ";
|
|
||||||
mLabel[BDACCOUNT_MSG_CONNECTACK] = "CONNECTACK ";
|
|
||||||
|
|
||||||
resetStats();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdAccount::incCounter(uint32_t idx, bool out)
|
|
||||||
{
|
|
||||||
if ((signed) idx > mNoStats-1)
|
|
||||||
{
|
|
||||||
std::cerr << "bdAccount::incCounter() Invalid Index";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out)
|
|
||||||
{
|
|
||||||
mCountersOut[idx]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mCountersRecv[idx]++;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdAccount::doStats()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < mNoStats; i++)
|
|
||||||
{
|
|
||||||
mLpfOut[i] *= (LPF_FACTOR) ;
|
|
||||||
mLpfOut[i] += (1.0 - LPF_FACTOR) * mCountersOut[i];
|
|
||||||
|
|
||||||
mLpfRecv[i] *= (LPF_FACTOR) ;
|
|
||||||
mLpfRecv[i] += (1.0 - LPF_FACTOR) * mCountersRecv[i];
|
|
||||||
}
|
|
||||||
resetCounters();
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdAccount::printStats(std::ostream &out)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
out << " Send Recv: ";
|
|
||||||
out << std::endl;
|
|
||||||
for(i = 0; i < mNoStats; i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
out << "Send" << mLabel[i] << " : " << std::setw(10) << mLpfOut[i];
|
|
||||||
out << " ";
|
|
||||||
out << "Recv" << mLabel[i] << " : " << std::setw(10) << mLpfRecv[i];
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdAccount::resetCounters()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < mNoStats; i++)
|
|
||||||
{
|
|
||||||
mCountersOut[i] = 0;
|
|
||||||
mCountersRecv[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdAccount::resetStats()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < mNoStats; i++)
|
|
||||||
{
|
|
||||||
mLpfOut[i] = 0;
|
|
||||||
mLpfRecv[i] = 0;
|
|
||||||
}
|
|
||||||
resetCounters();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
#ifndef BITDHT_ACCOUNT_H
|
|
||||||
#define BITDHT_ACCOUNT_H
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdaccount.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#define BDACCOUNT_MSG_OUTOFDATEPING 0
|
|
||||||
#define BDACCOUNT_MSG_PING 1
|
|
||||||
#define BDACCOUNT_MSG_PONG 2
|
|
||||||
#define BDACCOUNT_MSG_QUERYNODE 3
|
|
||||||
#define BDACCOUNT_MSG_QUERYHASH 4
|
|
||||||
#define BDACCOUNT_MSG_REPLYFINDNODE 5
|
|
||||||
#define BDACCOUNT_MSG_REPLYQUERYHASH 6
|
|
||||||
|
|
||||||
#define BDACCOUNT_MSG_POSTHASH 7
|
|
||||||
#define BDACCOUNT_MSG_REPLYPOSTHASH 8
|
|
||||||
|
|
||||||
#define BDACCOUNT_MSG_CONNECTREQUEST 9
|
|
||||||
#define BDACCOUNT_MSG_CONNECTREPLY 10
|
|
||||||
#define BDACCOUNT_MSG_CONNECTSTART 11
|
|
||||||
#define BDACCOUNT_MSG_CONNECTACK 12
|
|
||||||
|
|
||||||
#define BDACCOUNT_NUM_ENTRIES 13
|
|
||||||
|
|
||||||
class bdAccount
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdAccount();
|
|
||||||
|
|
||||||
void incCounter(uint32_t idx, bool out);
|
|
||||||
void doStats();
|
|
||||||
void printStats(std::ostream &out);
|
|
||||||
void resetCounters();
|
|
||||||
void resetStats();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int mNoStats;
|
|
||||||
|
|
||||||
std::vector<double> mCountersOut;
|
|
||||||
std::vector<double> mCountersRecv;
|
|
||||||
|
|
||||||
std::vector<double> mLpfOut;
|
|
||||||
std::vector<double> mLpfRecv;
|
|
||||||
|
|
||||||
std::vector<std::string> mLabel;
|
|
||||||
// Statistics.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BITDHT_ACCOUNT_H
|
|
|
@ -1,267 +0,0 @@
|
||||||
1.162.168.21 8956
|
|
||||||
2.6.224.136 17320
|
|
||||||
5.116.142.222 13755
|
|
||||||
5.189.185.57 6968
|
|
||||||
5.202.101.3 4000
|
|
||||||
5.227.124.122 1024
|
|
||||||
5.227.124.122 20600
|
|
||||||
5.227.124.122 64196
|
|
||||||
5.39.94.218 6991
|
|
||||||
5.79.102.9 6881
|
|
||||||
5.89.120.163 2457
|
|
||||||
14.117.182.22 1091
|
|
||||||
14.8.109.32 17160
|
|
||||||
23.115.236.180 42375
|
|
||||||
24.153.98.173 1024
|
|
||||||
24.38.199.13 10583
|
|
||||||
27.150.87.242 1123
|
|
||||||
27.151.179.38 51413
|
|
||||||
27.152.212.182 1424
|
|
||||||
31.24.186.40 16143
|
|
||||||
31.36.78.93 30020
|
|
||||||
31.44.90.218 51413
|
|
||||||
37.120.213.132 19525
|
|
||||||
37.14.113.18 3815
|
|
||||||
37.146.76.158 51413
|
|
||||||
37.187.105.230 5169
|
|
||||||
37.232.184.93 6881
|
|
||||||
37.46.150.58 51413
|
|
||||||
39.111.152.200 17527
|
|
||||||
39.154.68.57 28007
|
|
||||||
42.200.116.4 18578
|
|
||||||
42.3.188.207 19771
|
|
||||||
45.176.111.21 1434
|
|
||||||
45.32.43.51 49091
|
|
||||||
45.76.218.165 52911
|
|
||||||
45.77.214.200 44350
|
|
||||||
46.172.86.23 46039
|
|
||||||
46.223.161.46 23693
|
|
||||||
46.237.96.68 16536
|
|
||||||
46.52.174.214 24012
|
|
||||||
46.7.227.47 27644
|
|
||||||
46.7.9.41 21374
|
|
||||||
49.64.73.215 51413
|
|
||||||
49.74.50.28 60893
|
|
||||||
49.75.73.147 51413
|
|
||||||
49.79.26.15 51413
|
|
||||||
49.83.226.50 20864
|
|
||||||
49.83.241.222 51413
|
|
||||||
52.9.197.152 6881
|
|
||||||
58.209.188.12 20994
|
|
||||||
59.149.118.196 51413
|
|
||||||
59.2.250.243 57099
|
|
||||||
59.6.53.18 57437
|
|
||||||
60.104.89.4 51413
|
|
||||||
60.124.114.239 16925
|
|
||||||
60.178.44.27 1050
|
|
||||||
60.99.229.14 20617
|
|
||||||
61.223.34.21 17881
|
|
||||||
61.227.127.222 22223
|
|
||||||
61.239.28.169 18873
|
|
||||||
62.210.82.193 51413
|
|
||||||
64.191.5.92 56891
|
|
||||||
65.92.141.96 58361
|
|
||||||
67.215.246.10 6881
|
|
||||||
68.151.213.83 20047
|
|
||||||
69.40.178.254 50793
|
|
||||||
71.34.2.150 8053
|
|
||||||
72.95.247.56 12956
|
|
||||||
73.157.77.166 5477
|
|
||||||
74.109.243.24 7250
|
|
||||||
74.140.153.59 24757
|
|
||||||
74.72.13.99 9613
|
|
||||||
76.29.106.98 41447
|
|
||||||
77.202.207.190 33034
|
|
||||||
77.21.64.116 22222
|
|
||||||
77.245.14.94 9910
|
|
||||||
78.131.78.35 51238
|
|
||||||
78.158.1.15 7433
|
|
||||||
78.231.125.98 12162
|
|
||||||
78.242.250.55 55946
|
|
||||||
79.164.245.5 49001
|
|
||||||
80.147.23.201 32746
|
|
||||||
80.200.171.90 16294
|
|
||||||
80.99.222.34 51414
|
|
||||||
81.171.17.30 42254
|
|
||||||
82.221.103.244 6881
|
|
||||||
82.235.78.193 44097
|
|
||||||
82.244.32.78 43518
|
|
||||||
82.64.181.170 38240
|
|
||||||
82.64.249.25 51413
|
|
||||||
82.64.44.119 51413
|
|
||||||
82.65.164.218 15726
|
|
||||||
82.65.68.9 51413
|
|
||||||
82.77.146.109 53713
|
|
||||||
83.46.92.34 50000
|
|
||||||
84.195.46.218 54600
|
|
||||||
84.40.106.115 12046
|
|
||||||
85.149.0.42 21045
|
|
||||||
86.121.194.1 51413
|
|
||||||
86.98.50.30 21455
|
|
||||||
87.123.166.45 4145
|
|
||||||
87.169.199.211 10496
|
|
||||||
88.7.217.202 31348
|
|
||||||
88.99.25.154 38051
|
|
||||||
89.135.26.33 51413
|
|
||||||
89.17.134.184 10327
|
|
||||||
89.245.86.20 32417
|
|
||||||
89.253.118.133 8621
|
|
||||||
90.101.94.104 20780
|
|
||||||
90.151.95.110 2199
|
|
||||||
90.219.241.30 51413
|
|
||||||
90.219.8.170 11916
|
|
||||||
91.121.136.132 59001
|
|
||||||
91.123.72.241 49001
|
|
||||||
91.142.65.40 51413
|
|
||||||
91.173.208.204 16300
|
|
||||||
91.211.245.40 7369
|
|
||||||
91.92.194.144 1031
|
|
||||||
91.98.96.76 5385
|
|
||||||
92.244.238.115 3115
|
|
||||||
92.97.68.210 58000
|
|
||||||
93.100.182.236 32249
|
|
||||||
93.11.175.113 22948
|
|
||||||
93.115.202.240 64493
|
|
||||||
93.152.132.9 12332
|
|
||||||
94.154.81.100 12345
|
|
||||||
94.222.188.14 29299
|
|
||||||
95.211.117.105 62086
|
|
||||||
95.219.143.102 10360
|
|
||||||
95.222.119.133 43087
|
|
||||||
95.42.138.33 16550
|
|
||||||
96.39.191.231 52000
|
|
||||||
99.192.24.198 52552
|
|
||||||
103.226.250.79 3521
|
|
||||||
103.82.242.163 8083
|
|
||||||
104.156.238.118 34731
|
|
||||||
104.237.149.26 64879
|
|
||||||
107.155.5.39 6881
|
|
||||||
109.129.202.63 11076
|
|
||||||
109.148.168.121 21651
|
|
||||||
109.24.244.111 33334
|
|
||||||
110.81.114.66 24732
|
|
||||||
111.175.84.3 6881
|
|
||||||
111.216.9.68 13493
|
|
||||||
113.105.18.227 16001
|
|
||||||
113.194.69.53 53858
|
|
||||||
113.219.200.7 12935
|
|
||||||
113.252.78.238 23474
|
|
||||||
113.68.239.87 6396
|
|
||||||
113.69.96.171 51443
|
|
||||||
114.188.193.161 22555
|
|
||||||
114.231.190.193 51413
|
|
||||||
114.232.201.253 30350
|
|
||||||
114.32.153.245 26233
|
|
||||||
114.32.1.94 7788
|
|
||||||
114.38.137.40 24062
|
|
||||||
114.75.44.238 6881
|
|
||||||
115.133.66.181 9460
|
|
||||||
115.205.157.105 51413
|
|
||||||
116.1.193.182 51413
|
|
||||||
117.247.200.35 5353
|
|
||||||
117.60.240.145 35709
|
|
||||||
117.60.62.8 51413
|
|
||||||
117.93.101.232 51413
|
|
||||||
118.123.245.182 5060
|
|
||||||
119.177.21.161 27048
|
|
||||||
119.64.245.112 56265
|
|
||||||
121.171.118.184 11566
|
|
||||||
121.178.169.67 49259
|
|
||||||
121.234.117.237 15398
|
|
||||||
122.116.102.22 14054
|
|
||||||
123.202.146.112 23118
|
|
||||||
123.217.135.139 7830
|
|
||||||
128.68.229.32 51413
|
|
||||||
134.209.114.242 8000
|
|
||||||
139.28.218.4 34826
|
|
||||||
142.113.115.71 26453
|
|
||||||
148.251.68.55 50000
|
|
||||||
148.70.53.219 2551
|
|
||||||
150.117.108.250 21902
|
|
||||||
150.117.44.190 25052
|
|
||||||
151.224.15.227 51413
|
|
||||||
157.157.157.41 51413
|
|
||||||
161.97.102.243 51902
|
|
||||||
162.208.6.211 51413
|
|
||||||
167.179.83.227 60220
|
|
||||||
168.70.68.30 18325
|
|
||||||
169.0.60.179 64494
|
|
||||||
171.5.165.129 6881
|
|
||||||
172.104.76.77 60542
|
|
||||||
172.104.93.28 35617
|
|
||||||
172.98.144.81 19186
|
|
||||||
173.176.138.246 9545
|
|
||||||
173.199.70.134 39045
|
|
||||||
173.212.205.73 51432
|
|
||||||
173.212.219.143 6881
|
|
||||||
174.89.174.228 51413
|
|
||||||
175.197.1.120 52574
|
|
||||||
176.9.8.143 58250
|
|
||||||
178.118.86.145 51413
|
|
||||||
178.162.139.87 10029
|
|
||||||
178.32.220.92 6881
|
|
||||||
178.67.121.182 49001
|
|
||||||
182.138.217.58 6881
|
|
||||||
182.138.90.72 50288
|
|
||||||
182.139.213.160 39587
|
|
||||||
183.131.239.178 57835
|
|
||||||
183.22.252.15 21568
|
|
||||||
185.126.33.59 50024
|
|
||||||
185.156.175.187 1025
|
|
||||||
185.157.221.247 25401
|
|
||||||
185.252.60.243 49001
|
|
||||||
185.45.195.156 28074
|
|
||||||
185.45.195.181 28185
|
|
||||||
185.45.195.190 28136
|
|
||||||
185.61.148.114 64879
|
|
||||||
188.133.192.123 19967
|
|
||||||
188.235.1.208 7890
|
|
||||||
188.240.208.187 51413
|
|
||||||
192.181.103.63 19627
|
|
||||||
192.241.151.29 6881
|
|
||||||
193.242.205.145 49001
|
|
||||||
193.77.153.124 59835
|
|
||||||
194.176.114.54 51413
|
|
||||||
194.35.233.206 20124
|
|
||||||
195.154.172.169 36097
|
|
||||||
195.154.172.169 38340
|
|
||||||
195.154.172.169 48043
|
|
||||||
195.154.172.169 48799
|
|
||||||
195.154.179.2 22794
|
|
||||||
195.154.179.2 41210
|
|
||||||
195.154.179.2 42687
|
|
||||||
195.154.179.2 49156
|
|
||||||
195.154.179.2 50385
|
|
||||||
195.154.179.2 50944
|
|
||||||
195.154.181.225 37558
|
|
||||||
195.191.246.240 1026
|
|
||||||
196.191.92.25 22937
|
|
||||||
197.157.219.137 22629
|
|
||||||
197.61.66.105 24612
|
|
||||||
198.13.48.70 37360
|
|
||||||
199.254.238.193 15374
|
|
||||||
200.63.107.82 13323
|
|
||||||
201.241.63.68 38705
|
|
||||||
203.130.242.178 28280
|
|
||||||
203.213.61.76 50559
|
|
||||||
207.154.222.13 51111
|
|
||||||
210.195.211.60 49771
|
|
||||||
210.6.145.50 15207
|
|
||||||
212.102.42.202 7611
|
|
||||||
212.129.19.188 27096
|
|
||||||
212.129.19.188 29812
|
|
||||||
212.129.19.188 50117
|
|
||||||
212.129.19.188 51965
|
|
||||||
212.129.33.59 6881
|
|
||||||
212.32.231.67 51413
|
|
||||||
212.86.51.7 65148
|
|
||||||
213.136.79.7 11910
|
|
||||||
218.161.100.192 51413
|
|
||||||
218.219.199.148 18753
|
|
||||||
220.189.94.56 13279
|
|
||||||
222.211.148.83 8080
|
|
||||||
222.77.110.143 46016
|
|
||||||
223.116.81.154 10655
|
|
||||||
223.16.153.107 51413
|
|
||||||
223.26.31.77 21440
|
|
||||||
223.65.101.235 25159
|
|
|
@ -1,55 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
<<LICENSE
|
|
||||||
|
|
||||||
Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
LICENSE
|
|
||||||
|
|
||||||
<<README
|
|
||||||
Generate a clean DHT bootstrap node list.
|
|
||||||
Feeds on previously known nodes from standard input and a few well known
|
|
||||||
mainline DHT bootstrap nodes. Prints only nodes that appears to be active to a
|
|
||||||
quick nmap check. Make sure your internet connection is working well before
|
|
||||||
using this.
|
|
||||||
|
|
||||||
Example usage:
|
|
||||||
--------------------------------
|
|
||||||
cat bdboot.txt | bdboot_generate.sh | tee /tmp/bdboot_generated.txt
|
|
||||||
cat /tmp/bdboot_generated.txt | sort -u > bdboot.txt
|
|
||||||
--------------------------------
|
|
||||||
README
|
|
||||||
|
|
||||||
function check_dht_host()
|
|
||||||
{
|
|
||||||
mHost="$1"
|
|
||||||
mPort="$2"
|
|
||||||
|
|
||||||
sudo nmap -oG - -sU -p $mPort $mHost | grep open | \
|
|
||||||
awk '{print $2" "$5}' | awk -F/ '{print $1}'
|
|
||||||
}
|
|
||||||
|
|
||||||
cat | while read line; do
|
|
||||||
hostIP="$(echo $line | awk '{print $1}')"
|
|
||||||
hostPort="$(echo $line | awk '{print $2}')"
|
|
||||||
check_dht_host $hostIP $hostPort
|
|
||||||
done
|
|
||||||
|
|
||||||
check_dht_host router.utorrent.com 6881
|
|
||||||
check_dht_host router.bittorrent.com 6881
|
|
||||||
check_dht_host dht.libtorrent.org 25401
|
|
||||||
check_dht_host dht.transmissionbt.com 6881
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,314 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdconnection.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BITDHT_CONNECTION_H
|
|
||||||
#define BITDHT_CONNECTION_H
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
|
|
||||||
class bdQueryManager;
|
|
||||||
class bdNodePublisher;
|
|
||||||
|
|
||||||
/************************************************************************************************************
|
|
||||||
************************************** ProxyTuple + Connection State ****************************************
|
|
||||||
************************************************************************************************************/
|
|
||||||
|
|
||||||
#define BITDHT_CONNREQUEST_READY 1
|
|
||||||
#define BITDHT_CONNREQUEST_PAUSED 2
|
|
||||||
#define BITDHT_CONNREQUEST_INPROGRESS 3
|
|
||||||
#define BITDHT_CONNREQUEST_EXTCONNECT 4
|
|
||||||
#define BITDHT_CONNREQUEST_DONE 5
|
|
||||||
|
|
||||||
#define BITDHT_CONNREQUEST_TIMEOUT_CONNECT 300 // MAKE THIS LARGE - SHOULD NEVER HAPPEN.
|
|
||||||
#define BITDHT_CONNREQUEST_TIMEOUT_INPROGRESS 30
|
|
||||||
#define BITDHT_CONNREQUEST_MAX_AGE 60
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_CONNECTION_WAITING_AUTH 1
|
|
||||||
#define BITDHT_CONNECTION_WAITING_REPLY 2
|
|
||||||
#define BITDHT_CONNECTION_WAITING_START 3
|
|
||||||
#define BITDHT_CONNECTION_WAITING_ACK 4
|
|
||||||
#define BITDHT_CONNECTION_COMPLETED 5
|
|
||||||
|
|
||||||
|
|
||||||
#define BD_CONNECTION_START_RETRY_PERIOD 3 // Should only take a couple of seconds to get reply.
|
|
||||||
#define BD_CONNECTION_START_MAX_RETRY 3
|
|
||||||
#define BD_CONNECTION_MAX_TIMEOUT 20 /* should be quick */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class bdProxyTuple
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdProxyTuple() { return; }
|
|
||||||
bdProxyTuple(bdNodeId *s, bdNodeId *p, bdNodeId *d)
|
|
||||||
:srcId(*s), proxyId(*p), destId(*d) { return; }
|
|
||||||
|
|
||||||
bdNodeId srcId;
|
|
||||||
bdNodeId proxyId;
|
|
||||||
bdNodeId destId;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const bdProxyTuple &t);
|
|
||||||
int operator<(const bdProxyTuple &a, const bdProxyTuple &b);
|
|
||||||
int operator==(const bdProxyTuple &a, const bdProxyTuple &b);
|
|
||||||
|
|
||||||
|
|
||||||
class bdConnection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdConnection();
|
|
||||||
|
|
||||||
/** Functions to tweak the connection status */
|
|
||||||
|
|
||||||
// User initialised Connection.
|
|
||||||
int ConnectionSetup(bdId *proxyId, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delay);
|
|
||||||
int ConnectionSetupDirect(bdId *destId, bdId *srcConnAddr);
|
|
||||||
|
|
||||||
// Initialise a new Connection. (receiving a Connection Request)
|
|
||||||
int ConnectionRequestDirect(bdId *id, bdId *srcConnAddr, bdId *destConnAddr);
|
|
||||||
int ConnectionRequestProxy(bdId *id, bdId *srcConnAddr, bdNodeId *ownId, bdId *destConnAddr, int mode, int delay);
|
|
||||||
int ConnectionRequestEnd(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode);
|
|
||||||
|
|
||||||
// Setup Finishing Stage, (receiving a Connection Reply).
|
|
||||||
int upgradeProxyConnectionToFinish(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delay, int status);
|
|
||||||
|
|
||||||
int AuthoriseDirectConnection(bdId *srcId, bdId *proxyId, bdId *destId, int mode, int loc);
|
|
||||||
int AuthoriseProxyConnection(bdId *srcId, bdId *proxyId, bdId *destId, int mode, int loc, int bandwidth);
|
|
||||||
int AuthoriseEndConnection(bdId *srcId, bdId *proxyId, bdId *destId, int mode, int loc, int delay);
|
|
||||||
|
|
||||||
int CompleteConnection(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int bandwidth, int delay);
|
|
||||||
|
|
||||||
int checkForDefaultConnectAddress();
|
|
||||||
|
|
||||||
/* Connection State, and TimeStamp of Update */
|
|
||||||
int mState;
|
|
||||||
time_t mLastEvent;
|
|
||||||
|
|
||||||
/* Addresses of Start/Proxy/End Nodes */
|
|
||||||
bdId mSrcId;
|
|
||||||
bdId mDestId;
|
|
||||||
bdId mProxyId;
|
|
||||||
|
|
||||||
/* Where we are in the connection,
|
|
||||||
* and what connection mode.
|
|
||||||
*/
|
|
||||||
int mPoint;
|
|
||||||
int mMode;
|
|
||||||
|
|
||||||
/* must have ip:ports of connection ends (if proxied) */
|
|
||||||
bdId mSrcConnAddr;
|
|
||||||
bdId mDestConnAddr;
|
|
||||||
|
|
||||||
int mBandwidth;
|
|
||||||
int mMaxDelay;
|
|
||||||
time_t mConnectionStartTS;
|
|
||||||
|
|
||||||
/* START/ACK Finishing ****/
|
|
||||||
time_t mLastStart; /* timer for retries */
|
|
||||||
int mRetryCount; /* retry counter */
|
|
||||||
|
|
||||||
bool mSrcAck;
|
|
||||||
bool mDestAck;
|
|
||||||
|
|
||||||
// Completion TS.
|
|
||||||
time_t mCompletedTS;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#define BD_PI_SRC_UNKNOWN 0
|
|
||||||
#define BD_PI_SRC_QUERYRESULT 1
|
|
||||||
#define BD_PI_SRC_QUERYPROXY 2
|
|
||||||
#define BD_PI_SRC_NODESPACE_FRIEND 3
|
|
||||||
#define BD_PI_SRC_NODESPACE_SERVER 4
|
|
||||||
#define BD_PI_SRC_NODESPACE_ENGINEVERSION 5
|
|
||||||
#define BD_PI_SRC_ADDGOODPROXY 6
|
|
||||||
|
|
||||||
|
|
||||||
class bdProxyId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdProxyId(const bdId &in_id, uint32_t in_srctype, uint32_t in_errcode)
|
|
||||||
:id(in_id), srcType(in_srctype), errcode(in_errcode) { return; }
|
|
||||||
|
|
||||||
bdProxyId() :srcType(BD_PI_SRC_UNKNOWN), errcode(0) { return; }
|
|
||||||
|
|
||||||
std::string proxySrcType() const;
|
|
||||||
|
|
||||||
bdId id;
|
|
||||||
uint32_t srcType;
|
|
||||||
uint32_t errcode;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdConnectionRequest
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdConnectionRequest() : mMode(0), mState(0), mStateTS(0), mPauseTS(0), mErrCode(0), mDelay(0), mRequestTS(0), mRecycled(0), mCurrentSrcType(0)
|
|
||||||
{
|
|
||||||
bdsockaddr_clear(&mLocalAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
int setupDirectConnection(struct sockaddr_in *laddr, bdNodeId *target);
|
|
||||||
int setupProxyConnection(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t delay);
|
|
||||||
|
|
||||||
int addGoodProxy(const bdId *srcId);
|
|
||||||
int checkGoodProxyPeer(const bdId *Id);
|
|
||||||
|
|
||||||
bdNodeId mTarget;
|
|
||||||
struct sockaddr_in mLocalAddr;
|
|
||||||
int mMode;
|
|
||||||
|
|
||||||
int mState;
|
|
||||||
time_t mStateTS;
|
|
||||||
|
|
||||||
time_t mPauseTS;
|
|
||||||
uint32_t mErrCode;
|
|
||||||
|
|
||||||
int mDelay;
|
|
||||||
time_t mRequestTS; // reference Time for mDelay.
|
|
||||||
|
|
||||||
std::list<bdProxyId> mGoodProxies;
|
|
||||||
std::list<bdId> mPotentialProxies;
|
|
||||||
//std::list<bdId> mGoodProxies;
|
|
||||||
int mRecycled;
|
|
||||||
|
|
||||||
bdId mCurrentAttempt;
|
|
||||||
uint32_t mCurrentSrcType;
|
|
||||||
|
|
||||||
std::list<bdProxyId> mPeersTried;
|
|
||||||
//std::list<bdId> mPeersTried;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const bdConnectionRequest &req);
|
|
||||||
std::ostream &operator<<(std::ostream &out, const bdConnection &conn);
|
|
||||||
|
|
||||||
|
|
||||||
/*********
|
|
||||||
* The Connection Management Class.
|
|
||||||
* this encapsulates all of the functionality..
|
|
||||||
* except for a couple of message in/outs + callback.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class bdConnectManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdConnectManager(bdNodeId *ownid, bdSpace *space, bdQueryManager *qmgr, bdDhtFunctions *fns, bdNodePublisher *pub);
|
|
||||||
|
|
||||||
|
|
||||||
/* connection functions */
|
|
||||||
void requestConnection(bdNodeId *id, uint32_t modes);
|
|
||||||
void allowConnection(bdNodeId *id, uint32_t modes);
|
|
||||||
|
|
||||||
|
|
||||||
/* high level */
|
|
||||||
|
|
||||||
void shutdownConnections();
|
|
||||||
void printConnections();
|
|
||||||
|
|
||||||
/* Connections: Configuration */
|
|
||||||
void defaultConnectionOptions();
|
|
||||||
virtual void setConnectionOptions(uint32_t allowedModes, uint32_t flags);
|
|
||||||
|
|
||||||
/* Connections: Initiation */
|
|
||||||
|
|
||||||
int requestConnection(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t delay, uint32_t start);
|
|
||||||
int requestConnection_direct(struct sockaddr_in *laddr, bdNodeId *target);
|
|
||||||
int requestConnection_proxy(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t delay);
|
|
||||||
|
|
||||||
int killConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
|
|
||||||
|
|
||||||
int checkExistingConnectionAttempt(bdNodeId *target);
|
|
||||||
void addPotentialConnectionProxy(const bdId *srcId, const bdId *target);
|
|
||||||
void updatePotentialConnectionProxy(const bdId *id, uint32_t mode);
|
|
||||||
|
|
||||||
int checkPeerForFlag(const bdId *id, uint32_t with_flag);
|
|
||||||
|
|
||||||
int tickConnections();
|
|
||||||
void iterateConnectionRequests();
|
|
||||||
int startConnectionAttempt(bdConnectionRequest *req);
|
|
||||||
|
|
||||||
// internal Callback -> normally continues to callbackConnect().
|
|
||||||
void callbackConnectRequest(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
int mode, int point, int param, int cbtype, int errcode);
|
|
||||||
|
|
||||||
/* Connections: Outgoing */
|
|
||||||
|
|
||||||
int startConnectionAttempt(bdId *proxyId, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delay);
|
|
||||||
void AuthConnectionOk(bdId *srcId, bdId *proxyId, bdId *destId, int mode, int loc, int bandwidth, int delay);
|
|
||||||
void AuthConnectionNo(bdId *srcId, bdId *proxyId, bdId *destId, int mode, int loc, int errcode);
|
|
||||||
void iterateConnections();
|
|
||||||
|
|
||||||
|
|
||||||
/* Connections: Utility State */
|
|
||||||
|
|
||||||
bdConnection *findExistingConnection(bdNodeId *srcId, bdNodeId *proxyId, bdNodeId *destId);
|
|
||||||
bdConnection *newConnection(bdNodeId *srcId, bdNodeId *proxyId, bdNodeId *destId);
|
|
||||||
int cleanConnection(bdNodeId *srcId, bdNodeId *proxyId, bdNodeId *destId);
|
|
||||||
|
|
||||||
int determinePosition(bdNodeId *sender, bdNodeId *src, bdNodeId *dest);
|
|
||||||
int determineProxyId(bdNodeId *sender, bdNodeId *src, bdNodeId *dest, bdNodeId *proxyId);
|
|
||||||
|
|
||||||
bdConnection *findSimilarConnection(bdNodeId *srcId, bdNodeId *destId);
|
|
||||||
bdConnection *findExistingConnectionBySender(bdId *sender, bdId *src, bdId *dest);
|
|
||||||
bdConnection *newConnectionBySender(bdId *sender, bdId *src, bdId *dest);
|
|
||||||
int cleanConnectionBySender(bdId *sender, bdId *src, bdId *dest);
|
|
||||||
|
|
||||||
// Overloaded Generalised Connection Callback.
|
|
||||||
virtual void callbackConnect(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
int mode, int point, int param, int cbtype, int errcode);
|
|
||||||
|
|
||||||
/* Connections: */
|
|
||||||
int recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delay);
|
|
||||||
int recvedConnectionReply(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delay, int status);
|
|
||||||
int recvedConnectionStart(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode, int delayOrBandwidth);
|
|
||||||
int recvedConnectionAck(bdId *id, bdId *srcConnAddr, bdId *destConnAddr, int mode);
|
|
||||||
|
|
||||||
/* setup Relay Mode */
|
|
||||||
void setRelayMode(uint32_t mode);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::map<bdProxyTuple, bdConnection> mConnections;
|
|
||||||
std::map<bdNodeId, bdConnectionRequest> mConnectionRequests;
|
|
||||||
|
|
||||||
uint32_t mConfigAllowedModes;
|
|
||||||
bool mConfigAutoProxy;
|
|
||||||
|
|
||||||
uint32_t mRelayMode;
|
|
||||||
|
|
||||||
/****************************** Connection Code (in bdconnection.cc) ****************************/
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bdNodeId mOwnId;
|
|
||||||
bdSpace *mNodeSpace;
|
|
||||||
bdQueryManager *mQueryMgr;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
bdNodePublisher *mPub;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BITDHT_CONNECTION_H
|
|
|
@ -1,318 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdfilter.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdfilter.h"
|
|
||||||
#include "bitdht/bdmanager.h"
|
|
||||||
#include "util/bdfile.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* #define DEBUG_FILTER 1
|
|
||||||
**/
|
|
||||||
#define BDFILTER_ENTRY_DROP_PERIOD (7 * 24 * 3600)
|
|
||||||
|
|
||||||
bdFilter::bdFilter(const std::string &fname, const bdNodeId *ownid, uint32_t filterFlags, bdDhtFunctions *fns, bdNodeManager *manager)
|
|
||||||
{
|
|
||||||
/* */
|
|
||||||
mOwnId = *ownid;
|
|
||||||
mFns = fns;
|
|
||||||
mFilename = fname ;
|
|
||||||
|
|
||||||
loadBannedIpFile() ;
|
|
||||||
|
|
||||||
mFilterFlags = filterFlags;
|
|
||||||
mNodeManager = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdFilter::writeBannedIpFile()
|
|
||||||
{
|
|
||||||
std::string filetmp = mFilename + ".tmp" ;
|
|
||||||
|
|
||||||
FILE *fd = fopen(filetmp.c_str(), "w");
|
|
||||||
|
|
||||||
if (!fd)
|
|
||||||
{
|
|
||||||
std::cerr << "(EE) bdFilter::writeBannedIpFile() FAILED to Open File " << mFilename << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( std::map<uint32_t,bdFilteredPeer>::iterator it=mFiltered.begin();it!=mFiltered.end();++it)
|
|
||||||
{
|
|
||||||
fprintf(fd, "%s %u %lu %lu\n", bdnet_inet_ntoa(it->second.mAddr.sin_addr).c_str(), it->second.mFilterFlags, it->second.mFilterTS, it->second.mLastSeen) ;
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
fprintf(stderr, "Storing Peer Address: %s \n", bdnet_inet_ntoa(it->second.mAddr.sin_addr).c_str()) ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
if(!bdFile::renameFile(filetmp,mFilename))
|
|
||||||
std::cerr << "Could not rename file !!" << std::endl;
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
else
|
|
||||||
std::cerr << "Successfully renamed file " << filetmp << " to " << mFilename << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdFilter::loadBannedIpFile()
|
|
||||||
{
|
|
||||||
char line[10240];
|
|
||||||
char addr_str[10240];
|
|
||||||
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
memset(&addr, 0, sizeof(struct sockaddr_in));
|
|
||||||
addr.sin_family = PF_INET;
|
|
||||||
|
|
||||||
FILE *fd = fopen(mFilename.c_str(),"r") ;
|
|
||||||
|
|
||||||
if(fd == NULL)
|
|
||||||
{
|
|
||||||
std::cerr << "(EE) Cannot load filter file " << mFilename << std::endl;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(line == fgets(line, 10240, fd))
|
|
||||||
{
|
|
||||||
uint32_t filter_flags ;
|
|
||||||
unsigned long long int filter_ts ;
|
|
||||||
unsigned long long int last_seen ;
|
|
||||||
|
|
||||||
if (4 == sscanf(line, "%s %u %llu %llu", addr_str, &filter_flags,&filter_ts,&last_seen))
|
|
||||||
{
|
|
||||||
if (bdnet_inet_aton(addr_str, &(addr.sin_addr)))
|
|
||||||
{
|
|
||||||
addr.sin_port = 0;
|
|
||||||
|
|
||||||
bdFilteredPeer peer;
|
|
||||||
|
|
||||||
peer.mAddr = addr;
|
|
||||||
peer.mFilterTS = filter_ts;
|
|
||||||
peer.mLastSeen = last_seen;
|
|
||||||
peer.mFilterFlags = filter_flags;
|
|
||||||
|
|
||||||
mFiltered[addr.sin_addr.s_addr] = peer ;
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << "Loaded filtered IP: " << std::string(addr_str) << " last seen: " << last_seen << ", TS=" << filter_ts << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
//bool bdFilter::filtered(std::list<bdFilteredPeer> &answer)
|
|
||||||
//{
|
|
||||||
// answer = mFiltered;
|
|
||||||
// return (answer.size() > 0);
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool bdFilter::filteredIPs(std::list<struct sockaddr_in> &answer)
|
|
||||||
{
|
|
||||||
std::map<uint32_t,bdFilteredPeer>::iterator it;
|
|
||||||
for(it = mFiltered.begin(); it != mFiltered.end(); it++)
|
|
||||||
{
|
|
||||||
answer.push_back(it->second.mAddr);
|
|
||||||
}
|
|
||||||
return (answer.size() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdFilter::checkPeer(const bdId *id, uint32_t mode)
|
|
||||||
{
|
|
||||||
bool add = false;
|
|
||||||
uint32_t flags = 0;
|
|
||||||
if ((mFilterFlags & BITDHT_FILTER_REASON_OWNID) &&
|
|
||||||
isOwnIdWithoutBitDhtFlags(id, mode))
|
|
||||||
{
|
|
||||||
add = true;
|
|
||||||
flags |= BITDHT_FILTER_REASON_OWNID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (add)
|
|
||||||
{
|
|
||||||
bool isNew = addPeerToFilter(id->addr, flags);
|
|
||||||
|
|
||||||
if (isNew)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdFilter::addPeerToFilter(const struct sockaddr_in& addr, uint32_t flags)
|
|
||||||
{
|
|
||||||
std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.find(addr.sin_addr.s_addr) ;
|
|
||||||
|
|
||||||
if(it != mFiltered.end())
|
|
||||||
{
|
|
||||||
it->second.mLastSeen = time(NULL);
|
|
||||||
it->second.mFilterFlags |= flags;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
bdFilteredPeer fp;
|
|
||||||
|
|
||||||
fp.mAddr = addr;
|
|
||||||
fp.mAddr.sin_port = 0;
|
|
||||||
fp.mFilterFlags = flags;
|
|
||||||
fp.mFilterTS = now;
|
|
||||||
fp.mLastSeen = now;
|
|
||||||
|
|
||||||
uint32_t saddr = addr.sin_addr.s_addr;
|
|
||||||
|
|
||||||
mFiltered[saddr] = fp;
|
|
||||||
|
|
||||||
std::cerr << "Adding New Banned Ip Address: " << bdnet_inet_ntoa(addr.sin_addr);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
writeBannedIpFile() ;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// void bdFilter::loadFilteredPeers(const std::list<bdFilteredPeer>& peers)
|
|
||||||
// {
|
|
||||||
// for(std::list<bdFilteredPeer>::iterator it = peers.begin(); it != peers.end();++it)
|
|
||||||
// {
|
|
||||||
// #ifdef DEBUG_FILTER
|
|
||||||
// std::cerr << "Loading filtered peer " << inet_ntoa(it->mAddr.sin_addr) << " Flags: " << it->mFilterFlags << " FilterTS: "
|
|
||||||
// << now - it->mFilterTS << " LastSeen: " << now - it->mLastSeen << std::endl;
|
|
||||||
// #endif
|
|
||||||
// uint32_t saddr = it->mAddr.sin_addr.s_addr;
|
|
||||||
// mFiltered[saddr] = *it ;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
void bdFilter::getFilteredPeers(std::list<bdFilteredPeer>& peers)
|
|
||||||
{
|
|
||||||
for(std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.begin(); it != mFiltered.end();++it)
|
|
||||||
peers.push_back(it->second) ;
|
|
||||||
}
|
|
||||||
/* fast check if the addr is in the structure */
|
|
||||||
int bdFilter::addrOkay(struct sockaddr_in *addr)
|
|
||||||
{
|
|
||||||
// first check upper layer
|
|
||||||
bool isAvailable, isBanned;
|
|
||||||
mNodeManager->doIsBannedCallback(addr, &isAvailable, &isBanned);
|
|
||||||
|
|
||||||
if(isAvailable) {
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << "bdFilter::addrOkay addr: " << inet_ntoa(addr->sin_addr) << " result from upper layer: " << (isBanned ? "banned" : "ok") << std::endl;
|
|
||||||
#endif
|
|
||||||
return !isBanned;
|
|
||||||
} else {
|
|
||||||
// fallback to own ban list
|
|
||||||
|
|
||||||
std::map<uint32_t,bdFilteredPeer>::const_iterator it = mFiltered.find(addr->sin_addr.s_addr);
|
|
||||||
if (it == mFiltered.end())
|
|
||||||
return 1; // Address is Okay
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << "Detected Packet From Banned Ip Address: " << inet_ntoa(addr->sin_addr);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdFilter::isOwnIdWithoutBitDhtFlags(const bdId *id, uint32_t peerFlags)
|
|
||||||
{
|
|
||||||
if (peerFlags & BITDHT_PEER_STATUS_RECV_PONG)
|
|
||||||
{
|
|
||||||
if (peerFlags & BITDHT_PEER_STATUS_DHT_ENGINE)
|
|
||||||
{
|
|
||||||
/* okay! */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now check distance */
|
|
||||||
bdMetric dist;
|
|
||||||
mFns->bdDistance(&mOwnId, &(id->id), &dist);
|
|
||||||
int bucket = mFns->bdBucketDistance(&dist);
|
|
||||||
|
|
||||||
/* if they match us... kill it */
|
|
||||||
if (bucket == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* periodically we want to cleanup the filter....
|
|
||||||
* if we haven't had an IP address reported as filtered for several hours.
|
|
||||||
* remove it from the list.
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool bdFilter::cleanupFilter()
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << "bdFilter: Checking current filter List:" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
time_t dropTime = now - BDFILTER_ENTRY_DROP_PERIOD;
|
|
||||||
|
|
||||||
for(std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.begin(); it != mFiltered.end();)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << "\t" << bdnet_inet_ntoa(it->second.mAddr.sin_addr);
|
|
||||||
std::cerr << " Flags: " << it->second.mFilterFlags;
|
|
||||||
std::cerr << " FilterTS: " << now - it->second.mFilterTS;
|
|
||||||
std::cerr << " LastSeen: " << now - it->second.mLastSeen;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (it->second.mLastSeen < dropTime)
|
|
||||||
{
|
|
||||||
/* remove from filter */
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << " OLD DROPPING" << std::endl;
|
|
||||||
#endif
|
|
||||||
std::map<uint32_t,bdFilteredPeer>::iterator tmp(it) ;
|
|
||||||
++tmp ;
|
|
||||||
|
|
||||||
mFiltered.erase(it);
|
|
||||||
it = tmp ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FILTER
|
|
||||||
std::cerr << " OK" << std::endl;
|
|
||||||
#endif
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdfilter.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BITDHT_FILTER_H
|
|
||||||
#define BITDHT_FILTER_H
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
/* Query result flags are in bdiface.h */
|
|
||||||
|
|
||||||
#define BITDHT_FILTER_REASON_OWNID 0x0001
|
|
||||||
|
|
||||||
class bdFilteredPeer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct sockaddr_in mAddr;
|
|
||||||
uint32_t mFilterFlags; /* reasons why we are filtering */
|
|
||||||
time_t mFilterTS;
|
|
||||||
time_t mLastSeen;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdNodeManager;
|
|
||||||
|
|
||||||
class bdFilter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdFilter(const std::string& fname, const bdNodeId *ownid, uint32_t filterFlags, bdDhtFunctions *fns, bdNodeManager *manager);
|
|
||||||
|
|
||||||
// get the answer.
|
|
||||||
//bool filtered(std::list<bdFilteredPeer> &answer);
|
|
||||||
bool filteredIPs(std::list<struct sockaddr_in> &answer);
|
|
||||||
|
|
||||||
//void loadFilteredPeers(const std::list<bdFilteredPeer>& peers) ;
|
|
||||||
void getFilteredPeers(std::list<bdFilteredPeer> &peers);
|
|
||||||
|
|
||||||
int checkPeer(const bdId *id, uint32_t peerFlags);
|
|
||||||
|
|
||||||
int addrOkay(struct sockaddr_in *addr);
|
|
||||||
int addPeerToFilter(const struct sockaddr_in &addr, uint32_t flags);
|
|
||||||
|
|
||||||
bool cleanupFilter();
|
|
||||||
|
|
||||||
void loadBannedIpFile() ;
|
|
||||||
void writeBannedIpFile() ;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool isOwnIdWithoutBitDhtFlags(const bdId *id, uint32_t peerFlags);
|
|
||||||
|
|
||||||
// searching for
|
|
||||||
bdNodeId mOwnId;
|
|
||||||
uint32_t mFilterFlags;
|
|
||||||
|
|
||||||
std::map<uint32_t,bdFilteredPeer> mFiltered;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
std::string mFilename ;
|
|
||||||
|
|
||||||
// have access to the manager for isBanned callback
|
|
||||||
bdNodeManager* mNodeManager;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,243 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdfriendlist.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdfriendlist.h"
|
|
||||||
#include "bitdht/bdstddht.h"
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
/*****
|
|
||||||
* #define DEBUG_FRIENDLIST 1
|
|
||||||
****/
|
|
||||||
|
|
||||||
bdFriendEntry::bdFriendEntry()
|
|
||||||
{
|
|
||||||
mFlags = 0;
|
|
||||||
mLastSeen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdFriendEntry::addrKnown(struct sockaddr_in *addr)
|
|
||||||
{
|
|
||||||
if (mFlags & BD_FRIEND_ENTRY_ADDR_OK)
|
|
||||||
{
|
|
||||||
if (mFlags & BD_FRIEND_ENTRY_ONLINE)
|
|
||||||
{
|
|
||||||
*addr = mPeerId.addr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (time(NULL) - mLastSeen < BD_FRIEND_ENTRY_TIMEOUT)
|
|
||||||
{
|
|
||||||
*addr = mPeerId.addr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t bdFriendEntry::getPeerFlags()
|
|
||||||
{
|
|
||||||
return mFlags & BD_FRIEND_ENTRY_MASK_KNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bdFriendList::bdFriendList(const bdNodeId *ownId)
|
|
||||||
{
|
|
||||||
bdId tmpId;
|
|
||||||
tmpId.id = *ownId;
|
|
||||||
updatePeer(&tmpId, BD_FRIEND_ENTRY_SELF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******
|
|
||||||
* Simple logic: timestamp is set with address.
|
|
||||||
* if ONLINE, then address will be dropped as soon as OFFLINE.
|
|
||||||
* if ADDR_OK, then address will be dropped after XX seconds.
|
|
||||||
*
|
|
||||||
* ONLINE - will be used with friends.
|
|
||||||
* ADDR_OK - will potentially be used for friends of friends (but not for now).
|
|
||||||
*****/
|
|
||||||
|
|
||||||
/* catch-all interface function */
|
|
||||||
bool bdFriendList::updatePeer(const bdId *id, uint32_t flags)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FRIENDLIST
|
|
||||||
std::cerr << "bdFriendList::updatePeer() Peer(";
|
|
||||||
bdStdPrintId(std::cerr, id);
|
|
||||||
std::cerr << ") Flags: " << flags;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::map<bdNodeId, bdFriendEntry>::iterator it;
|
|
||||||
it = mPeers.find(id->id);
|
|
||||||
if (it == mPeers.end())
|
|
||||||
{
|
|
||||||
bdFriendEntry entry;
|
|
||||||
entry.mPeerId.id = id->id;
|
|
||||||
entry.mFlags = 0;
|
|
||||||
entry.mLastSeen = 0;
|
|
||||||
|
|
||||||
mPeers[id->id] = entry;
|
|
||||||
it = mPeers.find(id->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update all */
|
|
||||||
it->second.mFlags = flags;
|
|
||||||
if (it->second.mFlags & (BD_FRIEND_ENTRY_ADDR_OK | BD_FRIEND_ENTRY_ONLINE))
|
|
||||||
{
|
|
||||||
it->second.mFlags |= BD_FRIEND_ENTRY_ADDR_OK;
|
|
||||||
|
|
||||||
it->second.mPeerId.addr = id->addr;
|
|
||||||
it->second.mLastSeen = time(NULL);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdFriendList::removePeer(const bdNodeId *id)
|
|
||||||
{
|
|
||||||
/* see if it exists... */
|
|
||||||
std::map<bdNodeId, bdFriendEntry>::iterator it;
|
|
||||||
it = mPeers.find(*id);
|
|
||||||
if (it == mPeers.end())
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FRIENDLIST
|
|
||||||
std::cerr << "bdFriendList::removeFriend() Peer(";
|
|
||||||
bdStdPrintNodeId(std::cerr, id);
|
|
||||||
std::cerr << ") is unknown!";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPeers.erase(*id);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdFriendList::findPeerEntry(const bdNodeId *id, bdFriendEntry &entry)
|
|
||||||
{
|
|
||||||
/* see if it exists... */
|
|
||||||
std::map<bdNodeId, bdFriendEntry>::iterator it;
|
|
||||||
it = mPeers.find(*id);
|
|
||||||
if (it == mPeers.end())
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FRIENDLIST
|
|
||||||
std::cerr << "bdFriendList::getPeerEntry() Peer(";
|
|
||||||
bdStdPrintNodeId(std::cerr, id);
|
|
||||||
std::cerr << ") is unknown!";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = it->second;
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdFriendList::findPeersWithFlags(uint32_t flags, std::list<bdNodeId> &peerList)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FRIENDLIST
|
|
||||||
std::cerr << "bdFriendList::findPeersWithFlags(" << flags << ")";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* see if it exists... */
|
|
||||||
std::map<bdNodeId, bdFriendEntry>::iterator it;
|
|
||||||
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
|
||||||
{
|
|
||||||
/* if they have ALL of the flags we specified */
|
|
||||||
if ((it->second.getPeerFlags() & flags) == flags)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_FRIENDLIST
|
|
||||||
std::cerr << "bdFriendList::findPeersWithFlags() Found: ";
|
|
||||||
bdStdPrintNodeId(std::cerr, id);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
peerList.push_back(it->second.mPeerId.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (peerList.size() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool bdFriendList::print(std::ostream &out)
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
out << "bdFriendList::print()";
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
std::map<bdNodeId, bdFriendEntry>::iterator it;
|
|
||||||
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
|
||||||
{
|
|
||||||
bdStdPrintId(out, &(it->second.mPeerId));
|
|
||||||
out << " Flags: " << it->second.mFlags;
|
|
||||||
out << " Seen: " << now - it->second.mLastSeen;
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bdPeerQueue::bdPeerQueue()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdPeerQueue::queuePeer(const bdId *id, uint32_t flags)
|
|
||||||
{
|
|
||||||
bdFriendEntry entry;
|
|
||||||
entry.mPeerId = *id;
|
|
||||||
entry.mFlags = flags;
|
|
||||||
entry.mLastSeen = time(NULL);
|
|
||||||
|
|
||||||
mPeerQueue.push_back(entry);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdPeerQueue::popPeer(bdId *id, uint32_t &flags)
|
|
||||||
{
|
|
||||||
if (mPeerQueue.size() > 0)
|
|
||||||
{
|
|
||||||
bdFriendEntry entry = mPeerQueue.front();
|
|
||||||
mPeerQueue.pop_front();
|
|
||||||
*id = entry.mPeerId;
|
|
||||||
flags = entry.mFlags;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdfriendlist.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BITDHT_FRIEND_LIST_H
|
|
||||||
#define BITDHT_FRIEND_LIST_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class maintains a list of current friends and friends-of-friends.
|
|
||||||
* It should also be updated when a peer's address has been identified.
|
|
||||||
*
|
|
||||||
* It is used for selecting preferential peers for DHT Connections.
|
|
||||||
* and for detecting bad peers that are duplicating real RS peers.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#define BD_FRIEND_ENTRY_TIMEOUT 10
|
|
||||||
|
|
||||||
|
|
||||||
//#define BD_FRIEND_ENTRY_ONLINE 0x0001
|
|
||||||
//#define BD_FRIEND_ENTRY_ADDR_OK 0x0002
|
|
||||||
|
|
||||||
//#define BD_FRIEND_ENTRY_WHITELIST BITDHT_PEER_STATUS_DHT_WHITELIST
|
|
||||||
//#define BD_FRIEND_ENTRY_FOF BITDHT_PEER_STATUS_DHT_FOF
|
|
||||||
//#define BD_FRIEND_ENTRY_FRIEND BITDHT_PEER_STATUS_DHT_FRIEND
|
|
||||||
//#define BD_FRIEND_ENTRY_RELAY_SERVER BITDHT_PEER_STATUS_DHT_RELAY_SERVER
|
|
||||||
|
|
||||||
//#define BD_FRIEND_ENTRY_SELF BITDHT_PEER_STATUS_DHT_SELF
|
|
||||||
|
|
||||||
//#define BD_FRIEND_ENTRY_MASK_KNOWN BITDHT_PEER_STATUS_MASK_KNOWN
|
|
||||||
|
|
||||||
class bdFriendEntry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdFriendEntry();
|
|
||||||
|
|
||||||
bool addrKnown(struct sockaddr_in *addr);
|
|
||||||
uint32_t getPeerFlags();
|
|
||||||
|
|
||||||
bdId mPeerId;
|
|
||||||
uint32_t mFlags;
|
|
||||||
time_t mLastSeen;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdFriendList
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
bdFriendList(const bdNodeId *ownid);
|
|
||||||
|
|
||||||
bool updatePeer(const bdId *id, uint32_t flags);
|
|
||||||
bool removePeer(const bdNodeId *id);
|
|
||||||
|
|
||||||
bool findPeerEntry(const bdNodeId *id, bdFriendEntry &entry);
|
|
||||||
bool findPeersWithFlags(uint32_t flags, std::list<bdNodeId> &peerList);
|
|
||||||
|
|
||||||
bool print(std::ostream &out);
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::map<bdNodeId, bdFriendEntry> mPeers;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdPeerQueue
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
bdPeerQueue();
|
|
||||||
|
|
||||||
bool queuePeer(const bdId *id, uint32_t flags);
|
|
||||||
bool popPeer(bdId *id, uint32_t &flags);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::list<bdFriendEntry> mPeerQueue;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,283 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdhash.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdhash.h"
|
|
||||||
#include "bitdht/bdstddht.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
bdHashEntry::bdHashEntry(std::string value, std::string secret, time_t lifetime, time_t store)
|
|
||||||
:mValue(value), mStoreTS(store), mSecret(secret), mLifetime(lifetime)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************** class bdHashSet ********************************/
|
|
||||||
|
|
||||||
bdHashSet::bdHashSet(bdNodeId *id)
|
|
||||||
:mId(*id)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdHashSet::search(std::string key, uint32_t maxAge, std::list<bdHashEntry> &entries)
|
|
||||||
{
|
|
||||||
std::multimap<std::string, bdHashEntry>::iterator sit, eit, it;
|
|
||||||
sit = mEntries.lower_bound(key);
|
|
||||||
eit = mEntries.upper_bound(key);
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
for(it = sit; it != eit; it++)
|
|
||||||
{
|
|
||||||
time_t age = now - it->second.mStoreTS;
|
|
||||||
if (age < (int32_t) maxAge)
|
|
||||||
{
|
|
||||||
entries.push_back(it->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (0 < entries.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* With modification.
|
|
||||||
* If there is no secret -> it cannot be deleted (must timeout), but can be extended.
|
|
||||||
* If there is a secret -> must include it to modify.
|
|
||||||
*
|
|
||||||
* Therefore if identical entry without secret comes along - what do I do?
|
|
||||||
* -> create duplicate?
|
|
||||||
*/
|
|
||||||
|
|
||||||
int bdHashSet::modify(std::string key, bdHashEntry *entry, uint32_t modFlags)
|
|
||||||
{
|
|
||||||
std::multimap<std::string, bdHashEntry>::iterator sit, eit, it;
|
|
||||||
sit = mEntries.lower_bound(key);
|
|
||||||
eit = mEntries.upper_bound(key);
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
bool updated = false;
|
|
||||||
for(it = sit; it != eit; it++)
|
|
||||||
{
|
|
||||||
/* check it all */
|
|
||||||
if (it->second.mValue == entry->mValue)
|
|
||||||
{
|
|
||||||
bool noSecret = (it->second.mSecret == "");
|
|
||||||
bool sameSecret = (it->second.mSecret == entry->mSecret);
|
|
||||||
bool update = false;
|
|
||||||
|
|
||||||
if (noSecret && sameSecret)
|
|
||||||
{
|
|
||||||
/* only allowed to increase lifetime */
|
|
||||||
if (modFlags == BITDHT_HASH_ENTRY_ADD)
|
|
||||||
{
|
|
||||||
time_t existKillTime = it->second.mLifetime + it->second.mStoreTS;
|
|
||||||
time_t newKillTime = entry->mLifetime + now;
|
|
||||||
if (newKillTime > existKillTime)
|
|
||||||
{
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (sameSecret)
|
|
||||||
{
|
|
||||||
if (modFlags == BITDHT_HASH_ENTRY_ADD)
|
|
||||||
{
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
else if (modFlags == BITDHT_HASH_ENTRY_DELETE)
|
|
||||||
{
|
|
||||||
/* do it here */
|
|
||||||
mEntries.erase(it);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update)
|
|
||||||
{
|
|
||||||
it->second.mStoreTS = now;
|
|
||||||
it->second.mLifetime = entry->mLifetime;
|
|
||||||
updated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!updated) && (modFlags == BITDHT_HASH_ENTRY_ADD))
|
|
||||||
{
|
|
||||||
/* create a new entry */
|
|
||||||
bdHashEntry newEntry(entry->mValue, entry->mSecret, entry->mLifetime, now);
|
|
||||||
mEntries.insert(std::pair<std::string, bdHashEntry>(key, newEntry));
|
|
||||||
updated = true;
|
|
||||||
}
|
|
||||||
return updated;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdHashSet::printHashSet(std::ostream &out)
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
std::multimap<std::string, bdHashEntry>::iterator it;
|
|
||||||
out << "Hash: ";
|
|
||||||
bdStdPrintNodeId(out, &mId); // Allowing "Std" as we dont need dht functions everywhere.
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
for(it = mEntries.begin(); it != mEntries.end();it++)
|
|
||||||
{
|
|
||||||
time_t age = now - it->second.mStoreTS;
|
|
||||||
out << "\tK:" << bdStdConvertToPrintable(it->first);
|
|
||||||
out << " V:" << bdStdConvertToPrintable(it->second.mValue);
|
|
||||||
out << " A:" << age << " L:" << it->second.mLifetime;
|
|
||||||
out << " S:" << bdStdConvertToPrintable(it->second.mSecret);
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int bdHashSet::cleanupHashSet(uint32_t maxAge)
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
/* this is nasty... but don't know how to effectively remove from multimaps
|
|
||||||
* * Must do full repeat for each removal.
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::multimap<std::string, bdHashEntry>::iterator it;
|
|
||||||
for(it = mEntries.begin(); it != mEntries.end();)
|
|
||||||
{
|
|
||||||
time_t age = now - it->second.mStoreTS;
|
|
||||||
if ((age > (int32_t) maxAge) || (age > it->second.mLifetime))
|
|
||||||
{
|
|
||||||
mEntries.erase(it);
|
|
||||||
it = mEntries.begin();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************* class bdHashSpace ***************************/
|
|
||||||
|
|
||||||
bdHashSpace::bdHashSpace()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* accessors */
|
|
||||||
int bdHashSpace::search(bdNodeId *id, std::string key, uint32_t maxAge, std::list<bdHashEntry> &entries)
|
|
||||||
{
|
|
||||||
std::map<bdNodeId, bdHashSet>::iterator it;
|
|
||||||
it = mHashTable.find(*id);
|
|
||||||
if (it == mHashTable.end())
|
|
||||||
{
|
|
||||||
/* no entry */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return it->second.search(key, maxAge, entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdHashSpace::modify(bdNodeId *id, std::string key, bdHashEntry *entry, uint32_t modFlags)
|
|
||||||
{
|
|
||||||
std::map<bdNodeId, bdHashSet>::iterator it;
|
|
||||||
it = mHashTable.find(*id);
|
|
||||||
if (it == mHashTable.end())
|
|
||||||
{
|
|
||||||
if (modFlags == BITDHT_HASH_ENTRY_DELETE)
|
|
||||||
{
|
|
||||||
/* done already */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//mHashTable[*id] = bdHashSet(id);
|
|
||||||
mHashTable.insert(std::pair<bdNodeId, bdHashSet>(*id, bdHashSet(id)));
|
|
||||||
it = mHashTable.find(*id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return it->second.modify(key, entry, modFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdHashSpace::printHashSpace(std::ostream &out)
|
|
||||||
{
|
|
||||||
std::map<bdNodeId, bdHashSet>::iterator it;
|
|
||||||
out << "bdHashSpace::printHashSpace()" << std::endl;
|
|
||||||
out << "--------------------------------------------" << std::endl;
|
|
||||||
|
|
||||||
for(it = mHashTable.begin(); it != mHashTable.end(); it++)
|
|
||||||
{
|
|
||||||
it->second.printHashSet(out);
|
|
||||||
}
|
|
||||||
out << "--------------------------------------------" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdHashSpace::cleanHashSpace(bdNodeId *min, bdNodeId *max, time_t maxAge)
|
|
||||||
{
|
|
||||||
std::map<bdNodeId, bdHashSet>::iterator it;
|
|
||||||
std::list<bdNodeId> eraseList;
|
|
||||||
std::list<bdNodeId>::iterator eit;
|
|
||||||
|
|
||||||
for(it = mHashTable.begin(); it != mHashTable.end(); it++)
|
|
||||||
{
|
|
||||||
if ((it->first < *min) ||
|
|
||||||
(*max < it->first))
|
|
||||||
{
|
|
||||||
/* schedule for erasure */
|
|
||||||
eraseList.push_back(it->first);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* clean up Hash Set */
|
|
||||||
it->second.cleanupHashSet(maxAge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
while(eraseList.size() > 0)
|
|
||||||
{
|
|
||||||
bdNodeId &eId = eraseList.front();
|
|
||||||
it = mHashTable.find(eId);
|
|
||||||
if (it != mHashTable.end())
|
|
||||||
{
|
|
||||||
mHashTable.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int bdHashSpace::clear()
|
|
||||||
{
|
|
||||||
mHashTable.clear();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdhash.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BITDHT_HASH_SPACE_H
|
|
||||||
#define BITDHT_HASH_SPACE_H
|
|
||||||
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#define BITDHT_HASH_ENTRY_ADD 1
|
|
||||||
#define BITDHT_HASH_ENTRY_DELETE 2
|
|
||||||
|
|
||||||
class bdHashEntry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdHashEntry(std::string value, std::string secret, time_t lifetime, time_t store);
|
|
||||||
std::string mValue;
|
|
||||||
time_t mStoreTS;
|
|
||||||
|
|
||||||
/* These are nice features that OpenDHT had */
|
|
||||||
std::string mSecret;
|
|
||||||
time_t mLifetime;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdHashSet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdHashSet(bdNodeId *id);
|
|
||||||
|
|
||||||
int search(std::string key, uint32_t maxAge, std::list<bdHashEntry> &entries);
|
|
||||||
int modify(std::string key, bdHashEntry *entry, uint32_t modFlags);
|
|
||||||
int printHashSet(std::ostream &out);
|
|
||||||
int cleanupHashSet(uint32_t maxAge);
|
|
||||||
|
|
||||||
bdNodeId mId;
|
|
||||||
std::multimap<std::string, bdHashEntry> mEntries;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdHashSpace
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdHashSpace();
|
|
||||||
|
|
||||||
/* accessors */
|
|
||||||
int search(bdNodeId *id, std::string key, uint32_t maxAge, std::list<bdHashEntry> &entries);
|
|
||||||
int modify(bdNodeId *id, std::string key, bdHashEntry *entry, uint32_t modFlags);
|
|
||||||
|
|
||||||
int printHashSpace(std::ostream&);
|
|
||||||
int cleanHashSpace(bdNodeId *min, bdNodeId *max, time_t maxAge);
|
|
||||||
int clear();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::map<bdNodeId, bdHashSet> mHashTable;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,647 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdhistory.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#include "bitdht/bdhistory.h"
|
|
||||||
#include "bitdht/bdstddht.h"
|
|
||||||
#include "bitdht/bdmsgs.h"
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#define MIN_RESEND_PERIOD 60
|
|
||||||
|
|
||||||
bdMsgHistoryList::bdMsgHistoryList()
|
|
||||||
:mPeerVersion("Unknown")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void bdMsgHistoryList::addMsg(time_t ts, uint32_t msgType, bool incoming, const bdNodeId *aboutId)
|
|
||||||
{
|
|
||||||
// std::cerr << "bdMsgHistoryList::addMsg()";
|
|
||||||
// std::cerr << std::endl;
|
|
||||||
|
|
||||||
bdMsgHistoryItem msg(msgType, incoming, aboutId);
|
|
||||||
msgHistory.insert(std::make_pair(ts, msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdMsgHistoryList::setPeerType(time_t /* ts */, std::string version)
|
|
||||||
{
|
|
||||||
mPeerVersion = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdMsgHistoryList::msgCount(time_t start_ts, time_t end_ts)
|
|
||||||
{
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
|
||||||
sit = msgHistory.lower_bound(start_ts);
|
|
||||||
eit = msgHistory.upper_bound(end_ts);
|
|
||||||
int count = 0;
|
|
||||||
for (it = sit; it != eit; it++, count++) ; // empty loop.
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdMsgHistoryList::msgClear(time_t before)
|
|
||||||
{
|
|
||||||
if (before == 0)
|
|
||||||
{
|
|
||||||
msgHistory.clear();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the old stuff in the list.
|
|
||||||
while((msgHistory.begin() != msgHistory.end()) && (msgHistory.begin()->first < before))
|
|
||||||
{
|
|
||||||
msgHistory.erase(msgHistory.begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
// return true if empty.
|
|
||||||
if (msgHistory.begin() == msgHistory.end())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdMsgHistoryList::msgClear()
|
|
||||||
{
|
|
||||||
msgHistory.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdMsgHistoryList::clearHistory()
|
|
||||||
{
|
|
||||||
msgClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdMsgHistoryList::printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts)
|
|
||||||
{
|
|
||||||
//out << "AGE: MSGS => incoming, <= outgoing" << std::endl;
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
|
||||||
sit = msgHistory.lower_bound(start_ts);
|
|
||||||
eit = msgHistory.upper_bound(end_ts);
|
|
||||||
time_t curr_ts = 0;
|
|
||||||
bool time_changed = false;
|
|
||||||
bool first_line = true;
|
|
||||||
|
|
||||||
for(it = sit; it != eit; it++)
|
|
||||||
{
|
|
||||||
time_changed = false;
|
|
||||||
if (curr_ts != it->first)
|
|
||||||
{
|
|
||||||
curr_ts = it->first;
|
|
||||||
time_changed = true;
|
|
||||||
}
|
|
||||||
switch(mode)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
/* print one line per ts */
|
|
||||||
if (time_changed)
|
|
||||||
{
|
|
||||||
if (!first_line)
|
|
||||||
{
|
|
||||||
/* finish existing line */
|
|
||||||
out << " " << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
first_line = false;
|
|
||||||
}
|
|
||||||
out << "\tTS: " << time(NULL) - curr_ts << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
bitdht_msgtype(it->second.msgType, name);
|
|
||||||
|
|
||||||
if (it->second.incoming)
|
|
||||||
{
|
|
||||||
out << "( =I> ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out << "( <O= ";
|
|
||||||
}
|
|
||||||
|
|
||||||
out << name << " ";
|
|
||||||
if ((it->second.aboutId.data[0] == 0)
|
|
||||||
&& (it->second.aboutId.data[3] == 0)
|
|
||||||
&& (it->second.aboutId.data[3] == 0)
|
|
||||||
&& (it->second.aboutId.data[3] == 0))
|
|
||||||
{
|
|
||||||
/* don't print anything */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bdStdPrintNodeId(out, &(it->second.aboutId));
|
|
||||||
}
|
|
||||||
out << " )";
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} // end of switch.
|
|
||||||
}
|
|
||||||
|
|
||||||
/* finish up last line */
|
|
||||||
if (!first_line)
|
|
||||||
{
|
|
||||||
out << " " << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdMsgHistoryList::canSend()
|
|
||||||
{
|
|
||||||
std::cerr << "bdMsgHistoryList::canSend()";
|
|
||||||
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::reverse_iterator rit;
|
|
||||||
|
|
||||||
rit = msgHistory.rbegin();
|
|
||||||
if (rit != msgHistory.rend())
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
if (now - rit->first > MIN_RESEND_PERIOD)
|
|
||||||
{
|
|
||||||
std::cerr << " OVER RESEND_PERIOD... true";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgHistory.size() % 2 == 0)
|
|
||||||
{
|
|
||||||
std::cerr << " SIZE: " << msgHistory.size() << " % 2 = 0 ... true";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << " false";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdMsgHistoryList::validPeer()
|
|
||||||
{
|
|
||||||
std::cerr << "bdMsgHistoryList::validPeer()";
|
|
||||||
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::iterator it;
|
|
||||||
|
|
||||||
for(it = msgHistory.begin(); it != msgHistory.end(); it++)
|
|
||||||
{
|
|
||||||
if (it->second.incoming)
|
|
||||||
{
|
|
||||||
std::cerr << " Incoming Msg... so validPeer";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << " false";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_PING_PER_MINUTE 2
|
|
||||||
#define MAX_QUERY_PER_MINUTE 2
|
|
||||||
|
|
||||||
bool bdMsgHistoryList::analysePeer()
|
|
||||||
|
|
||||||
{
|
|
||||||
/* analyse and print out details of the peers messages */
|
|
||||||
bool flagged = false;
|
|
||||||
|
|
||||||
//out << "AGE: MSGS => incoming, <= outgoing" << std::endl;
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
|
||||||
sit = msgHistory.begin();
|
|
||||||
eit = msgHistory.end();
|
|
||||||
if (sit == eit)
|
|
||||||
{
|
|
||||||
// nothing here.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t start_ts = sit->first;
|
|
||||||
time_t end_ts = msgHistory.rbegin()->first; // must exist.
|
|
||||||
|
|
||||||
|
|
||||||
// don't divide by zero.
|
|
||||||
if (end_ts - start_ts < 60)
|
|
||||||
{
|
|
||||||
end_ts = start_ts + 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* what do we want to analyse? */
|
|
||||||
|
|
||||||
/* if we have sent / recved too many queries or pings */
|
|
||||||
|
|
||||||
int in_ping = 0;
|
|
||||||
int out_ping = 0;
|
|
||||||
int in_query = 0;
|
|
||||||
int out_query = 0;
|
|
||||||
int in_other = 0;
|
|
||||||
int out_other = 0;
|
|
||||||
|
|
||||||
for(it = sit; it != eit; it++)
|
|
||||||
{
|
|
||||||
if (it->second.incoming)
|
|
||||||
{
|
|
||||||
switch(it->second.msgType)
|
|
||||||
{
|
|
||||||
case BITDHT_MSG_TYPE_PING:
|
|
||||||
in_ping++;
|
|
||||||
break;
|
|
||||||
case BITDHT_MSG_TYPE_FIND_NODE:
|
|
||||||
in_query++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
in_other++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch(it->second.msgType)
|
|
||||||
{
|
|
||||||
case BITDHT_MSG_TYPE_PING:
|
|
||||||
out_ping++;
|
|
||||||
break;
|
|
||||||
case BITDHT_MSG_TYPE_FIND_NODE:
|
|
||||||
out_query++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
out_other++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
float in_ping_per_min = in_ping * 60.0 / (end_ts - start_ts);
|
|
||||||
float out_ping_per_min = out_ping * 60.0 / (end_ts - start_ts);
|
|
||||||
float in_query_per_min = in_query * 60.0 / (end_ts - start_ts);
|
|
||||||
float out_query_per_min = out_query * 60.0 / (end_ts - start_ts);
|
|
||||||
|
|
||||||
if ((in_ping_per_min > MAX_PING_PER_MINUTE) ||
|
|
||||||
(out_ping_per_min > MAX_PING_PER_MINUTE) ||
|
|
||||||
(in_query_per_min > MAX_PING_PER_MINUTE) ||
|
|
||||||
(out_query_per_min > MAX_PING_PER_MINUTE))
|
|
||||||
{
|
|
||||||
flagged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flagged)
|
|
||||||
{
|
|
||||||
/* print header */
|
|
||||||
std::ostream &out = std::cerr;
|
|
||||||
out << "BdHistoryAnalysis has flagged peer: ";
|
|
||||||
bdStdPrintId(out, &mId);
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
out << "PeerType: " << mPeerVersion;
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
out << "Ping In Per Min : " << in_ping_per_min << std::endl;
|
|
||||||
out << "Ping Out Per Min : " << out_ping_per_min << std::endl;
|
|
||||||
out << "Query In Per Min : " << in_query_per_min << std::endl;
|
|
||||||
out << "Query Out Per Min: " << out_query_per_min << std::endl;
|
|
||||||
|
|
||||||
out << "Message History: ";
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
printHistory(out, 0, 0, time(NULL));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdHistory::bdHistory(time_t store_period)
|
|
||||||
:mStorePeriod(store_period) { return; }
|
|
||||||
|
|
||||||
void bdHistory::addMsg(const bdId *id, bdToken * /*transId*/, uint32_t msgType, bool incoming, const bdNodeId *aboutId)
|
|
||||||
{
|
|
||||||
//std::cerr << "bdHistory::addMsg() ";
|
|
||||||
//bdStdPrintId(std::cerr, id);
|
|
||||||
//std::cerr << std::endl;
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
std::map<bdId, bdMsgHistoryList>::iterator it;
|
|
||||||
bdMsgHistoryList &histRef = mHistory[*id]; /* will instaniate empty */
|
|
||||||
histRef.mId = *id;
|
|
||||||
histRef.addMsg(now, msgType, incoming, aboutId);
|
|
||||||
|
|
||||||
/* add to mMsgTimeline */
|
|
||||||
mMsgTimeline.insert(std::make_pair(now, MsgRegister(id, msgType, incoming, aboutId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdHistory::setPeerType(const bdId *id, std::string version)
|
|
||||||
{
|
|
||||||
std::map<bdId, bdMsgHistoryList>::iterator it;
|
|
||||||
bdMsgHistoryList &histRef = mHistory[*id]; /* will instaniate empty */
|
|
||||||
histRef.setPeerType(time(NULL), version);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdHistory::printMsgs()
|
|
||||||
{
|
|
||||||
/* print and clear msgs */
|
|
||||||
std::ostream &out = std::cerr;
|
|
||||||
|
|
||||||
std::cerr << "bdHistory::printMsgs()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
|
||||||
{
|
|
||||||
if (it->second.msgCount(0, time(NULL))) // all msg count.
|
|
||||||
{
|
|
||||||
/* print header */
|
|
||||||
out << "Msgs for ";
|
|
||||||
bdStdPrintId(out, &(it->first));
|
|
||||||
out << " v:" << it->second.mPeerVersion;
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
it->second.printHistory(out, 0, 0, time(NULL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out << "Msg Timeline:";
|
|
||||||
time_t now = time(NULL);
|
|
||||||
std::multimap<time_t, MsgRegister>::iterator hit;
|
|
||||||
for(hit = mMsgTimeline.begin(); hit != mMsgTimeline.end(); hit++)
|
|
||||||
{
|
|
||||||
out << now - hit->first << " ";
|
|
||||||
bdStdPrintId(out, &(hit->second.id));
|
|
||||||
|
|
||||||
if (hit->second.incoming)
|
|
||||||
{
|
|
||||||
out << " =I> ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out << " <O= ";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
if (bitdht_msgtype(hit->second.msgType, name))
|
|
||||||
{
|
|
||||||
out << name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out << "UNKNOWN MSG";
|
|
||||||
}
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdHistory::cleanupOldMsgs()
|
|
||||||
{
|
|
||||||
std::cerr << "bdHistory::cleanupOldMsgs()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
if (mStorePeriod == 0)
|
|
||||||
{
|
|
||||||
return; // no cleanup
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<bdId> to_cleanup;
|
|
||||||
std::set<bdId>::iterator cit;
|
|
||||||
|
|
||||||
time_t before = time(NULL) - mStorePeriod;
|
|
||||||
|
|
||||||
// Delete the old stuff in the list.
|
|
||||||
while((mMsgTimeline.begin() != mMsgTimeline.end()) && (mMsgTimeline.begin()->first < before))
|
|
||||||
{
|
|
||||||
std::multimap<time_t, MsgRegister>::iterator it = mMsgTimeline.begin();
|
|
||||||
to_cleanup.insert(it->second.id);
|
|
||||||
mMsgTimeline.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove old msgs, delete entry if its empty.
|
|
||||||
std::map<bdId, bdMsgHistoryList>::iterator hit;
|
|
||||||
for(cit = to_cleanup.begin(); cit != to_cleanup.end(); cit++)
|
|
||||||
{
|
|
||||||
hit = mHistory.find(*cit);
|
|
||||||
if (hit != mHistory.end())
|
|
||||||
{
|
|
||||||
if (hit->second.msgClear(before))
|
|
||||||
{
|
|
||||||
// don't erase actual entry (so we remember peer type).
|
|
||||||
//mHistory.erase(hit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void bdHistory::clearHistory()
|
|
||||||
{
|
|
||||||
// Switched to a alternative clear, so we don't drop peers, and remember their type.
|
|
||||||
//mHistory.clear();
|
|
||||||
|
|
||||||
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
|
||||||
{
|
|
||||||
it->second.clearHistory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdHistory::canSend(const bdId *id)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
it = mHistory.find(*id);
|
|
||||||
if (it != mHistory.end())
|
|
||||||
{
|
|
||||||
return (it->second.canSend());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if not found - then can send */
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdHistory::validPeer(const bdId *id)
|
|
||||||
{
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
it = mHistory.find(*id);
|
|
||||||
if (it != mHistory.end())
|
|
||||||
{
|
|
||||||
return (it->second.validPeer());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if not found - then can send */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdHistory::analysePeers()
|
|
||||||
{
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
|
||||||
{
|
|
||||||
it->second.analysePeer();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Temp data class. */
|
|
||||||
class TypeStats
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
TypeStats() :nodes(0) { return; }
|
|
||||||
|
|
||||||
std::map<uint32_t, uint32_t> incoming, outgoing;
|
|
||||||
int nodes;
|
|
||||||
|
|
||||||
|
|
||||||
void printStats(std::ostream &out, const TypeStats *refStats)
|
|
||||||
{
|
|
||||||
std::map<uint32_t, uint32_t>::iterator it;
|
|
||||||
std::map<uint32_t, uint32_t>::const_iterator rit;
|
|
||||||
|
|
||||||
out << " Nodes: " << nodes;
|
|
||||||
if (refStats)
|
|
||||||
{
|
|
||||||
out << " (" << 100.0 * nodes / (float) refStats->nodes << " %)";
|
|
||||||
}
|
|
||||||
out << std::endl;
|
|
||||||
|
|
||||||
out << " Incoming Msgs";
|
|
||||||
out << std::endl;
|
|
||||||
for(it = incoming.begin(); it != incoming.end(); it++)
|
|
||||||
{
|
|
||||||
uint32_t count = 0;
|
|
||||||
if (refStats)
|
|
||||||
{
|
|
||||||
rit = refStats->incoming.find(it->first);
|
|
||||||
if (rit != refStats->incoming.end())
|
|
||||||
{
|
|
||||||
count = rit->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printStatsLine(out, it->first, it->second, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
out << " Outgoing Msgs";
|
|
||||||
out << std::endl;
|
|
||||||
for(it = outgoing.begin(); it != outgoing.end(); it++)
|
|
||||||
{
|
|
||||||
uint32_t count = 0;
|
|
||||||
if (refStats)
|
|
||||||
{
|
|
||||||
rit = refStats->outgoing.find(it->first);
|
|
||||||
if (rit != refStats->outgoing.end())
|
|
||||||
{
|
|
||||||
count = rit->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printStatsLine(out, it->first, it->second, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void printStatsLine(std::ostream &out, uint32_t msgType, uint32_t count, uint32_t global)
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
bitdht_msgtype(msgType, name);
|
|
||||||
out << "\t" << name << " " << count;
|
|
||||||
if (global != 0)
|
|
||||||
{
|
|
||||||
out << " (" << 100.0 * count / (float) global << " %)";
|
|
||||||
}
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}; /* end of TypeStats */
|
|
||||||
|
|
||||||
bool bdHistory::peerTypeAnalysis()
|
|
||||||
{
|
|
||||||
|
|
||||||
std::map<std::string, TypeStats> mTypeStats;
|
|
||||||
TypeStats globalStats;
|
|
||||||
|
|
||||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
|
||||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
|
||||||
{
|
|
||||||
if (it->second.msgHistory.empty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string version = it->second.mPeerVersion;
|
|
||||||
// group be first two bytes.
|
|
||||||
version = it->second.mPeerVersion.substr(0,2);
|
|
||||||
TypeStats &stats = mTypeStats[version];
|
|
||||||
|
|
||||||
stats.nodes++;
|
|
||||||
globalStats.nodes++;
|
|
||||||
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem>::iterator lit;
|
|
||||||
for (lit = it->second.msgHistory.begin(); lit != it->second.msgHistory.end(); lit++)
|
|
||||||
{
|
|
||||||
if (lit->second.incoming)
|
|
||||||
{
|
|
||||||
stats.incoming[lit->second.msgType]++;
|
|
||||||
globalStats.incoming[lit->second.msgType]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stats.outgoing[lit->second.msgType]++;
|
|
||||||
globalStats.outgoing[lit->second.msgType]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, TypeStats>::iterator tit;
|
|
||||||
for(tit = mTypeStats.begin(); tit != mTypeStats.end(); tit++)
|
|
||||||
{
|
|
||||||
std::cerr << "Stats for Peer Type: " << tit->first;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
tit->second.printStats(std::cerr, &globalStats);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "Global Stats: ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
globalStats.printStats(std::cerr, NULL);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdhistory.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BITDHT_HISTORY_H
|
|
||||||
#define BITDHT_HISTORY_H
|
|
||||||
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
#include "bitdht/bdobj.h"
|
|
||||||
#include "bitdht/bdstddht.h"
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#define MSG_TYPE_DIRECTION_MASK 0x000f0000
|
|
||||||
|
|
||||||
#define MSG_DIRECTION_INCOMING 0x00010000
|
|
||||||
#define MSG_DIRECTION_OUTGOING 0x00020000
|
|
||||||
|
|
||||||
/**** DEBUGGING HISTORY ****/
|
|
||||||
|
|
||||||
class MsgRegister
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MsgRegister() { return; }
|
|
||||||
MsgRegister(const bdId *inId, uint32_t inMsgType, bool inIncoming, const bdNodeId *inAboutId)
|
|
||||||
:id(*inId), msgType(inMsgType), incoming(inIncoming)
|
|
||||||
{
|
|
||||||
if (inAboutId)
|
|
||||||
{
|
|
||||||
aboutId = *inAboutId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bdStdZeroNodeId(&aboutId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdId id;
|
|
||||||
uint32_t msgType;
|
|
||||||
bool incoming;
|
|
||||||
bdNodeId aboutId; // filled in for queries.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdMsgHistoryItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdMsgHistoryItem()
|
|
||||||
:msgType(0), incoming(false)
|
|
||||||
{
|
|
||||||
bdStdZeroNodeId(&aboutId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdMsgHistoryItem(uint32_t inMsgType, bool inIncoming, const bdNodeId *inAboutId)
|
|
||||||
:msgType(inMsgType), incoming(inIncoming)
|
|
||||||
{
|
|
||||||
if (inAboutId)
|
|
||||||
{
|
|
||||||
aboutId = *inAboutId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bdStdZeroNodeId(&aboutId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t msgType;
|
|
||||||
bool incoming;
|
|
||||||
bdNodeId aboutId; // filled in for queries.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdMsgHistoryList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdMsgHistoryList();
|
|
||||||
void addMsg(time_t ts, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
|
||||||
void setPeerType(time_t ts, std::string version);
|
|
||||||
int msgCount(time_t start_ts, time_t end_ts);
|
|
||||||
bool msgClear(time_t before); // 0 => clear all.
|
|
||||||
void msgClear();
|
|
||||||
void printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts);
|
|
||||||
bool analysePeer();
|
|
||||||
void clearHistory();
|
|
||||||
|
|
||||||
bool canSend();
|
|
||||||
bool validPeer();
|
|
||||||
|
|
||||||
std::multimap<time_t, bdMsgHistoryItem> msgHistory;
|
|
||||||
std::string mPeerVersion;
|
|
||||||
bdId mId;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class bdHistory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdHistory(time_t store_period);
|
|
||||||
|
|
||||||
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
|
||||||
void setPeerType(const bdId *id, std::string version);
|
|
||||||
void printMsgs();
|
|
||||||
|
|
||||||
void cleanupOldMsgs();
|
|
||||||
void clearHistory();
|
|
||||||
bool analysePeers();
|
|
||||||
bool peerTypeAnalysis();
|
|
||||||
|
|
||||||
bool canSend(const bdId *id);
|
|
||||||
bool validPeer(const bdId *id);
|
|
||||||
|
|
||||||
/* recent history */
|
|
||||||
//std::list<bdId> lastMsgs;
|
|
||||||
std::map<bdId, bdMsgHistoryList> mHistory;
|
|
||||||
std::multimap<time_t, MsgRegister> mMsgTimeline;
|
|
||||||
|
|
||||||
int mStorePeriod;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,413 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdiface.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BIT_DHT_INTERFACE_H
|
|
||||||
#define BIT_DHT_INTERFACE_H
|
|
||||||
|
|
||||||
#include <iosfwd>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#include "util/bdnet.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Functions and Classes required for Interfacing with the BitDht.
|
|
||||||
* This should be the sole header file required to talk to Dht.
|
|
||||||
* ... though setting it up will require including udpbitdht.h as well.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BITDHT_KEY_LEN 20
|
|
||||||
#define BITDHT_KEY_INTLEN 5
|
|
||||||
#define BITDHT_KEY_BITLEN 160
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_MAX_PKTSIZE 1024
|
|
||||||
|
|
||||||
#define BITDHT_TTL 64
|
|
||||||
|
|
||||||
#define BITDHT_SEARCH_ONE_SHOT 1
|
|
||||||
#define BITDHT_SEARCH_REPEATING 2
|
|
||||||
|
|
||||||
class bdNodeId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
unsigned char data[BITDHT_KEY_LEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdMetric: public bdNodeId {};
|
|
||||||
|
|
||||||
class bdId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdId();
|
|
||||||
bdId(bdNodeId in_id, struct sockaddr_in in_addr);
|
|
||||||
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
bdNodeId id;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define BITDHT_LIKELY_SAME_NO 0x00000000
|
|
||||||
#define BITDHT_LIKELY_SAME_YES 0x00000001
|
|
||||||
#define BITDHT_LIKELY_SAME_PORT_CHANGED 0x00000002
|
|
||||||
#define BITDHT_LIKELY_SAME_LOC_CHANGED 0x00000004
|
|
||||||
#define BITDHT_LIKELY_SAME_IDENTICAL 0x00000008
|
|
||||||
|
|
||||||
|
|
||||||
class bdDhtFunctions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// bdDhtFunctions();
|
|
||||||
/* setup variables */
|
|
||||||
virtual uint16_t bdNumBuckets() = 0;
|
|
||||||
virtual uint16_t bdNodesPerBucket() = 0; /* used for bdspace */
|
|
||||||
virtual uint16_t bdNumQueryNodes() = 0; /* used for queries */
|
|
||||||
virtual uint16_t bdBucketBitSize() = 0;
|
|
||||||
|
|
||||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric) = 0;
|
|
||||||
virtual int bdBucketDistance(const bdNodeId *n1, const bdNodeId *n2) = 0;
|
|
||||||
virtual int bdBucketDistance(const bdMetric *metric) = 0;
|
|
||||||
|
|
||||||
virtual bool bdSimilarId(const bdId *id1, const bdId *id2) = 0;
|
|
||||||
virtual bool bdUpdateSimilarId(bdId *dest, const bdId *src) = 0;
|
|
||||||
|
|
||||||
virtual void bdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *mid) = 0;
|
|
||||||
|
|
||||||
virtual void bdPrintId(std::ostream &out, const bdId *a) = 0;
|
|
||||||
virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DHT MODES
|
|
||||||
#define BITDHT_MODE_TRAFFIC_MASK 0x00000f00
|
|
||||||
#define BITDHT_MODE_RELAYSERVER_MASK 0x0000f000
|
|
||||||
|
|
||||||
// These are not ORd - only one can apply.
|
|
||||||
#define BITDHT_MODE_TRAFFIC_HIGH 0x00000100
|
|
||||||
#define BITDHT_MODE_TRAFFIC_MED 0x00000200
|
|
||||||
#define BITDHT_MODE_TRAFFIC_LOW 0x00000300
|
|
||||||
#define BITDHT_MODE_TRAFFIC_TRICKLE 0x00000400
|
|
||||||
#define BITDHT_MODE_TRAFFIC_DEFAULT BITDHT_MODE_TRAFFIC_LOW
|
|
||||||
|
|
||||||
// These are not ORd - only one can apply.
|
|
||||||
#define BITDHT_MODE_RELAYSERVERS_IGNORED 0x00001000
|
|
||||||
#define BITDHT_MODE_RELAYSERVERS_FLAGGED 0x00002000
|
|
||||||
#define BITDHT_MODE_RELAYSERVERS_ONLY 0x00003000
|
|
||||||
#define BITDHT_MODE_RELAYSERVERS_SERVER 0x00004000
|
|
||||||
|
|
||||||
|
|
||||||
/* NODE OPTIONS */
|
|
||||||
#define BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT 0x00000001
|
|
||||||
#define BITDHT_OPTIONS_ENABLE_RELAYS 0x00000002
|
|
||||||
|
|
||||||
|
|
||||||
/* peer flags
|
|
||||||
* order is important!
|
|
||||||
* higher bits = more priority.
|
|
||||||
* BITDHT_PEER_STATUS_RECVPING
|
|
||||||
* BITDHT_PEER_STATUS_RECVPONG
|
|
||||||
* BITDHT_PEER_STATUS_RECVNODES
|
|
||||||
* BITDHT_PEER_STATUS_RECVHASHES
|
|
||||||
* BITDHT_PEER_STATUS_DHT_ENGINE (dbXXxx)
|
|
||||||
* BITDHT_PEER_STATUS_DHT_APPL (XXRSxx)
|
|
||||||
* BITDHT_PEER_STATUS_DHT_VERSION (XXxx50)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BITDHT_PEER_STATUS_MASK_RECVD 0x000000ff
|
|
||||||
#define BITDHT_PEER_STATUS_MASK_DHT 0x0000ff00
|
|
||||||
#define BITDHT_PEER_STATUS_MASK_KNOWN 0x00ff0000
|
|
||||||
|
|
||||||
#define BITDHT_PEER_STATUS_RECV_PING 0x00000001
|
|
||||||
#define BITDHT_PEER_STATUS_RECV_PONG 0x00000002
|
|
||||||
#define BITDHT_PEER_STATUS_RECV_NODES 0x00000004
|
|
||||||
#define BITDHT_PEER_STATUS_RECV_HASHES 0x00000008
|
|
||||||
#define BITDHT_PEER_STATUS_RECV_CONNECT_MSG 0x00000010
|
|
||||||
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_ENGINE 0x00000100
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_ENGINE_VERSION 0x00000200
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_APPL 0x00000400
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_APPL_VERSION 0x00000800
|
|
||||||
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_WHITELIST 0x00010000
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_FOF 0x00020000
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_FRIEND 0x00040000
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_RELAY_SERVER 0x00080000 // (Flag must be enabled)
|
|
||||||
#define BITDHT_PEER_STATUS_DHT_SELF 0x00100000
|
|
||||||
|
|
||||||
|
|
||||||
// EXTRA FLAGS are our internal thoughts about the peer.
|
|
||||||
#define BITDHT_PEER_EXFLAG_MASK_BASIC 0x000000ff
|
|
||||||
#define BITDHT_PEER_EXFLAG_UNSTABLE 0x00000001 // Port changes.
|
|
||||||
#define BITDHT_PEER_EXFLAG_ATTACHED 0x00000002 // We will ping in heavily. (if unstable)
|
|
||||||
#define BITDHT_PEER_EXFLAG_BADPEER 0x00000004 // For testing, we flag rather than discard.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_MODE_DIRECT 0x00000001
|
|
||||||
#define BITDHT_CONNECT_MODE_PROXY 0x00000002
|
|
||||||
#define BITDHT_CONNECT_MODE_RELAY 0x00000004
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_OPTION_AUTOPROXY 0x00000001
|
|
||||||
|
|
||||||
// STATUS CODES. == 0 is okay, != 0 is error.
|
|
||||||
#define BITDHT_CONNECT_ANSWER_OKAY 0x00000000
|
|
||||||
#define BITDHT_CONNECT_ERROR_NONE (BITDHT_CONNECT_ANSWER_OKAY)
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_ERROR_MASK_TYPE 0x0000ffff
|
|
||||||
#define BITDHT_CONNECT_ERROR_MASK_SOURCE 0x00ff0000
|
|
||||||
#define BITDHT_CONNECT_ERROR_MASK_CRMOVE 0xff000000
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_ERROR_SOURCE_START 0x00010000
|
|
||||||
#define BITDHT_CONNECT_ERROR_SOURCE_MID 0x00020000
|
|
||||||
#define BITDHT_CONNECT_ERROR_SOURCE_END 0x00040000
|
|
||||||
#define BITDHT_CONNECT_ERROR_SOURCE_OTHER 0x00080000
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_ERROR_CRMOVE_FATAL 0x01000000
|
|
||||||
#define BITDHT_CONNECT_ERROR_CRMOVE_NOMOREIDS 0x02000000
|
|
||||||
#define BITDHT_CONNECT_ERROR_CRMOVE_NEXTID 0x04000000
|
|
||||||
#define BITDHT_CONNECT_ERROR_CRMOVE_PAUSED 0x08000000
|
|
||||||
|
|
||||||
// ERROR CODES.
|
|
||||||
#define BITDHT_CONNECT_ERROR_GENERIC 0x00000001
|
|
||||||
#define BITDHT_CONNECT_ERROR_PROTOCOL 0x00000002
|
|
||||||
#define BITDHT_CONNECT_ERROR_TIMEOUT 0x00000003
|
|
||||||
#define BITDHT_CONNECT_ERROR_TEMPUNAVAIL 0x00000004 // Haven't got ext address yet.
|
|
||||||
#define BITDHT_CONNECT_ERROR_NOADDRESS 0x00000005 // Can't find the peer in tables.
|
|
||||||
#define BITDHT_CONNECT_ERROR_UNREACHABLE 0x00000006 // Symmetric NAT
|
|
||||||
|
|
||||||
#define BITDHT_CONNECT_ERROR_UNSUPPORTED 0x00000007
|
|
||||||
#define BITDHT_CONNECT_ERROR_OVERLOADED 0x00000008
|
|
||||||
#define BITDHT_CONNECT_ERROR_AUTH_DENIED 0x00000009
|
|
||||||
#define BITDHT_CONNECT_ERROR_DUPLICATE 0x0000000a
|
|
||||||
|
|
||||||
// These are slightly special ones used for CB_REQUEST
|
|
||||||
#define BITDHT_CONNECT_ERROR_TOOMANYRETRY 0x0000000b
|
|
||||||
#define BITDHT_CONNECT_ERROR_OUTOFPROXY 0x0000000c
|
|
||||||
#define BITDHT_CONNECT_ERROR_USER 0x0000000d
|
|
||||||
|
|
||||||
|
|
||||||
/*************/
|
|
||||||
// FRIEND_ENTRY_FLAGS... used by updateKnownPeers().
|
|
||||||
|
|
||||||
#define BD_FRIEND_ENTRY_ONLINE 0x0001
|
|
||||||
#define BD_FRIEND_ENTRY_ADDR_OK 0x0002
|
|
||||||
|
|
||||||
#define BD_FRIEND_ENTRY_WHITELIST BITDHT_PEER_STATUS_DHT_WHITELIST
|
|
||||||
#define BD_FRIEND_ENTRY_FOF BITDHT_PEER_STATUS_DHT_FOF
|
|
||||||
#define BD_FRIEND_ENTRY_FRIEND BITDHT_PEER_STATUS_DHT_FRIEND
|
|
||||||
#define BD_FRIEND_ENTRY_RELAY_SERVER BITDHT_PEER_STATUS_DHT_RELAY_SERVER
|
|
||||||
|
|
||||||
#define BD_FRIEND_ENTRY_SELF BITDHT_PEER_STATUS_DHT_SELF
|
|
||||||
|
|
||||||
#define BD_FRIEND_ENTRY_MASK_KNOWN BITDHT_PEER_STATUS_MASK_KNOWN
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Definitions of bdSpace Peer and Bucket are publically available,
|
|
||||||
* so we can expose the bucket entries for the gui.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class bdPeer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdPeer():mPeerFlags(0), mLastSendTime(0), mLastRecvTime(0), mFoundTime(0), mExtraFlags(0) { return; }
|
|
||||||
|
|
||||||
bdId mPeerId;
|
|
||||||
uint32_t mPeerFlags;
|
|
||||||
time_t mLastSendTime;
|
|
||||||
time_t mLastRecvTime;
|
|
||||||
time_t mFoundTime; /* time stamp that peer was found */
|
|
||||||
|
|
||||||
uint32_t mExtraFlags;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdBucket
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdBucket();
|
|
||||||
/* list so we can queue properly */
|
|
||||||
std::list<bdPeer> entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdQueryStatus
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
uint32_t mStatus;
|
|
||||||
uint32_t mQFlags;
|
|
||||||
std::list<bdId> mResults;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdQuerySummary
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdNodeId mId;
|
|
||||||
bdMetric mLimit;
|
|
||||||
uint32_t mState;
|
|
||||||
time_t mQueryTS;
|
|
||||||
uint32_t mQueryFlags;
|
|
||||||
int32_t mSearchTime;
|
|
||||||
|
|
||||||
int32_t mQueryIdlePeerRetryPeriod; // seconds between retries.
|
|
||||||
|
|
||||||
// closest peers
|
|
||||||
std::multimap<bdMetric, bdPeer> mClosest;
|
|
||||||
std::multimap<bdMetric, bdPeer> mPotentialPeers;
|
|
||||||
std::list<bdPeer> mProxiesUnknown;
|
|
||||||
std::list<bdPeer> mProxiesFlagged;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Status options */
|
|
||||||
#define BITDHT_QUERY_READY 1
|
|
||||||
#define BITDHT_QUERY_QUERYING 2
|
|
||||||
#define BITDHT_QUERY_FAILURE 3
|
|
||||||
#define BITDHT_QUERY_FOUND_CLOSEST 4
|
|
||||||
#define BITDHT_QUERY_PEER_UNREACHABLE 5
|
|
||||||
#define BITDHT_QUERY_SUCCESS 6
|
|
||||||
|
|
||||||
/* Query Flags */
|
|
||||||
#define BITDHT_QFLAGS_NONE 0x0000
|
|
||||||
#define BITDHT_QFLAGS_DISGUISE 0x0001 // Don't search directly for target.
|
|
||||||
#define BITDHT_QFLAGS_DO_IDLE 0x0002
|
|
||||||
#define BITDHT_QFLAGS_INTERNAL 0x0004 // runs through startup. (limited callback)
|
|
||||||
#define BITDHT_QFLAGS_UPDATES 0x0008 // Do regular updates.
|
|
||||||
|
|
||||||
/* Connect Callback Flags */
|
|
||||||
#define BITDHT_CONNECT_CB_AUTH 1
|
|
||||||
#define BITDHT_CONNECT_CB_PENDING 2
|
|
||||||
#define BITDHT_CONNECT_CB_START 3
|
|
||||||
#define BITDHT_CONNECT_CB_PROXY 4
|
|
||||||
#define BITDHT_CONNECT_CB_FAILED 5
|
|
||||||
#define BITDHT_CONNECT_CB_REQUEST 6
|
|
||||||
|
|
||||||
#define BD_PROXY_CONNECTION_UNKNOWN_POINT 0
|
|
||||||
#define BD_PROXY_CONNECTION_START_POINT 1
|
|
||||||
#define BD_PROXY_CONNECTION_MID_POINT 2
|
|
||||||
#define BD_PROXY_CONNECTION_END_POINT 3
|
|
||||||
|
|
||||||
#define BITDHT_INFO_CB_TYPE_BADPEER 1
|
|
||||||
|
|
||||||
/* Relay Modes */
|
|
||||||
#define BITDHT_RELAYS_OFF 0
|
|
||||||
#define BITDHT_RELAYS_ON 1
|
|
||||||
#define BITDHT_RELAYS_ONLY 2
|
|
||||||
#define BITDHT_RELAYS_SERVER 3
|
|
||||||
|
|
||||||
|
|
||||||
class BitDhtCallback
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// ~BitDhtCallback();
|
|
||||||
|
|
||||||
// dummy cos not needed for standard dht behaviour;
|
|
||||||
virtual int dhtNodeCallback(const bdId * /*id*/, uint32_t /*peerflags*/) { return 0; }
|
|
||||||
|
|
||||||
// must be implemented.
|
|
||||||
virtual int dhtPeerCallback(const bdId *id, uint32_t status) = 0;
|
|
||||||
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status) = 0;
|
|
||||||
|
|
||||||
// connection callback. Not required for basic behaviour, but forced for initial development.
|
|
||||||
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
|
||||||
uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode) = 0; /* { return 0; } */
|
|
||||||
|
|
||||||
// Generic Info callback - initially will be used to provide bad peers.
|
|
||||||
virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info) = 0;
|
|
||||||
|
|
||||||
// ask upper layer whether an IP is banned or not
|
|
||||||
// must not be implemented
|
|
||||||
// when set it will be used instead of the own ban list
|
|
||||||
// return code is used to express availability/absence
|
|
||||||
virtual int dhtIsBannedCallback(const sockaddr_in */*addr*/, bool */*isBanned*/) { return 0;}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BitDhtInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/* bad peer notification */
|
|
||||||
virtual void addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age) = 0;
|
|
||||||
|
|
||||||
/* Friend Tracking */
|
|
||||||
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags) = 0;
|
|
||||||
|
|
||||||
/***** Request Lookup (DHT Peer & Keyword) *****/
|
|
||||||
virtual void addFindNode(bdNodeId *id, uint32_t mode) = 0;
|
|
||||||
virtual void removeFindNode(bdNodeId *id) = 0;
|
|
||||||
virtual void findDhtValue(bdNodeId *id, std::string key, uint32_t mode) = 0;
|
|
||||||
|
|
||||||
/***** Connections Requests *****/
|
|
||||||
virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t delay, uint32_t start) = 0;
|
|
||||||
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc,
|
|
||||||
uint32_t bandwidth, uint32_t delay, uint32_t answer) = 0;
|
|
||||||
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags) = 0;
|
|
||||||
|
|
||||||
virtual bool setAttachMode(bool on) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/***** Add / Remove Callback Clients *****/
|
|
||||||
virtual void addCallback(BitDhtCallback *cb) = 0;
|
|
||||||
virtual void removeCallback(BitDhtCallback *cb) = 0;
|
|
||||||
|
|
||||||
/***** Get Results Details *****/
|
|
||||||
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from) = 0;
|
|
||||||
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value) = 0;
|
|
||||||
virtual int getDhtBucket(const int idx, bdBucket &bucket) = 0;
|
|
||||||
|
|
||||||
virtual int getDhtQueries(std::map<bdNodeId, bdQueryStatus> &queries) = 0;
|
|
||||||
virtual int getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query) = 0;
|
|
||||||
|
|
||||||
/* stats and Dht state */
|
|
||||||
virtual int startDht() = 0;
|
|
||||||
virtual int stopDht() = 0;
|
|
||||||
virtual int stateDht() = 0; /* STOPPED, STARTING, ACTIVE, FAILED */
|
|
||||||
virtual uint32_t statsNetworkSize() = 0;
|
|
||||||
virtual uint32_t statsBDVersionSize() = 0; /* same version as us! */
|
|
||||||
|
|
||||||
virtual uint32_t setDhtMode(uint32_t dhtFlags) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// general helper functions for decoding error messages.
|
|
||||||
std::string decodeConnectionError(uint32_t errcode);
|
|
||||||
std::string decodeConnectionErrorCRMove(uint32_t errcode);
|
|
||||||
std::string decodeConnectionErrorSource(uint32_t errcode);
|
|
||||||
std::string decodeConnectionErrorType(uint32_t errcode);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,209 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdmanager.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_MANAGER_H
|
|
||||||
#define BITDHT_MANAGER_H
|
|
||||||
|
|
||||||
/*******
|
|
||||||
* Node Manager.
|
|
||||||
******/
|
|
||||||
|
|
||||||
/******************************************
|
|
||||||
* 1) Maintains a list of ids to search for.
|
|
||||||
* 2) Sets up initial search for own node.
|
|
||||||
* 3) Checks on status of queries.
|
|
||||||
* 4) Callback on successful searches.
|
|
||||||
*
|
|
||||||
* This is pretty specific to RS requirements.
|
|
||||||
****/
|
|
||||||
|
|
||||||
#define BITDHT_PS_MASK_ACTIONS (0x000000ff)
|
|
||||||
#define BITDHT_PS_MASK_STATE (0x0000ff00)
|
|
||||||
|
|
||||||
#define BITDHT_PS_ACTION_SEARCHING (0x00000001)
|
|
||||||
#define BITDHT_PS_ACTION_WAITING (0x00000002)
|
|
||||||
#define BITDHT_PS_ACTION_PINGING (0x00000004)
|
|
||||||
|
|
||||||
#define BITDHT_PS_STATE_UNKNOWN (0x00000100)
|
|
||||||
#define BITDHT_PS_STATE_OFFLINE (0x00000200)
|
|
||||||
#define BITDHT_PS_STATE_ONLINE (0x00000400)
|
|
||||||
#define BITDHT_PS_STATE_CONNECTED (0x00000800)
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include "bitdht/bdnode.h"
|
|
||||||
#include "util/bdbloom.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class bdQueryPeer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdId mId;
|
|
||||||
uint32_t mStatus;
|
|
||||||
uint32_t mQFlags;
|
|
||||||
//time_t mLastQuery;
|
|
||||||
//time_t mLastFound;
|
|
||||||
struct sockaddr_in mDhtAddr;
|
|
||||||
time_t mCallbackTS; // for UPDATES flag.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_MGR_STATE_OFF 0
|
|
||||||
#define BITDHT_MGR_STATE_STARTUP 1
|
|
||||||
#define BITDHT_MGR_STATE_FINDSELF 2
|
|
||||||
#define BITDHT_MGR_STATE_ACTIVE 3
|
|
||||||
#define BITDHT_MGR_STATE_REFRESH 4
|
|
||||||
#define BITDHT_MGR_STATE_QUIET 5
|
|
||||||
#define BITDHT_MGR_STATE_FAILED 6
|
|
||||||
|
|
||||||
#define MAX_STARTUP_TIME 10
|
|
||||||
#define MAX_REFRESH_TIME 10
|
|
||||||
|
|
||||||
#define BITDHT_MGR_QUERY_FAILURE 1
|
|
||||||
#define BITDHT_MGR_QUERY_PEER_OFFLINE 2
|
|
||||||
#define BITDHT_MGR_QUERY_PEER_UNREACHABLE 3
|
|
||||||
#define BITDHT_MGR_QUERY_PEER_ONLINE 4
|
|
||||||
|
|
||||||
|
|
||||||
/*** NB: Nothing in here is protected by mutexes
|
|
||||||
* must be done at a higher level!
|
|
||||||
***/
|
|
||||||
|
|
||||||
class bdNodeManager: public bdNode, public BitDhtInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, std::string bootfilebak, const std::string &filterfile, bdDhtFunctions *fns);
|
|
||||||
|
|
||||||
|
|
||||||
void iteration();
|
|
||||||
|
|
||||||
/***** Functions to Call down to bdNodeManager ****/
|
|
||||||
|
|
||||||
|
|
||||||
/* Friend Tracking */
|
|
||||||
virtual void addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age);
|
|
||||||
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags);
|
|
||||||
|
|
||||||
/* Request DHT Peer Lookup */
|
|
||||||
/* Request Keyword Lookup */
|
|
||||||
virtual void addFindNode(bdNodeId *id, uint32_t mode);
|
|
||||||
virtual void removeFindNode(bdNodeId *id);
|
|
||||||
virtual void findDhtValue(bdNodeId *id, std::string key, uint32_t mode);
|
|
||||||
|
|
||||||
/***** Add / Remove Callback Clients *****/
|
|
||||||
virtual void addCallback(BitDhtCallback *cb);
|
|
||||||
virtual void removeCallback(BitDhtCallback *cb);
|
|
||||||
|
|
||||||
/***** Get Results Details *****/
|
|
||||||
virtual int getDhtPeerAddress(const bdNodeId *id, struct sockaddr_in &from);
|
|
||||||
virtual int getDhtValue(const bdNodeId *id, std::string key, std::string &value);
|
|
||||||
virtual int getDhtBucket(const int idx, bdBucket &bucket);
|
|
||||||
|
|
||||||
virtual int getDhtQueries(std::map<bdNodeId, bdQueryStatus> &queries);
|
|
||||||
virtual int getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query);
|
|
||||||
|
|
||||||
/***** Connection Interface ****/
|
|
||||||
virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t delay, uint32_t start);
|
|
||||||
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
uint32_t mode, uint32_t loc, uint32_t bandwidth, uint32_t delay, uint32_t answer);
|
|
||||||
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);
|
|
||||||
|
|
||||||
virtual bool setAttachMode(bool on);
|
|
||||||
|
|
||||||
/* stats and Dht state */
|
|
||||||
virtual int startDht();
|
|
||||||
virtual int stopDht();
|
|
||||||
virtual int stateDht(); /* STOPPED, STARTING, ACTIVE, FAILED */
|
|
||||||
virtual uint32_t statsNetworkSize();
|
|
||||||
virtual uint32_t statsBDVersionSize(); /* same version as us! */
|
|
||||||
|
|
||||||
virtual uint32_t setDhtMode(uint32_t dhtFlags);
|
|
||||||
|
|
||||||
/******************* Internals *************************/
|
|
||||||
|
|
||||||
// Overloaded from bdnode for external node callback.
|
|
||||||
virtual void addPeer(const bdId *id, uint32_t peerflags);
|
|
||||||
// Overloaded from bdnode for external node callback.
|
|
||||||
virtual void callbackConnect(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
int mode, int point, int param, int cbtype, int errcode);
|
|
||||||
|
|
||||||
int isBitDhtPacket(char *data, int size, struct sockaddr_in &from);
|
|
||||||
|
|
||||||
// this function is used by bdFilter (must be public!)
|
|
||||||
void doIsBannedCallback(const sockaddr_in *addr, bool *isAvailable, bool* isBanned);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
void doNodeCallback(const bdId *id, uint32_t peerflags);
|
|
||||||
void doPeerCallback(const bdId *id, uint32_t status);
|
|
||||||
void doValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
|
||||||
void doInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info);
|
|
||||||
|
|
||||||
int status();
|
|
||||||
int checkStatus();
|
|
||||||
int checkPingStatus();
|
|
||||||
int checkBadPeerStatus();
|
|
||||||
int SearchOutOfDate();
|
|
||||||
void startQueries();
|
|
||||||
|
|
||||||
int QueryRandomLocalNet();
|
|
||||||
void SearchForLocalNet();
|
|
||||||
|
|
||||||
std::map<bdNodeId, bdQueryPeer> mActivePeers;
|
|
||||||
std::list<BitDhtCallback *> mCallbacks;
|
|
||||||
|
|
||||||
uint32_t mMode;
|
|
||||||
time_t mModeTS;
|
|
||||||
|
|
||||||
time_t mStartTS;
|
|
||||||
time_t mSearchTS;
|
|
||||||
bool mSearchingDone;
|
|
||||||
|
|
||||||
bdDhtFunctions *mDhtFns;
|
|
||||||
|
|
||||||
uint32_t mNetworkSize;
|
|
||||||
uint32_t mBdNetworkSize;
|
|
||||||
|
|
||||||
bdBloom mBloomFilter;
|
|
||||||
|
|
||||||
bool mLocalNetEnhancements;
|
|
||||||
|
|
||||||
/* future node functions */
|
|
||||||
//addPeerPing(foundId);
|
|
||||||
//clearPing(it->first);
|
|
||||||
//PingStatus(it->first);
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdDebugCallback: public BitDhtCallback
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~bdDebugCallback();
|
|
||||||
virtual int dhtPeerCallback(const bdId *id, uint32_t status);
|
|
||||||
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
|
||||||
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
|
||||||
uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode);
|
|
||||||
virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,127 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdmsgs.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_MSGS_H
|
|
||||||
#define BITDHT_MSGS_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <list>
|
|
||||||
#include "bitdht/bencode.h"
|
|
||||||
#include "bitdht/bdobj.h"
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
|
|
||||||
#define BITDHT_MSG_TYPE_UNKNOWN 0
|
|
||||||
#define BITDHT_MSG_TYPE_PING 1
|
|
||||||
#define BITDHT_MSG_TYPE_PONG 2
|
|
||||||
#define BITDHT_MSG_TYPE_FIND_NODE 3
|
|
||||||
#define BITDHT_MSG_TYPE_REPLY_NODE 4
|
|
||||||
#define BITDHT_MSG_TYPE_GET_HASH 5
|
|
||||||
#define BITDHT_MSG_TYPE_REPLY_HASH 6
|
|
||||||
#define BITDHT_MSG_TYPE_REPLY_NEAR 7
|
|
||||||
#define BITDHT_MSG_TYPE_POST_HASH 8
|
|
||||||
#define BITDHT_MSG_TYPE_REPLY_POST 9
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// THESE ARE EXTENSIONS
|
|
||||||
#define BITDHT_MSG_TYPE_CONNECT 20
|
|
||||||
|
|
||||||
// CONNECTIONS.
|
|
||||||
#define BITDHT_MSG_TYPE_CONNECT_REQUEST 101
|
|
||||||
#define BITDHT_MSG_TYPE_CONNECT_REPLY 102
|
|
||||||
#define BITDHT_MSG_TYPE_CONNECT_START 103
|
|
||||||
#define BITDHT_MSG_TYPE_CONNECT_ACK 104
|
|
||||||
|
|
||||||
// FANCY HASHES.
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_COMPACTNODEID_LEN 26
|
|
||||||
#define BITDHT_COMPACTPEERID_LEN 6
|
|
||||||
|
|
||||||
#define BE_Y_UNKNOWN 0
|
|
||||||
#define BE_Y_R 1
|
|
||||||
#define BE_Y_Q 2
|
|
||||||
|
|
||||||
|
|
||||||
/****** Known BD Version Strings ******/
|
|
||||||
|
|
||||||
#define BITDHT_VID_RS1 1
|
|
||||||
#define BITDHT_VID_UT 2
|
|
||||||
|
|
||||||
|
|
||||||
int bitdht_create_ping_msg(bdToken *tid, bdNodeId *id, bdToken *vid, char *msg, int avail);
|
|
||||||
int bitdht_response_ping_msg(bdToken *tid, bdNodeId *id, bdToken *vid, char *msg, int avail);
|
|
||||||
int bitdht_find_node_msg(bdToken *tid, bdNodeId *id, bdNodeId *target, bool localnet, char *msg, int avail);
|
|
||||||
int bitdht_resp_node_msg(bdToken *tid, bdNodeId *id, std::list<bdId> &nodes,
|
|
||||||
char *msg, int avail);
|
|
||||||
int bitdht_get_peers_msg(bdToken *tid, bdNodeId *id, bdNodeId *info_hash,
|
|
||||||
char *msg, int avail);
|
|
||||||
int bitdht_peers_reply_hash_msg(bdToken *tid, bdNodeId *id,
|
|
||||||
bdToken *token, std::list<std::string> &values,
|
|
||||||
char *msg, int avail);
|
|
||||||
int bitdht_peers_reply_closest_msg(bdToken *tid, bdNodeId *id,
|
|
||||||
bdToken *token, std::list<bdId> &nodes,
|
|
||||||
char *msg, int avail);
|
|
||||||
int bitdht_announce_peers_msg(bdToken *tid, bdNodeId *id, bdNodeId *info_hash,
|
|
||||||
uint32_t port, bdToken *token, char *msg, int avail);
|
|
||||||
int bitdht_reply_announce_msg(bdToken *tid, bdNodeId *id,
|
|
||||||
char *msg, int avail);
|
|
||||||
|
|
||||||
|
|
||||||
// Extensions.
|
|
||||||
int bitdht_connect_genmsg(bdToken *tid, bdNodeId *id, int msgtype, bdId *src, bdId *dest, int mode, int param, int status, char *msg, int avail);
|
|
||||||
|
|
||||||
|
|
||||||
//int response_peers_message()
|
|
||||||
//int response_closestnodes_message()
|
|
||||||
|
|
||||||
be_node *beMsgGetDictNode(be_node *node, const char *key);
|
|
||||||
int beMsgMatchString(be_node *n, const char *str, int len);
|
|
||||||
uint32_t beMsgGetY(be_node *n);
|
|
||||||
uint32_t beMsgType(be_node *n);
|
|
||||||
|
|
||||||
bool bitdht_msgtype(uint32_t msg_type, std::string &name);
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t convertBdVersionToVID(bdVersion *version);
|
|
||||||
|
|
||||||
be_node *makeCompactPeerIds(std::list<std::string> &values);
|
|
||||||
be_node *makeCompactNodeIdString(std::list<bdId> &nodes);
|
|
||||||
|
|
||||||
int beMsgGetToken(be_node *n, bdToken &token);
|
|
||||||
int beMsgGetNodeId(be_node *n, bdNodeId &nodeId);
|
|
||||||
int beMsgGetBdId(be_node *n, bdId &id);
|
|
||||||
int beMsgGetListBdIds(be_node *n, std::list<bdId> &nodes);
|
|
||||||
|
|
||||||
int beMsgGetListStrings(be_node *n, std::list<std::string> &values);
|
|
||||||
int beMsgGetUInt32(be_node *n, uint32_t *port);
|
|
||||||
|
|
||||||
/* Low Level conversion functions */
|
|
||||||
int decodeCompactPeerId(struct sockaddr_in *addr, char *enc, int len);
|
|
||||||
std::string encodeCompactPeerId(struct sockaddr_in *addr);
|
|
||||||
|
|
||||||
int decodeCompactNodeId(bdId *id, char *enc, int len);
|
|
||||||
std::string encodeCompactNodeId(bdId *id);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,284 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdnode.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_NODE_H
|
|
||||||
#define BITDHT_NODE_H
|
|
||||||
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
#include "bitdht/bdquery.h"
|
|
||||||
#include "bitdht/bdstore.h"
|
|
||||||
#include "bitdht/bdobj.h"
|
|
||||||
#include "bitdht/bdhash.h"
|
|
||||||
#include "bitdht/bdhistory.h"
|
|
||||||
#include "bitdht/bdfilter.h"
|
|
||||||
|
|
||||||
#include "bitdht/bdconnection.h"
|
|
||||||
#include "bitdht/bdaccount.h"
|
|
||||||
|
|
||||||
#include "bitdht/bdfriendlist.h"
|
|
||||||
|
|
||||||
class bdFilter;
|
|
||||||
|
|
||||||
|
|
||||||
#define BD_QUERY_NEIGHBOURS 1
|
|
||||||
#define BD_QUERY_LOCALNET 2
|
|
||||||
#define BD_QUERY_HASH 3
|
|
||||||
|
|
||||||
/**********************************
|
|
||||||
* Running a node....
|
|
||||||
*
|
|
||||||
* run().
|
|
||||||
* loops through and checks out of date peers.
|
|
||||||
* handles searches.
|
|
||||||
* prints out dht Table.
|
|
||||||
*
|
|
||||||
|
|
||||||
The node handles the i/o traffic from peers.
|
|
||||||
It
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ping, return
|
|
||||||
peers, return
|
|
||||||
hash store, return
|
|
||||||
hash get, return
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
respond queue.
|
|
||||||
|
|
||||||
query queue.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
input -> call into recvFunction()
|
|
||||||
output -> call back to Udp().
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*********/
|
|
||||||
|
|
||||||
class bdFilteredPeer ;
|
|
||||||
class bdNodeManager;
|
|
||||||
|
|
||||||
class bdNodeNetMsg
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
bdNodeNetMsg(char *data, int size, struct sockaddr_in *addr);
|
|
||||||
~bdNodeNetMsg();
|
|
||||||
|
|
||||||
void print(std::ostream &out);
|
|
||||||
|
|
||||||
char *data;
|
|
||||||
int mSize;
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdNodePublisher
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/* simplified outgoing msg functions (for the managers) */
|
|
||||||
virtual void send_ping(bdId *id) = 0; /* message out */
|
|
||||||
virtual void send_query(bdId *id, bdNodeId *targetNodeId, bool localnet) = 0; /* message out */
|
|
||||||
virtual void send_connect_msg(bdId *id, int msgtype,
|
|
||||||
bdId *srcAddr, bdId *destAddr, int mode, int param, int status) = 0;
|
|
||||||
|
|
||||||
// internal Callback -> normally continues to callbackConnect().
|
|
||||||
virtual void callbackConnect(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
int mode, int point, int param, int cbtype, int errcode) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdNode: public bdNodePublisher
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdNode(bdNodeId *id, std::string dhtVersion, const std::string& bootfile, const std::string& bootfilebak, const std::string& filterfile,
|
|
||||||
bdDhtFunctions *fns, bdNodeManager* manager);
|
|
||||||
|
|
||||||
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
|
||||||
|
|
||||||
void setNodeOptions(uint32_t optFlags);
|
|
||||||
uint32_t setNodeDhtMode(uint32_t dhtFlags);
|
|
||||||
|
|
||||||
/* startup / shutdown node */
|
|
||||||
void restartNode();
|
|
||||||
void shutdownNode();
|
|
||||||
|
|
||||||
void getOwnId(bdNodeId *id);
|
|
||||||
|
|
||||||
// virtual so manager can do callback.
|
|
||||||
// peer flags defined in bdiface.h
|
|
||||||
virtual void addPeer(const bdId *id, uint32_t peerflags);
|
|
||||||
|
|
||||||
void printState();
|
|
||||||
void checkPotentialPeer(bdId *id, bdId *src);
|
|
||||||
void addPotentialPeer(bdId *id, bdId *src);
|
|
||||||
|
|
||||||
void iterationOff();
|
|
||||||
void iteration();
|
|
||||||
void processRemoteQuery();
|
|
||||||
void updateStore();
|
|
||||||
|
|
||||||
bool addressBanned(const sockaddr_in &raddr) ;
|
|
||||||
bool getFilteredPeers(std::list<bdFilteredPeer> &peers);
|
|
||||||
//void loadFilteredPeers(const std::list<bdFilteredPeer> &peers);
|
|
||||||
|
|
||||||
/* simplified outgoing msg functions (for the managers) */
|
|
||||||
virtual void send_ping(bdId *id); /* message out */
|
|
||||||
virtual void send_query(bdId *id, bdNodeId *targetNodeId, bool localnet); /* message out */
|
|
||||||
virtual void send_connect_msg(bdId *id, int msgtype,
|
|
||||||
bdId *srcAddr, bdId *destAddr, int mode, int param, int status);
|
|
||||||
|
|
||||||
// This is implemented in bdManager.
|
|
||||||
// virtual void callbackConnect(bdId *srcId, bdId *proxyId, bdId *destId,
|
|
||||||
// int mode, int point, int param, int cbtype, int errcode);
|
|
||||||
|
|
||||||
/* interaction with outside world (Accessed by controller to deliver us msgs) */
|
|
||||||
int outgoingMsg(struct sockaddr_in *addr, char *msg, int *len);
|
|
||||||
void incomingMsg(struct sockaddr_in *addr, char *msg, int len);
|
|
||||||
|
|
||||||
// For Relay Mode switching.
|
|
||||||
void dropRelayServers();
|
|
||||||
void pingRelayServers();
|
|
||||||
|
|
||||||
// Below is internal Management of incoming / outgoing messages.
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* internal interaction with network */
|
|
||||||
void sendPkt(char *msg, int len, struct sockaddr_in addr);
|
|
||||||
void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|
||||||
|
|
||||||
|
|
||||||
/* output functions (send msg) */
|
|
||||||
void msgout_ping(bdId *id, bdToken *transId);
|
|
||||||
void msgout_pong(bdId *id, bdToken *transId);
|
|
||||||
void msgout_find_node(bdId *id, bdToken *transId, bdNodeId *query, bool localnet);
|
|
||||||
void msgout_reply_find_node(bdId *id, bdToken *transId,
|
|
||||||
std::list<bdId> &peers);
|
|
||||||
void msgout_get_hash(bdId *id, bdToken *transId, bdNodeId *info_hash);
|
|
||||||
void msgout_reply_hash(bdId *id, bdToken *transId,
|
|
||||||
bdToken *token, std::list<std::string> &values);
|
|
||||||
void msgout_reply_nearest(bdId *id, bdToken *transId,
|
|
||||||
bdToken *token, std::list<bdId> &peers);
|
|
||||||
|
|
||||||
void msgout_post_hash(bdId *id, bdToken *transId, bdNodeId *info_hash,
|
|
||||||
uint32_t port, bdToken *token);
|
|
||||||
void msgout_reply_post(bdId *id, bdToken *transId);
|
|
||||||
|
|
||||||
|
|
||||||
/* input functions (once mesg is parsed) */
|
|
||||||
uint32_t parseVersion(bdToken *versionId);
|
|
||||||
void msgin_ping(bdId *id, bdToken *token, bdToken *versionId);
|
|
||||||
void msgin_pong(bdId *id, bdToken *transId, bdToken *versionId);
|
|
||||||
|
|
||||||
void msgin_find_node(bdId *id, bdToken *transId, bdNodeId *query, bool localnet);
|
|
||||||
void msgin_reply_find_node(bdId *id, bdToken *transId,
|
|
||||||
std::list<bdId> &entries);
|
|
||||||
|
|
||||||
void msgin_get_hash(bdId *id, bdToken *transId, bdNodeId *nodeid);
|
|
||||||
void msgin_reply_hash(bdId *id, bdToken *transId,
|
|
||||||
bdToken *token, std::list<std::string> &values);
|
|
||||||
void msgin_reply_nearest(bdId *id, bdToken *transId,
|
|
||||||
bdToken *token, std::list<bdId> &nodes);
|
|
||||||
|
|
||||||
void msgin_post_hash(bdId *id, bdToken *transId,
|
|
||||||
bdNodeId *info_hash, uint32_t port, bdToken *token);
|
|
||||||
void msgin_reply_post(bdId *id, bdToken *transId);
|
|
||||||
|
|
||||||
void msgout_connect_genmsg(bdId *id, bdToken *transId, int msgtype,
|
|
||||||
bdId *srcAddr, bdId *destAddr, int mode, int param, int status);
|
|
||||||
void msgin_connect_genmsg(bdId *id, bdToken *transId, int msgtype,
|
|
||||||
bdId *srcAddr, bdId *destAddr, int mode, int param, int status);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* token handling */
|
|
||||||
void genNewToken(bdToken *token);
|
|
||||||
int queueQuery(bdId *id, bdNodeId *query, bdToken *transId, uint32_t query_type);
|
|
||||||
|
|
||||||
/* transId handling */
|
|
||||||
void genNewTransId(bdToken *token);
|
|
||||||
void registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId);
|
|
||||||
uint32_t registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId);
|
|
||||||
|
|
||||||
void cleanupTransIdRegister();
|
|
||||||
|
|
||||||
|
|
||||||
void doStats();
|
|
||||||
|
|
||||||
/********** Variables **********/
|
|
||||||
private:
|
|
||||||
|
|
||||||
/**** Some Variables are Protected to allow inherited classes to use *****/
|
|
||||||
protected:
|
|
||||||
|
|
||||||
bdSpace mNodeSpace;
|
|
||||||
bdFilter mFilterPeers;
|
|
||||||
|
|
||||||
bdQueryManager *mQueryMgr;
|
|
||||||
bdConnectManager *mConnMgr;
|
|
||||||
|
|
||||||
bdNodeId mOwnId;
|
|
||||||
bdId mLikelyOwnId; // Try to workout own id address.
|
|
||||||
std::string mDhtVersion;
|
|
||||||
|
|
||||||
bdAccount mAccount;
|
|
||||||
bdStore mStore;
|
|
||||||
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
bdHashSpace mHashSpace;
|
|
||||||
|
|
||||||
bdFriendList mFriendList;
|
|
||||||
bdPeerQueue mBadPeerQueue;
|
|
||||||
|
|
||||||
bdHistory mHistory; /* for understanding the DHT */
|
|
||||||
|
|
||||||
bdQueryHistory mQueryHistory; /* for determining old peers */
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
uint32_t mNodeOptionFlags;
|
|
||||||
uint32_t mNodeDhtMode;
|
|
||||||
|
|
||||||
uint32_t mMaxAllowedMsgs;
|
|
||||||
uint32_t mRelayMode;
|
|
||||||
|
|
||||||
|
|
||||||
std::list<bdRemoteQuery> mRemoteQueries;
|
|
||||||
|
|
||||||
std::list<bdId> mPotentialPeers;
|
|
||||||
|
|
||||||
std::list<bdNodeNetMsg *> mOutgoingMsgs;
|
|
||||||
std::list<bdNodeNetMsg *> mIncomingMsgs;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BITDHT_NODE_H
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdobj.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdobj.h"
|
|
||||||
|
|
||||||
|
|
||||||
void bdPrintTransId(std::ostream &out, bdToken *transId)
|
|
||||||
{
|
|
||||||
//out << transId->data;
|
|
||||||
bdPrintToken(out, transId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdPrintToken(std::ostream &out, bdToken *token)
|
|
||||||
{
|
|
||||||
for(unsigned int i = 0; i < token->len; i++)
|
|
||||||
{
|
|
||||||
out << std::hex << (uint32_t) token->data[i];
|
|
||||||
}
|
|
||||||
out << std::dec;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdPrintCompactPeerId(std::ostream &out, std::string /*cpi*/ )
|
|
||||||
{
|
|
||||||
out << "DummyCompactPeerId";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdobj.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_OBJECTS_H
|
|
||||||
#define BITDHT_OBJECTS_H
|
|
||||||
|
|
||||||
#define BITDHT_TOKEN_MAX_LEN 20
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
class bdToken
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdToken() :len(0) { return; }
|
|
||||||
uint32_t len;
|
|
||||||
unsigned char data[BITDHT_TOKEN_MAX_LEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdCompactIds
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdCompactIds() :len(0) { return; }
|
|
||||||
uint32_t len;
|
|
||||||
unsigned char data[BITDHT_TOKEN_MAX_LEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdVersion
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdVersion() :len(0) { return; }
|
|
||||||
uint32_t len;
|
|
||||||
unsigned char data[BITDHT_TOKEN_MAX_LEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
void bdPrintTransId(std::ostream &out, bdToken *transId);
|
|
||||||
void bdPrintToken(std::ostream &out, bdToken *transId);
|
|
||||||
void bdPrintCompactPeerId(std::ostream &out, std::string cpi);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,212 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdpeer.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_PEER_H
|
|
||||||
#define BITDHT_PEER_H
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
/*******
|
|
||||||
* These type of parameters are now DHT Function dependent
|
|
||||||
*
|
|
||||||
#define BITDHT_BUCKET_SIZE 20
|
|
||||||
#define BITDHT_BUCKET_SIZE_BITS 5
|
|
||||||
|
|
||||||
#define BITDHT_N_BUCKETS BITDHT_KEY_BITLEN
|
|
||||||
*
|
|
||||||
*
|
|
||||||
***/
|
|
||||||
|
|
||||||
/***
|
|
||||||
* DEFINED in bdiface.h
|
|
||||||
* #define BITDHT_KEY_LEN 20
|
|
||||||
* #define BITDHT_KEY_INTLEN 5
|
|
||||||
* #define BITDHT_KEY_BITLEN 160
|
|
||||||
***/
|
|
||||||
|
|
||||||
#define BITDHT_ULLONG_BITS 64
|
|
||||||
|
|
||||||
#define BITDHT_MAX_RESPONSE_PERIOD (15)
|
|
||||||
#define BITDHT_MAX_SEND_PERIOD 300 // 5 minutes.
|
|
||||||
#define BITDHT_MAX_RECV_PERIOD (BITDHT_MAX_SEND_PERIOD + BITDHT_MAX_RESPONSE_PERIOD) // didn't respond to a ping.
|
|
||||||
|
|
||||||
// Properly out of date.
|
|
||||||
#define BITDHT_DISCARD_PERIOD (2 * BITDHT_MAX_SEND_PERIOD + BITDHT_MAX_RESPONSE_PERIOD) // didn't respond to two pings.
|
|
||||||
|
|
||||||
// Must have a FLAG by this time. (Make it really quick - so we through away the rubbish).
|
|
||||||
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/****
|
|
||||||
* DEFINED in bdiface.h
|
|
||||||
*
|
|
||||||
* class bdNodeId
|
|
||||||
* {
|
|
||||||
* public:
|
|
||||||
* unsigned char data[BITDHT_KEY_LEN];
|
|
||||||
* };
|
|
||||||
****/
|
|
||||||
|
|
||||||
|
|
||||||
/****
|
|
||||||
* DEFINED in bdiface.h
|
|
||||||
*
|
|
||||||
|
|
||||||
class bdMetric: public bdNodeId {};
|
|
||||||
|
|
||||||
class bdId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdId();
|
|
||||||
bdId(bdNodeId in_id, struct sockaddr_in in_addr);
|
|
||||||
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
bdNodeId id;
|
|
||||||
};
|
|
||||||
*
|
|
||||||
*********/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//void bdRandomNodeId(bdNodeId *id);
|
|
||||||
|
|
||||||
// Only Functions that are common for all Dhts.
|
|
||||||
// zero, basic comparisons..
|
|
||||||
void bdZeroNodeId(bdNodeId *id);
|
|
||||||
|
|
||||||
//void bdRandomId(bdId *id);
|
|
||||||
//int bdDistance(const bdNodeId *a, const bdNodeId *b, bdMetric *r);
|
|
||||||
//int bdBucketDistance(const bdMetric *m);
|
|
||||||
//int bdBucketDistance(const bdNodeId *a, const bdNodeId *b);
|
|
||||||
//int operator<(const bdMetric &a, const bdMetric &b);
|
|
||||||
|
|
||||||
//int operator<(const struct sockaddr_in &a, const struct sockaddr_in &b);
|
|
||||||
|
|
||||||
int operator<(const bdNodeId &a, const bdNodeId &b);
|
|
||||||
int operator<(const bdId &a, const bdId &b);
|
|
||||||
int operator==(const bdNodeId &a, const bdNodeId &b);
|
|
||||||
int operator==(const bdId &a, const bdId &b);
|
|
||||||
|
|
||||||
//void bdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *mid);
|
|
||||||
|
|
||||||
//void bdPrintId(std::ostream &out, const bdId *a);
|
|
||||||
//void bdPrintNodeId(std::ostream &out, const bdNodeId *a);
|
|
||||||
|
|
||||||
//std::string bdConvertToPrintable(std::string input);
|
|
||||||
|
|
||||||
/****
|
|
||||||
* DEFINED in bdiface.h
|
|
||||||
*
|
|
||||||
|
|
||||||
class bdPeer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdId mPeerId;
|
|
||||||
uint32_t mPeerFlags;
|
|
||||||
time_t mLastSendTime;
|
|
||||||
time_t mLastRecvTime;
|
|
||||||
time_t mFoundTime; // time stamp that peer was found
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class bdBucket
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdBucket();
|
|
||||||
|
|
||||||
// list so we can queue properly
|
|
||||||
std::list<bdPeer> entries;
|
|
||||||
};
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*****/
|
|
||||||
|
|
||||||
class bdSpace
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdSpace(bdNodeId *ownId, bdDhtFunctions *fns);
|
|
||||||
|
|
||||||
int clear();
|
|
||||||
|
|
||||||
int setAttachedFlag(uint32_t withflags, int count);
|
|
||||||
|
|
||||||
/* accessors */
|
|
||||||
int find_nearest_nodes(const bdNodeId *id, int number,
|
|
||||||
std::multimap<bdMetric, bdId> &nearest);
|
|
||||||
|
|
||||||
int find_nearest_nodes_with_flags(const bdNodeId *id, int number,
|
|
||||||
std::list<bdId> excluding,
|
|
||||||
std::multimap<bdMetric, bdId> &nearest, uint32_t with_flag);
|
|
||||||
|
|
||||||
int find_node(const bdNodeId *id, int number,
|
|
||||||
std::list<bdId> &matchIds, uint32_t with_flag);
|
|
||||||
int find_exactnode(const bdId *id, bdPeer &peer);
|
|
||||||
|
|
||||||
// switched to more efficient single sweep.
|
|
||||||
//int out_of_date_peer(bdId &id); // side-effect updates, send flag on peer.
|
|
||||||
int scanOutOfDatePeers(std::list<bdId> &peerIds);
|
|
||||||
int updateAttachedPeers();
|
|
||||||
|
|
||||||
int add_peer(const bdId *id, uint32_t mode);
|
|
||||||
int printDHT();
|
|
||||||
int getDhtBucket(const int idx, bdBucket &bucket);
|
|
||||||
|
|
||||||
uint32_t calcNetworkSize();
|
|
||||||
uint32_t calcNetworkSizeWithFlag(uint32_t withFlag);
|
|
||||||
uint32_t calcNetworkSizeWithFlag_old(uint32_t withFlag);
|
|
||||||
uint32_t calcSpaceSize();
|
|
||||||
uint32_t calcSpaceSizeWithFlag(uint32_t withFlag);
|
|
||||||
|
|
||||||
/* special function to enable DHT localisation (i.e find peers from own network) */
|
|
||||||
bool findRandomPeerWithFlag(bdId &id, uint32_t withFlag);
|
|
||||||
|
|
||||||
/* strip out flags - to switch in/out of relay mode */
|
|
||||||
int clean_node_flags(uint32_t flags);
|
|
||||||
|
|
||||||
/* to add later */
|
|
||||||
int updateOwnId(bdNodeId *newOwnId);
|
|
||||||
|
|
||||||
/* flag peer */
|
|
||||||
bool flagpeer(const bdId *id, uint32_t flags, uint32_t ex_flags);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<bdBucket> buckets;
|
|
||||||
bdNodeId mOwnId;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
|
|
||||||
uint32_t mAttachedFlags;
|
|
||||||
uint32_t mAttachedCount;
|
|
||||||
time_t mAttachTS;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,157 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdquery.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2010 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_QUERY_H
|
|
||||||
#define BITDHT_QUERY_H
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
#include "bitdht/bdobj.h"
|
|
||||||
|
|
||||||
/* Query result flags are in bdiface.h */
|
|
||||||
|
|
||||||
#define BITDHT_MIN_QUERY_AGE 10
|
|
||||||
#define BITDHT_MAX_QUERY_AGE 300 /* Query Should take <1 minute, so 5 minutes sounds reasonable */
|
|
||||||
|
|
||||||
class bdQuery
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryFlags,
|
|
||||||
bdDhtFunctions *fns);
|
|
||||||
|
|
||||||
// get the answer.
|
|
||||||
bool result(std::list<bdId> &answer);
|
|
||||||
bool proxies(std::list<bdId> &answer);
|
|
||||||
bool potentialProxies(std::list<bdId> &answer);
|
|
||||||
|
|
||||||
// returning results get passed to all queries.
|
|
||||||
//void addNode(const bdId *id, int mode);
|
|
||||||
int nextQuery(bdId &id, bdNodeId &targetId);
|
|
||||||
int addPeer(const bdId *id, uint32_t mode);
|
|
||||||
int addPotentialPeer(const bdId *id, const bdId *src, uint32_t srcmode);
|
|
||||||
int printQuery();
|
|
||||||
|
|
||||||
// searching for
|
|
||||||
bdNodeId mId;
|
|
||||||
bdMetric mLimit;
|
|
||||||
uint32_t mState;
|
|
||||||
time_t mQueryTS;
|
|
||||||
uint32_t mQueryFlags;
|
|
||||||
int32_t mSearchTime;
|
|
||||||
|
|
||||||
int32_t mQueryIdlePeerRetryPeriod; // seconds between retries.
|
|
||||||
|
|
||||||
//private:
|
|
||||||
|
|
||||||
// Closest Handling Fns.
|
|
||||||
int addClosestPeer(const bdId *id, uint32_t mode);
|
|
||||||
|
|
||||||
// Potential Handling Fns.
|
|
||||||
int worthyPotentialPeer(const bdId *id);
|
|
||||||
int updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType);
|
|
||||||
int trimPotentialPeers_FixedLength();
|
|
||||||
int trimPotentialPeers_toClosest();
|
|
||||||
int removeOldPotentialPeers();
|
|
||||||
|
|
||||||
// Proxy Handling Fns.
|
|
||||||
int addProxy(const bdId *id, const bdId *src, uint32_t srcmode);
|
|
||||||
int updateProxy(const bdId *id, uint32_t mode);
|
|
||||||
int updateProxyList(const bdId *id, uint32_t mode, std::list<bdPeer> &searchProxyList);
|
|
||||||
int trimProxies();
|
|
||||||
|
|
||||||
|
|
||||||
// closest peers.
|
|
||||||
std::multimap<bdMetric, bdPeer> mClosest;
|
|
||||||
std::multimap<bdMetric, bdPeer> mPotentialPeers;
|
|
||||||
time_t mPotPeerCleanTS; // periodic cleanup of PotentialPeers.
|
|
||||||
|
|
||||||
uint32_t mRequiredPeerFlags;
|
|
||||||
std::list<bdPeer> mProxiesUnknown;
|
|
||||||
std::list<bdPeer> mProxiesFlagged;
|
|
||||||
|
|
||||||
int mClosestListSize;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
class bdQueryStatus
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
uint32_t mStatus;
|
|
||||||
uint32_t mQFlags;
|
|
||||||
std::list<bdId> mResults;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* this is just a container class.
|
|
||||||
* we locally seach for this, once then discard.
|
|
||||||
*/
|
|
||||||
class bdRemoteQuery
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdRemoteQuery(bdId *id, bdNodeId *query, bdToken *transId, uint32_t query_type);
|
|
||||||
|
|
||||||
bdId mId;
|
|
||||||
bdNodeId mQuery;
|
|
||||||
bdToken mTransId;
|
|
||||||
uint32_t mQueryType;
|
|
||||||
|
|
||||||
time_t mQueryTS;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class bdQueryHistoryList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdQueryHistoryList();
|
|
||||||
|
|
||||||
bool addIncomingQuery(time_t recvd, const bdNodeId *aboutId); // calcs and returns mBadPeer
|
|
||||||
bool cleanupMsgs(time_t before); // returns true if empty.
|
|
||||||
|
|
||||||
bool mBadPeer;
|
|
||||||
std::multimap<time_t, bdNodeId> mList;
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdQueryHistory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdQueryHistory();
|
|
||||||
|
|
||||||
bool addIncomingQuery(time_t recvd, const bdId *id, const bdNodeId *aboutId);
|
|
||||||
void printMsgs();
|
|
||||||
|
|
||||||
void cleanupOldMsgs();
|
|
||||||
|
|
||||||
bool isBadPeer(const bdId *id);
|
|
||||||
|
|
||||||
int mStorePeriod;
|
|
||||||
std::map<bdId, bdQueryHistoryList> mHistory;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,379 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdquerymgr.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdquerymgr.h"
|
|
||||||
#include "bitdht/bdnode.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_QUERY_START_PEERS 10
|
|
||||||
#define BITDHT_QUERY_NEIGHBOUR_PEERS 8
|
|
||||||
#define BITDHT_MAX_REMOTE_QUERY_AGE 10
|
|
||||||
|
|
||||||
/****
|
|
||||||
* #define DEBUG_NODE_MULTIPEER 1
|
|
||||||
* #define DEBUG_NODE_MSGS 1
|
|
||||||
* #define DEBUG_NODE_ACTIONS 1
|
|
||||||
|
|
||||||
* #define DEBUG_NODE_MSGIN 1
|
|
||||||
* #define DEBUG_NODE_MSGOUT 1
|
|
||||||
***/
|
|
||||||
|
|
||||||
//#define DEBUG_NODE_MSGS 1
|
|
||||||
|
|
||||||
|
|
||||||
bdQueryManager::bdQueryManager(bdSpace *space, bdDhtFunctions *fns, bdNodePublisher *pub)
|
|
||||||
:mNodeSpace(space), mFns(fns), mPub(pub)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Startup / Shutdown ******/
|
|
||||||
void bdQueryManager::shutdownQueries()
|
|
||||||
{
|
|
||||||
/* clear the queries */
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end();it++)
|
|
||||||
{
|
|
||||||
delete (*it);
|
|
||||||
}
|
|
||||||
|
|
||||||
mLocalQueries.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdQueryManager::printQueries()
|
|
||||||
{
|
|
||||||
std::cerr << "bdQueryManager::printQueries()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++, i++)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Query #%d:\n", i);
|
|
||||||
(*it)->printQuery();
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int bdQueryManager::iterateQueries(int maxQueries)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_NODE_MULTIPEER
|
|
||||||
std::cerr << "bdQueryManager::iterateQueries() of Peer: ";
|
|
||||||
mFns->bdPrintNodeId(std::cerr, &mOwnId);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* allow each query to send up to one query... until maxMsgs has been reached */
|
|
||||||
int numQueries = mLocalQueries.size();
|
|
||||||
int sentQueries = 0;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
bdId id;
|
|
||||||
bdNodeId targetNodeId;
|
|
||||||
|
|
||||||
while((i < numQueries) && (sentQueries < maxQueries))
|
|
||||||
{
|
|
||||||
bdQuery *query = mLocalQueries.front();
|
|
||||||
mLocalQueries.pop_front();
|
|
||||||
mLocalQueries.push_back(query);
|
|
||||||
|
|
||||||
/* go through the possible queries */
|
|
||||||
if (query->nextQuery(id, targetNodeId))
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_NODE_MSGS
|
|
||||||
std::cerr << "bdQueryManager::iteration() send_query(";
|
|
||||||
mFns->bdPrintId(std::cerr, &id);
|
|
||||||
std::cerr << ",";
|
|
||||||
mFns->bdPrintNodeId(std::cerr, &targetNodeId);
|
|
||||||
std::cerr << ")";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
mPub->send_query(&id, &targetNodeId, false);
|
|
||||||
sentQueries++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
std::cerr << "bdQueryManager::iteration() maxMsgs: " << maxMsgs << " sentPings: " << sentPings;
|
|
||||||
std::cerr << " / " << allowedPings;
|
|
||||||
std::cerr << " sentQueries: " << sentQueries;
|
|
||||||
std::cerr << " / " << numQueries;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//printQueries();
|
|
||||||
|
|
||||||
return sentQueries;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdQueryManager::checkPotentialPeer(bdId *id, bdId *src)
|
|
||||||
{
|
|
||||||
bool isWorthyPeer = false;
|
|
||||||
/* also push to queries */
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->addPotentialPeer(id, src, 0))
|
|
||||||
{
|
|
||||||
isWorthyPeer = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isWorthyPeer)
|
|
||||||
{
|
|
||||||
isWorthyPeer = checkWorthyPeerSources(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isWorthyPeer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdQueryManager::addPeer(const bdId *id, uint32_t peerflags)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
fprintf(stderr, "bdQueryManager::addPeer(");
|
|
||||||
mFns->bdPrintId(std::cerr, id);
|
|
||||||
fprintf(stderr, ")\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* iterate through queries */
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
|
||||||
{
|
|
||||||
(*it)->addPeer(id, peerflags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/************************************ Query Details *************************/
|
|
||||||
void bdQueryManager::addQuery(const bdNodeId *id, uint32_t qflags)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::list<bdId> startList;
|
|
||||||
std::multimap<bdMetric, bdId> nearest;
|
|
||||||
std::multimap<bdMetric, bdId>::iterator it;
|
|
||||||
|
|
||||||
mNodeSpace->find_nearest_nodes(id, BITDHT_QUERY_START_PEERS, nearest);
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
fprintf(stderr, "bdQueryManager::addQuery(");
|
|
||||||
mFns->bdPrintNodeId(std::cerr, id);
|
|
||||||
fprintf(stderr, ")\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(it = nearest.begin(); it != nearest.end(); it++)
|
|
||||||
{
|
|
||||||
startList.push_back(it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
bdQuery *query = new bdQuery(id, startList, qflags, mFns);
|
|
||||||
mLocalQueries.push_back(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdQueryManager::clearQuery(const bdNodeId *rmId)
|
|
||||||
{
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end();)
|
|
||||||
{
|
|
||||||
if ((*it)->mId == *rmId)
|
|
||||||
{
|
|
||||||
bdQuery *query = (*it);
|
|
||||||
it = mLocalQueries.erase(it);
|
|
||||||
delete query;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdQueryManager::QueryStatus(std::map<bdNodeId, bdQueryStatus> &statusMap)
|
|
||||||
{
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
|
||||||
{
|
|
||||||
bdQueryStatus status;
|
|
||||||
status.mStatus = (*it)->mState;
|
|
||||||
status.mQFlags = (*it)->mQueryFlags;
|
|
||||||
(*it)->result(status.mResults);
|
|
||||||
statusMap[(*it)->mId] = status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdQueryManager::QuerySummary(const bdNodeId *id, bdQuerySummary &query)
|
|
||||||
{
|
|
||||||
std::list<bdQuery *>::iterator it;
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->mId == *id)
|
|
||||||
{
|
|
||||||
query.mId = (*it)->mId;
|
|
||||||
query.mLimit = (*it)->mLimit;
|
|
||||||
query.mState = (*it)->mState;
|
|
||||||
query.mQueryTS = (*it)->mQueryTS;
|
|
||||||
query.mQueryFlags = (*it)->mQueryFlags;
|
|
||||||
query.mSearchTime = (*it)->mSearchTime;
|
|
||||||
query.mClosest = (*it)->mClosest;
|
|
||||||
query.mPotentialPeers = (*it)->mPotentialPeers;
|
|
||||||
query.mProxiesUnknown = (*it)->mProxiesUnknown;
|
|
||||||
query.mProxiesFlagged = (*it)->mProxiesFlagged;
|
|
||||||
query.mQueryIdlePeerRetryPeriod = (*it)->mQueryIdlePeerRetryPeriod;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Extract Results from Peer Queries */
|
|
||||||
|
|
||||||
#define BDQRYMGR_RESULTS 1
|
|
||||||
#define BDQRYMGR_PROXIES 2
|
|
||||||
#define BDQRYMGR_POTPROXIES 3
|
|
||||||
|
|
||||||
int bdQueryManager::getResults(bdNodeId *target, std::list<bdId> &answer, int querytype)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* grab any peers from any existing query */
|
|
||||||
int results = 0;
|
|
||||||
std::list<bdQuery *>::iterator qit;
|
|
||||||
for(qit = mLocalQueries.begin(); qit != mLocalQueries.end(); qit++)
|
|
||||||
{
|
|
||||||
if (!((*qit)->mId == (*target)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_CONNECTION
|
|
||||||
std::cerr << "bdQueryManager::getResults() Found Matching Query";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
switch(querytype)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case BDQRYMGR_RESULTS:
|
|
||||||
results = (*qit)->result(answer);
|
|
||||||
break;
|
|
||||||
case BDQRYMGR_PROXIES:
|
|
||||||
results = (*qit)->proxies(answer);
|
|
||||||
break;
|
|
||||||
case BDQRYMGR_POTPROXIES:
|
|
||||||
results = (*qit)->potentialProxies(answer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* will only be one matching query.. so end loop */
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int bdQueryManager::result(bdNodeId *target, std::list<bdId> &answer)
|
|
||||||
{
|
|
||||||
return getResults(target, answer, BDQRYMGR_RESULTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdQueryManager::proxies(bdNodeId *target, std::list<bdId> &answer)
|
|
||||||
{
|
|
||||||
return getResults(target, answer, BDQRYMGR_PROXIES);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdQueryManager::potentialProxies(bdNodeId *target, std::list<bdId> &answer)
|
|
||||||
{
|
|
||||||
return getResults(target, answer, BDQRYMGR_POTPROXIES);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/************ WORTHY PEERS **********/
|
|
||||||
|
|
||||||
#define MAX_WORTHY_PEER_AGE 15
|
|
||||||
|
|
||||||
void bdQueryManager::addWorthyPeerSource(bdId *src)
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
bdPeer peer;
|
|
||||||
peer.mPeerId = *src;
|
|
||||||
peer.mFoundTime = now;
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
std::cerr << "bdQueryManager::addWorthyPeerSource(";
|
|
||||||
mFns->bdPrintId(std::cerr, src);
|
|
||||||
std::cerr << ")" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mWorthyPeerSources.push_back(peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdQueryManager::checkWorthyPeerSources(bdId *src)
|
|
||||||
{
|
|
||||||
if (!src)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
std::list<bdPeer>::iterator it;
|
|
||||||
for(it = mWorthyPeerSources.begin(); it != mWorthyPeerSources.end(); )
|
|
||||||
{
|
|
||||||
if (now - it->mFoundTime > MAX_WORTHY_PEER_AGE)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
std::cerr << "bdQueryManager::checkWorthyPeerSource() Discard old Source: ";
|
|
||||||
mFns->bdPrintId(std::cerr, &(it->mPeerId));
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
it = mWorthyPeerSources.erase(it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (it->mPeerId == *src)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
|
||||||
std::cerr << "bdQueryManager::checkWorthyPeerSource(";
|
|
||||||
mFns->bdPrintId(std::cerr, src);
|
|
||||||
std::cerr << ") = true" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdquerymgr.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_QUERY_MANAGER_H
|
|
||||||
#define BITDHT_QUERY_MANAGER_H
|
|
||||||
|
|
||||||
#include "bitdht/bdquery.h"
|
|
||||||
class bdNodePublisher;
|
|
||||||
|
|
||||||
|
|
||||||
class bdQueryManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdQueryManager(bdSpace *space, bdDhtFunctions *fns, bdNodePublisher *pub);
|
|
||||||
|
|
||||||
void shutdownQueries();
|
|
||||||
void printQueries();
|
|
||||||
|
|
||||||
int iterateQueries(int maxqueries);
|
|
||||||
|
|
||||||
bool checkPotentialPeer(bdId *id, bdId *src);
|
|
||||||
void addPeer(const bdId *id, uint32_t peerflags);
|
|
||||||
|
|
||||||
void addQuery(const bdNodeId *id, uint32_t qflags);
|
|
||||||
void clearQuery(const bdNodeId *id);
|
|
||||||
void QueryStatus(std::map<bdNodeId, bdQueryStatus> &statusMap);
|
|
||||||
int QuerySummary(const bdNodeId *id, bdQuerySummary &query);
|
|
||||||
|
|
||||||
int result(bdNodeId *target, std::list<bdId> &answer);
|
|
||||||
int proxies(bdNodeId *target, std::list<bdId> &answer);
|
|
||||||
int potentialProxies(bdNodeId *target, std::list<bdId> &answer);
|
|
||||||
|
|
||||||
// extra "Worthy Peers" we will want to ping.
|
|
||||||
void addWorthyPeerSource(bdId *src);
|
|
||||||
bool checkWorthyPeerSources(bdId *src);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int getResults(bdNodeId *target, std::list<bdId> &answer, int querytype);
|
|
||||||
|
|
||||||
/* NB: No Mutex Protection... Single threaded, Mutex at higher level!
|
|
||||||
*/
|
|
||||||
|
|
||||||
bdSpace *mNodeSpace;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
bdNodePublisher *mPub;
|
|
||||||
|
|
||||||
std::list<bdQuery *> mLocalQueries;
|
|
||||||
std::list<bdPeer> mWorthyPeerSources;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BITDHT_QUERY_MANAGER_H
|
|
|
@ -1,347 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdstddht.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdstddht.h"
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
#include "util/bdrandom.h"
|
|
||||||
#include "util/bdstring.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* #define BITDHT_DEBUG 1
|
|
||||||
**/
|
|
||||||
|
|
||||||
void bdStdRandomId(bdId *id)
|
|
||||||
{
|
|
||||||
bdStdRandomNodeId(&(id->id));
|
|
||||||
id->addr.sin_addr.s_addr = bdRandom::random_u32();
|
|
||||||
id->addr.sin_port = (bdRandom::random_u32() % USHRT_MAX);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdRandomNodeId(bdNodeId *id)
|
|
||||||
{
|
|
||||||
uint32_t *a_data = (uint32_t *) id->data;
|
|
||||||
for(int i = 0; i < BITDHT_KEY_INTLEN; i++)
|
|
||||||
{
|
|
||||||
a_data[i] = bdRandom::random_u32();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdZeroNodeId(bdNodeId *id)
|
|
||||||
{
|
|
||||||
uint32_t *a_data = (uint32_t *) id->data;
|
|
||||||
for(int i = 0; i < BITDHT_KEY_INTLEN; i++)
|
|
||||||
{
|
|
||||||
a_data[i] = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore differences in port....
|
|
||||||
// must be careful which one we accept after this.
|
|
||||||
// can could end-up with the wrong port.
|
|
||||||
// However this only matters with firewalled peers anyway.
|
|
||||||
// So not too serious.
|
|
||||||
bool bdStdSimilarId(const bdId *n1, const bdId *n2)
|
|
||||||
{
|
|
||||||
if (n1->id == n2->id)
|
|
||||||
{
|
|
||||||
if (n1->addr.sin_addr.s_addr == n2->addr.sin_addr.s_addr)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bdStdUpdateSimilarId(bdId *dest, const bdId *src)
|
|
||||||
{
|
|
||||||
/* only difference that's currently allowed */
|
|
||||||
if (dest->addr.sin_port == src->addr.sin_port)
|
|
||||||
{
|
|
||||||
/* no update required */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
dest->addr.sin_port = src->addr.sin_port;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* fills in bdNodeId r, with XOR of a and b */
|
|
||||||
int bdStdDistance(const bdNodeId *a, const bdNodeId *b, bdMetric *r)
|
|
||||||
{
|
|
||||||
uint8_t *a_data = (uint8_t *) a->data;
|
|
||||||
uint8_t *b_data = (uint8_t *) b->data;
|
|
||||||
uint8_t *ans = (uint8_t *) r->data;
|
|
||||||
for(int i = 0; i < BITDHT_KEY_LEN; i++)
|
|
||||||
{
|
|
||||||
*(ans++) = *(a_data++) ^ *(b_data++);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *midId)
|
|
||||||
{
|
|
||||||
bdMetric dist;
|
|
||||||
|
|
||||||
/* get distance between a & c */
|
|
||||||
bdStdDistance(target, other, &dist);
|
|
||||||
|
|
||||||
/* generate Random Id */
|
|
||||||
bdStdRandomNodeId(midId);
|
|
||||||
|
|
||||||
/* zero bits of Random Id until under 1/2 of distance
|
|
||||||
* done in bytes for ease... matches one extra byte than distance = 0
|
|
||||||
* -> hence wierd order of operations
|
|
||||||
*/
|
|
||||||
//bool done = false;
|
|
||||||
for(int i = 0; i < BITDHT_KEY_LEN; i++)
|
|
||||||
{
|
|
||||||
midId->data[i] = target->data[i];
|
|
||||||
|
|
||||||
if (dist.data[i] != 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStdLoadNodeId(bdNodeId *id, std::string input)
|
|
||||||
{
|
|
||||||
uint8_t *a_data = (uint8_t *) id->data;
|
|
||||||
uint32_t reqlen = BITDHT_KEY_LEN * 2;
|
|
||||||
if (input.size() < reqlen)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < BITDHT_KEY_LEN; i++)
|
|
||||||
{
|
|
||||||
char ch1 = input[2 * i];
|
|
||||||
char ch2 = input[2 * i + 1];
|
|
||||||
uint8_t value1 = 0;
|
|
||||||
uint8_t value2 = 0;
|
|
||||||
|
|
||||||
/* do char1 */
|
|
||||||
if (ch1 >= '0' && ch1 <= '9')
|
|
||||||
value1 = (ch1 - '0');
|
|
||||||
else if (ch1 >= 'A' && ch1 <= 'F')
|
|
||||||
value1 = (ch1 - 'A' + 10);
|
|
||||||
else if (ch1 >= 'a' && ch1 <= 'f')
|
|
||||||
value1 = (ch1 - 'a' + 10);
|
|
||||||
|
|
||||||
/* do char2 */
|
|
||||||
if (ch2 >= '0' && ch2 <= '9')
|
|
||||||
value2 = (ch2 - '0');
|
|
||||||
else if (ch2 >= 'A' && ch2 <= 'F')
|
|
||||||
value2 = (ch2 - 'A' + 10);
|
|
||||||
else if (ch2 >= 'a' && ch2 <= 'f')
|
|
||||||
value2 = (ch2 - 'a' + 10);
|
|
||||||
|
|
||||||
a_data[i] = (value1 << 4) + value2;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string bdStdConvertToPrintable(std::string input)
|
|
||||||
{
|
|
||||||
std::string out;
|
|
||||||
for(uint32_t i = 0; i < input.length(); i++)
|
|
||||||
{
|
|
||||||
/* sensible chars */
|
|
||||||
if ((input[i] > 31) && (input[i] < 127))
|
|
||||||
{
|
|
||||||
out += input[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bd_sprintf_append(out, "[0x%x]", (uint32_t) input[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdPrintNodeId(std::ostream &out, const bdNodeId *a)
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
bdStdPrintNodeId(s, a, true);
|
|
||||||
out << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdPrintNodeId(std::string &out, const bdNodeId *a, bool append)
|
|
||||||
{
|
|
||||||
if (!append)
|
|
||||||
{
|
|
||||||
out.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < BITDHT_KEY_LEN; i++)
|
|
||||||
{
|
|
||||||
bd_sprintf_append(out, "%02x", (uint32_t) (a->data)[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdPrintId(std::ostream &out, const bdId *a)
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
bdStdPrintId(s, a, false);
|
|
||||||
out << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdPrintId(std::string &out, const bdId *a, bool append)
|
|
||||||
{
|
|
||||||
bdStdPrintNodeId(out, &(a->id), append);
|
|
||||||
bd_sprintf_append(out, " ip:%s:%u", bdnet_inet_ntoa(a->addr.sin_addr).c_str(), ntohs(a->addr.sin_port));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns 0-160 depending on bucket */
|
|
||||||
int bdStdBucketDistance(const bdNodeId *a, const bdNodeId *b)
|
|
||||||
{
|
|
||||||
bdMetric m;
|
|
||||||
bdStdDistance(a, b, &m);
|
|
||||||
return bdStdBucketDistance(&m);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns 0-160 depending on bucket */
|
|
||||||
int bdStdBucketDistance(const bdMetric *m)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < BITDHT_KEY_BITLEN; i++)
|
|
||||||
{
|
|
||||||
int bit = BITDHT_KEY_BITLEN - i - 1;
|
|
||||||
int byte = i / 8;
|
|
||||||
int bbit = 7 - (i % 8);
|
|
||||||
unsigned char comp = (1 << bbit);
|
|
||||||
|
|
||||||
#ifdef BITDHT_DEBUG
|
|
||||||
fprintf(stderr, "bdStdBucketDistance: bit:%d byte:%d bbit:%d comp:%x, data:%x\n", bit, byte, bbit, comp, m->data[byte]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (comp & m->data[byte])
|
|
||||||
{
|
|
||||||
return bit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bdStdDht::bdStdDht()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* setup variables */
|
|
||||||
uint16_t bdStdDht::bdNumBuckets()
|
|
||||||
{
|
|
||||||
|
|
||||||
return BITDHT_STANDARD_N_BUCKETS;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t bdStdDht::bdNodesPerBucket() /* used for bdspace */
|
|
||||||
{
|
|
||||||
return BITDHT_STANDARD_BUCKET_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t bdStdDht::bdNumQueryNodes() /* used for queries */
|
|
||||||
{
|
|
||||||
return BITDHT_STANDARD_BUCKET_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t bdStdDht::bdBucketBitSize()
|
|
||||||
{
|
|
||||||
return BITDHT_STANDARD_BUCKET_SIZE_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStdDht::bdDistance(const bdNodeId *n1, const bdNodeId *n2, class bdMetric *metric)
|
|
||||||
{
|
|
||||||
return bdStdDistance(n1, n2, metric);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStdDht::bdBucketDistance(const bdNodeId *n1, const bdNodeId *n2)
|
|
||||||
{
|
|
||||||
return bdStdBucketDistance(n1, n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStdDht::bdBucketDistance(const bdMetric *metric)
|
|
||||||
{
|
|
||||||
return bdStdBucketDistance(metric);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdStdDht::bdSimilarId(const bdId *id1, const bdId *id2)
|
|
||||||
{
|
|
||||||
return bdStdSimilarId(id1, id2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool bdStdDht::bdUpdateSimilarId(bdId *dest, const bdId *src)
|
|
||||||
{
|
|
||||||
return bdStdUpdateSimilarId(dest, src);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdStdDht::bdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *mid)
|
|
||||||
{
|
|
||||||
return bdStdRandomMidId(target, other, mid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void bdStdDht::bdPrintId(std::ostream &out, const bdId *a)
|
|
||||||
{
|
|
||||||
return bdStdPrintId(out, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStdDht::bdPrintNodeId(std::ostream &out, const bdNodeId *a)
|
|
||||||
{
|
|
||||||
return bdStdPrintNodeId(out, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************/
|
|
||||||
|
|
||||||
bdModDht::bdModDht()
|
|
||||||
:mNodesPerBucket(BITDHT_STANDARD_BUCKET_SIZE)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdModDht::setNodesPerBucket(uint16_t nodesPerBucket)
|
|
||||||
{
|
|
||||||
mNodesPerBucket = nodesPerBucket;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t bdModDht::bdNodesPerBucket() /* used for bdspace */
|
|
||||||
{
|
|
||||||
return mNodesPerBucket;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdstddht.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_STANDARD_DHT_H
|
|
||||||
#define BITDHT_STANDARD_DHT_H
|
|
||||||
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
|
|
||||||
#define BITDHT_STANDARD_BUCKET_SIZE 10 // 20 too many per query?
|
|
||||||
#define BITDHT_STANDARD_BUCKET_SIZE_BITS 5
|
|
||||||
|
|
||||||
#define BITDHT_STANDARD_N_BUCKETS BITDHT_KEY_BITLEN
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void bdStdRandomNodeId(bdNodeId *id);
|
|
||||||
void bdStdZeroNodeId(bdNodeId *id);
|
|
||||||
|
|
||||||
void bdStdRandomId(bdId *id);
|
|
||||||
int bdStdDistance(const bdNodeId *a, const bdNodeId *b, bdMetric *r);
|
|
||||||
int bdStdBucketDistance(const bdMetric *m);
|
|
||||||
int bdStdBucketDistance(const bdNodeId *a, const bdNodeId *b);
|
|
||||||
|
|
||||||
void bdStdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *mid);
|
|
||||||
|
|
||||||
int bdStdLoadNodeId(bdNodeId *id, std::string input);
|
|
||||||
|
|
||||||
void bdStdPrintId(std::ostream &out, const bdId *a);
|
|
||||||
void bdStdPrintId(std::string &out, const bdId *a, bool append);
|
|
||||||
void bdStdPrintNodeId(std::ostream &out, const bdNodeId *a);
|
|
||||||
void bdStdPrintNodeId(std::string &out, const bdNodeId *a, bool append);
|
|
||||||
|
|
||||||
std::string bdStdConvertToPrintable(std::string input);
|
|
||||||
|
|
||||||
//uint32_t bdStdSimilarNode(const bdId*, const bdId*);
|
|
||||||
|
|
||||||
|
|
||||||
class bdStdDht: public bdDhtFunctions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdStdDht();
|
|
||||||
/* setup variables */
|
|
||||||
virtual uint16_t bdNumBuckets();
|
|
||||||
virtual uint16_t bdNodesPerBucket(); /* used for bdspace */
|
|
||||||
virtual uint16_t bdNumQueryNodes(); /* used for queries */
|
|
||||||
virtual uint16_t bdBucketBitSize();
|
|
||||||
|
|
||||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric);
|
|
||||||
virtual int bdBucketDistance(const bdNodeId *n1, const bdNodeId *n2);
|
|
||||||
virtual int bdBucketDistance(const bdMetric *metric);
|
|
||||||
|
|
||||||
virtual bool bdSimilarId(const bdId *id1, const bdId *id2);
|
|
||||||
virtual bool bdUpdateSimilarId(bdId *dest, const bdId *src); /* returns true if update was necessary */
|
|
||||||
|
|
||||||
virtual void bdRandomMidId(const bdNodeId *target, const bdNodeId *other, bdNodeId *mid);
|
|
||||||
|
|
||||||
virtual void bdPrintId(std::ostream &out, const bdId *a);
|
|
||||||
virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class bdModDht: public bdStdDht
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bdModDht();
|
|
||||||
virtual void setNodesPerBucket(uint16_t nodesPerBucket);
|
|
||||||
virtual uint16_t bdNodesPerBucket(); /* used for bdspace */
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16_t mNodesPerBucket;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,269 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdstore.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#include "bitdht/bdstore.h"
|
|
||||||
#include "util/bdnet.h"
|
|
||||||
#include "util/bdfile.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
//#define DEBUG_STORE 1
|
|
||||||
|
|
||||||
bdStore::bdStore(std::string file, std::string backupfile, bdDhtFunctions *fns)
|
|
||||||
:mFns(fns)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
std::cerr << "bdStore::bdStore(" << file << ")";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* read data from file */
|
|
||||||
mStoreFile = file;
|
|
||||||
mStoreFileBak = backupfile;
|
|
||||||
|
|
||||||
reloadFromStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStore::clear()
|
|
||||||
{
|
|
||||||
mIndex = 0;
|
|
||||||
store.clear();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStore::reloadFromStore()
|
|
||||||
{
|
|
||||||
int result = reloadFromStore(mStoreFile);
|
|
||||||
if( result != 0 && store.size() > 0){
|
|
||||||
return result;
|
|
||||||
} else if(mStoreFileBak != "") { //Nothing loaded, try the backup file
|
|
||||||
return reloadFromStore(mStoreFileBak);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStore::reloadFromStore(std::string file)
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
|
|
||||||
FILE *fd = fopen(file.c_str(), "r");
|
|
||||||
if (!fd)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to Open File: %s ... No Peers\n", file.c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char line[10240];
|
|
||||||
char addr_str[10240];
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
addr.sin_family = PF_INET;
|
|
||||||
unsigned short port;
|
|
||||||
|
|
||||||
while(line == fgets(line, 10240, fd))
|
|
||||||
{
|
|
||||||
if (2 == sscanf(line, "%s %hd", addr_str, &port))
|
|
||||||
{
|
|
||||||
if (bdnet_inet_aton(addr_str, &(addr.sin_addr)))
|
|
||||||
{
|
|
||||||
addr.sin_port = htons(port);
|
|
||||||
bdPeer peer;
|
|
||||||
bdZeroNodeId(&(peer.mPeerId.id));
|
|
||||||
peer.mPeerId.addr = addr;
|
|
||||||
peer.mLastSendTime = 0;
|
|
||||||
peer.mLastRecvTime = 0;
|
|
||||||
store.push_back(peer);
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "Read: %s %d\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "Read %ld Peers\n", (long) store.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a very ugly function!
|
|
||||||
int bdStore::getPeer(bdPeer *peer)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "bdStore::getPeer() %ld Peers left\n", (long) store.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::list<bdPeer>::iterator it;
|
|
||||||
int i = 0;
|
|
||||||
for(it = store.begin(); (it != store.end()) && (i < mIndex); it++, i++) ; /* empty loop */
|
|
||||||
if (it != store.end())
|
|
||||||
{
|
|
||||||
*peer = *it;
|
|
||||||
mIndex++;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bdStore::filterIpList(const std::list<struct sockaddr_in> &filteredIPs)
|
|
||||||
{
|
|
||||||
// Nasty O(n^2) iteration over 500 entries!!!.
|
|
||||||
// hope its not used to often.
|
|
||||||
|
|
||||||
std::list<struct sockaddr_in>::const_iterator it;
|
|
||||||
for(it = filteredIPs.begin(); it != filteredIPs.end(); it++)
|
|
||||||
{
|
|
||||||
std::list<bdPeer>::iterator sit;
|
|
||||||
for(sit = store.begin(); sit != store.end();)
|
|
||||||
{
|
|
||||||
if (it->sin_addr.s_addr == sit->mPeerId.addr.sin_addr.s_addr)
|
|
||||||
{
|
|
||||||
std::cerr << "bdStore::filterIpList() Found Bad entry in Store. Erasing!";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
sit = store.erase(sit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sit++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_ENTRIES 500
|
|
||||||
|
|
||||||
/* maintain a sorted list */
|
|
||||||
void bdStore::addStore(bdPeer *peer)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
std::cerr << "bdStore::addStore() ";
|
|
||||||
mFns->bdPrintId(std::cerr, &(peer->mPeerId));
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* remove old entry */
|
|
||||||
|
|
||||||
std::list<bdPeer>::iterator it;
|
|
||||||
for(it = store.begin(); it != store.end(); )
|
|
||||||
{
|
|
||||||
if ((it->mPeerId.addr.sin_addr.s_addr == peer->mPeerId.addr.sin_addr.s_addr) &&
|
|
||||||
(it->mPeerId.addr.sin_port == peer->mPeerId.addr.sin_port))
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
std::cerr << "bdStore::addStore() Removed Existing Entry: ";
|
|
||||||
mFns->bdPrintId(std::cerr, &(it->mPeerId));
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
it = store.erase(it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
std::cerr << "bdStore::addStore() Push_back";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
store.push_back(*peer);
|
|
||||||
|
|
||||||
while(store.size() > MAX_ENTRIES)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
std::cerr << "bdStore::addStore() pop_front()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
store.pop_front();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStore::writeStore(std::string file)
|
|
||||||
{
|
|
||||||
/* write out store */
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "bdStore::writeStore(%s) = %d entries\n", file.c_str(), store.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (store.size() < 0.9 * MAX_ENTRIES)
|
|
||||||
{
|
|
||||||
/* don't save yet! */
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "bdStore::writeStore() Delaying until more entries\n");
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string filetmp = file + ".tmp" ;
|
|
||||||
|
|
||||||
FILE *fd = fopen(filetmp.c_str(), "w");
|
|
||||||
|
|
||||||
if (!fd)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "bdStore::writeStore() FAILED to Open File\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<bdPeer>::iterator it;
|
|
||||||
for(it = store.begin(); it != store.end(); it++)
|
|
||||||
{
|
|
||||||
fprintf(fd, "%s %d\n", bdnet_inet_ntoa(it->mPeerId.addr.sin_addr).c_str(), ntohs(it->mPeerId.addr.sin_port));
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
fprintf(stderr, "Storing Peer Address: %s %d\n", inet_ntoa(it->mPeerId.addr.sin_addr), ntohs(it->mPeerId.addr.sin_port));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
if(!bdFile::renameFile(filetmp,file))
|
|
||||||
std::cerr << "Could not rename file !!" << std::endl;
|
|
||||||
#ifdef DEBUG_STORE
|
|
||||||
else
|
|
||||||
std::cerr << "Successfully renamed file " << filetmp << " to " << file << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void bdStore::writeStore()
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
if (mStoreFile == "")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return writeStore(mStoreFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdstore.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef BITDHT_STORE_H
|
|
||||||
#define BITDHT_STORE_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "bitdht/bdiface.h"
|
|
||||||
#include "bitdht/bdpeer.h"
|
|
||||||
|
|
||||||
class bdStore
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bdStore(std::string file, std::string backupfile, bdDhtFunctions *fns);
|
|
||||||
|
|
||||||
int reloadFromStore(); /* for restarts */
|
|
||||||
int reloadFromStore(std::string file);
|
|
||||||
int filterIpList(const std::list<struct sockaddr_in> &filteredIPs);
|
|
||||||
int clear();
|
|
||||||
|
|
||||||
int getPeer(bdPeer *peer);
|
|
||||||
void addStore(bdPeer *peer);
|
|
||||||
void writeStore(std::string file);
|
|
||||||
void writeStore();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::string mStoreFile;
|
|
||||||
std::string mStoreFileBak;
|
|
||||||
std::list<bdPeer> store;
|
|
||||||
int mIndex;
|
|
||||||
bdDhtFunctions *mFns;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,649 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdencode.cc *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* by Mike Frysinger <vapier@gmail.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This implementation isn't optimized at all as I wrote it to support
|
|
||||||
* a bogus system. I have no real interest in this format. Feel free
|
|
||||||
* to send me patches (so long as you don't copyright them and you release
|
|
||||||
* your changes into the public domain as well).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h> /* malloc() realloc() free() strtoll() */
|
|
||||||
#include <string.h> /* memset() */
|
|
||||||
#include "util/bdstring.h"
|
|
||||||
|
|
||||||
#include "bitdht/bencode.h"
|
|
||||||
|
|
||||||
/***
|
|
||||||
* #define BE_DEBUG_DECODE 1
|
|
||||||
* #define BE_DEBUG 1 // controlled from Makefile too.
|
|
||||||
***/
|
|
||||||
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
#include <stdio.h> /* debug */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static be_node *be_alloc(be_type type)
|
|
||||||
{
|
|
||||||
be_node *ret = (be_node *) malloc(sizeof(*ret));
|
|
||||||
if (ret) {
|
|
||||||
memset(ret, 0x00, sizeof(*ret));
|
|
||||||
ret->type = type;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static long long _be_decode_int(const char **data, long long *data_len)
|
|
||||||
{
|
|
||||||
char *endp;
|
|
||||||
long long ret = strtoll(*data, &endp, 10);
|
|
||||||
*data_len -= (endp - *data);
|
|
||||||
*data = endp;
|
|
||||||
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_int(pnt: %p, rem: %lld) = %lld\n", *data, *data_len, ret);
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
long long be_str_len(be_node *node)
|
|
||||||
{
|
|
||||||
long long ret = 0;
|
|
||||||
if (node->val.s)
|
|
||||||
memcpy(&ret, node->val.s - sizeof(ret), sizeof(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *_be_decode_str(const char **data, long long *data_len)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str(pnt: %p, rem: %lld)\n", *data, *data_len);
|
|
||||||
#endif
|
|
||||||
long long sllen = _be_decode_int(data, data_len);
|
|
||||||
long slen = sllen;
|
|
||||||
unsigned long len;
|
|
||||||
char *ret = NULL;
|
|
||||||
|
|
||||||
/* slen is signed, so negative values get rejected */
|
|
||||||
if (sllen < 0)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str() reject bad length\n");
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reject attempts to allocate large values that overflow the
|
|
||||||
* size_t type which is used with malloc()
|
|
||||||
*/
|
|
||||||
if (sizeof(long long) != sizeof(long))
|
|
||||||
if (sllen != slen)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str() reject large_values\n");
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* make sure we have enough data left */
|
|
||||||
if (sllen > *data_len - 1)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str() reject large_values\n");
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* switch from signed to unsigned so we don't overflow below */
|
|
||||||
len = slen;
|
|
||||||
|
|
||||||
if (**data == ':') {
|
|
||||||
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
|
|
||||||
|
|
||||||
if(_ret == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "(EE) bencode::_be_decode_str(): "
|
|
||||||
"ERROR. cannot allocate memory for %lu bytes.\n"
|
|
||||||
, len+1+sizeof(sllen) );
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(_ret, &sllen, sizeof(sllen));
|
|
||||||
ret = _ret + sizeof(sllen);
|
|
||||||
memcpy(ret, *data + 1, len);
|
|
||||||
ret[len] = '\0';
|
|
||||||
*data += len + 1;
|
|
||||||
*data_len -= len + 1;
|
|
||||||
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str() read %ld bytes\n", len+1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode_str() reject missing :\n");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static be_node *_be_decode(const char **data, long long *data_len)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode(pnt: %p, rem: %lld)\n", *data, *data_len);
|
|
||||||
#endif
|
|
||||||
be_node *ret = NULL;
|
|
||||||
|
|
||||||
if (!*data_len)
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() reject invalid datalen\n");
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (**data) {
|
|
||||||
/* lists */
|
|
||||||
case 'l': {
|
|
||||||
unsigned int i = 0;
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() found list\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = be_alloc(BE_LIST);
|
|
||||||
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
while (**data != 'e') {
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() list get item (%d)\n", i);
|
|
||||||
#endif
|
|
||||||
ret->val.l = (be_node **) realloc(ret->val.l, (i + 2) * sizeof(*ret->val.l));
|
|
||||||
ret->val.l[i] = _be_decode(data, data_len);
|
|
||||||
if (ret->val.l[i] == NULL)
|
|
||||||
{
|
|
||||||
/* failed decode - kill decode */
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() failed list decode - kill\n");
|
|
||||||
#endif
|
|
||||||
be_free(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
|
|
||||||
/* empty list case. */
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
ret->val.l = (be_node **) realloc(ret->val.l, 1 * sizeof(*ret->val.l));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->val.l[i] = NULL;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dictionaries */
|
|
||||||
case 'd': {
|
|
||||||
unsigned int i = 0;
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() found dictionary\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = be_alloc(BE_DICT);
|
|
||||||
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
while (**data != 'e') {
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() dictionary get key (%d)\n", i);
|
|
||||||
#endif
|
|
||||||
ret->val.d = (be_dict *) realloc(ret->val.d, (i + 2) * sizeof(*ret->val.d));
|
|
||||||
ret->val.d[i].key = _be_decode_str(data, data_len);
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() dictionary get val\n");
|
|
||||||
#endif
|
|
||||||
ret->val.d[i ].val = _be_decode(data, data_len);
|
|
||||||
ret->val.d[i+1].val = NULL ; // ensures termination of loops based on 0x0 value, otherwise, uninitialized
|
|
||||||
// memory occurs if(ret->val.d[i].key == 0x0 && ret->val.d[i].val != NULL)
|
|
||||||
// when calling be_free 8 lines below this point...
|
|
||||||
|
|
||||||
if ((ret->val.d[i].key == NULL) || (ret->val.d[i].val == NULL))
|
|
||||||
{
|
|
||||||
/* failed decode - kill decode */
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() failed dict decode - kill\n");
|
|
||||||
#endif
|
|
||||||
be_free(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
|
|
||||||
/* empty dictionary case. */
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
ret->val.d = (be_dict *) realloc(ret->val.d, 1 * sizeof(*ret->val.d));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ret->val.d[i].val = NULL;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* integers */
|
|
||||||
case 'i': {
|
|
||||||
ret = be_alloc(BE_INT);
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() found int\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
ret->val.i = _be_decode_int(data, data_len);
|
|
||||||
if (**data != 'e')
|
|
||||||
{
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() reject data != e - kill\n");
|
|
||||||
#endif
|
|
||||||
be_free(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
--(*data_len);
|
|
||||||
++(*data);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* byte strings */
|
|
||||||
case '0'...'9': {
|
|
||||||
ret = be_alloc(BE_STR);
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() found string\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret->val.s = _be_decode_str(data, data_len);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* invalid */
|
|
||||||
default:
|
|
||||||
#ifdef BE_DEBUG_DECODE
|
|
||||||
fprintf(stderr, "bencode::_be_decode() found invalid - kill\n");
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
be_node *be_decoden(const char *data, long long len)
|
|
||||||
{
|
|
||||||
return _be_decode(&data, &len);
|
|
||||||
}
|
|
||||||
|
|
||||||
be_node *be_decode(const char *data)
|
|
||||||
{
|
|
||||||
return be_decoden(data, strlen(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void _be_free_str(char *str)
|
|
||||||
{
|
|
||||||
if (str)
|
|
||||||
free(str - sizeof(long long));
|
|
||||||
}
|
|
||||||
void be_free(be_node *node)
|
|
||||||
{
|
|
||||||
switch (node->type) {
|
|
||||||
case BE_STR:
|
|
||||||
_be_free_str(node->val.s);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_INT:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_LIST: {
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; node->val.l[i]; ++i)
|
|
||||||
be_free(node->val.l[i]);
|
|
||||||
free(node->val.l);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BE_DICT: {
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; node->val.d[i].val; ++i) {
|
|
||||||
_be_free_str(node->val.d[i].key);
|
|
||||||
be_free(node->val.d[i].val);
|
|
||||||
}
|
|
||||||
free(node->val.d);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BE_DEBUG
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
static void _be_dump_indent(ssize_t indent)
|
|
||||||
{
|
|
||||||
while (indent-- > 0)
|
|
||||||
printf(" ");
|
|
||||||
}
|
|
||||||
static void _be_dump(be_node *node, ssize_t indent)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
_be_dump_indent(indent);
|
|
||||||
indent = abs(indent);
|
|
||||||
|
|
||||||
switch (node->type) {
|
|
||||||
case BE_STR:
|
|
||||||
be_dump_str(node);
|
|
||||||
//printf("str = %s (len = %lli)\n", node->val.s, be_str_len(node));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_INT:
|
|
||||||
printf("int = %lli\n", node->val.i);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_LIST:
|
|
||||||
puts("list [");
|
|
||||||
|
|
||||||
for (i = 0; node->val.l[i]; ++i)
|
|
||||||
_be_dump(node->val.l[i], indent + 1);
|
|
||||||
|
|
||||||
_be_dump_indent(indent);
|
|
||||||
puts("]");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_DICT:
|
|
||||||
puts("dict {");
|
|
||||||
|
|
||||||
for (i = 0; node->val.d[i].val; ++i) {
|
|
||||||
_be_dump_indent(indent + 1);
|
|
||||||
printf("%s => ", node->val.d[i].key);
|
|
||||||
_be_dump(node->val.d[i].val, -(indent + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
_be_dump_indent(indent);
|
|
||||||
puts("}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void be_dump(be_node *node)
|
|
||||||
{
|
|
||||||
_be_dump(node, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void be_dump_str(be_node *node)
|
|
||||||
{
|
|
||||||
if (node->type != BE_STR)
|
|
||||||
{
|
|
||||||
printf("be_dump_str(): error not a string\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int len = be_str_len(node);
|
|
||||||
int i = 0;
|
|
||||||
printf("str[%d] = ", len);
|
|
||||||
for(i = 0; i < len; i++)
|
|
||||||
{
|
|
||||||
/* sensible chars */
|
|
||||||
if ((node->val.s[i] > 31) && (node->val.s[i] < 127))
|
|
||||||
{
|
|
||||||
printf("%c", node->val.s[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("[%d]", node->val.s[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/******************** New Functions added by drBob *************
|
|
||||||
* Output bencode
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
int be_encode(be_node *node, char *str, int len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int loc = 0;
|
|
||||||
|
|
||||||
switch (node->type) {
|
|
||||||
case BE_STR:
|
|
||||||
bd_snprintf(str, len, "%lli:", be_str_len(node));
|
|
||||||
loc += strlen(&(str[loc]));
|
|
||||||
|
|
||||||
memcpy(&(str[loc]), node->val.s, be_str_len(node));
|
|
||||||
loc += be_str_len(node);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_INT:
|
|
||||||
bd_snprintf(str, len, "i%llie", node->val.i);
|
|
||||||
loc += strlen(&(str[loc]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_LIST:
|
|
||||||
|
|
||||||
snprintf(str, len, "l");
|
|
||||||
loc += 1;
|
|
||||||
|
|
||||||
for (i = 0; node->val.l[i]; ++i)
|
|
||||||
{
|
|
||||||
loc += be_encode(node->val.l[i], &(str[loc]), len-loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(&(str[loc]), len - loc, "e");
|
|
||||||
loc += 1;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BE_DICT:
|
|
||||||
snprintf(str, len, "d");
|
|
||||||
loc += 1;
|
|
||||||
|
|
||||||
for (i = 0; node->val.d[i].val; ++i) {
|
|
||||||
|
|
||||||
/* assumption that key must be ascii! */
|
|
||||||
snprintf(&(str[loc]), len-loc, "%i:%s",
|
|
||||||
(int) strlen(node->val.d[i].key),
|
|
||||||
node->val.d[i].key);
|
|
||||||
loc += strlen(&(str[loc]));
|
|
||||||
loc += be_encode(node->val.d[i].val, &(str[loc]), len-loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(&(str[loc]), len - loc, "e");
|
|
||||||
loc += 1;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* hackish way to create nodes! */
|
|
||||||
be_node *be_create_dict()
|
|
||||||
{
|
|
||||||
be_node *n = be_decode("de");
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
be_node *be_create_list()
|
|
||||||
{
|
|
||||||
be_node *n = be_decode("le");
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
be_node *be_create_str(const char *str)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* must */
|
|
||||||
be_node *n = NULL;
|
|
||||||
int len = strlen(str);
|
|
||||||
long long int sllen = len;
|
|
||||||
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
|
|
||||||
if(_ret == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "(EE) bencode::be_create_str(): "
|
|
||||||
"ERROR. cannot allocate memory for %lu bytes.\n"
|
|
||||||
, len+1+sizeof(sllen) );
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
char *ret = NULL;
|
|
||||||
n = be_alloc(BE_STR);
|
|
||||||
|
|
||||||
memcpy(_ret, &sllen, sizeof(sllen));
|
|
||||||
ret = _ret + sizeof(sllen);
|
|
||||||
memcpy(ret, str, len);
|
|
||||||
ret[len] = '\0';
|
|
||||||
|
|
||||||
n->val.s = ret;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
be_node *be_create_str_wlen(const char *str, int len) /* not including \0 */
|
|
||||||
{
|
|
||||||
|
|
||||||
/* must */
|
|
||||||
be_node *n = NULL;
|
|
||||||
long long int sllen = len;
|
|
||||||
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
|
|
||||||
if(_ret == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "(EE) bencode::be_create_str_wlen(): "
|
|
||||||
"ERROR. cannot allocate memory for %lu bytes.\n"
|
|
||||||
, len+1+sizeof(sllen) );
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
char *ret = NULL;
|
|
||||||
n = be_alloc(BE_STR);
|
|
||||||
|
|
||||||
memcpy(_ret, &sllen, sizeof(sllen));
|
|
||||||
ret = _ret + sizeof(sllen);
|
|
||||||
memcpy(ret, str, len);
|
|
||||||
ret[len] = '\0';
|
|
||||||
|
|
||||||
n->val.s = ret;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
be_node *be_create_int(long long int num)
|
|
||||||
{
|
|
||||||
/* must */
|
|
||||||
be_node *n = be_alloc(BE_INT);
|
|
||||||
n->val.i = num;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int be_add_keypair(be_node *dict, const char *str, be_node *node)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
/* only if dict type */
|
|
||||||
if (dict->type != BE_DICT)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get to end of dict.
|
|
||||||
for(i = 0; dict->val.d[i].val; i++)
|
|
||||||
;//Silent empty body for loop for clang
|
|
||||||
|
|
||||||
//fprintf(stderr, "be_add_keypair() i = %d\n",i);
|
|
||||||
|
|
||||||
/* realloc space */
|
|
||||||
dict->val.d = (be_dict *) realloc(dict->val.d, (i + 2) * sizeof(*dict->val.d));
|
|
||||||
|
|
||||||
/* stupid key storage system */
|
|
||||||
int len = strlen(str);
|
|
||||||
long long int sllen = len;
|
|
||||||
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
|
|
||||||
if(_ret == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "(EE) bencode::be_create_str_wlen(): "
|
|
||||||
"ERROR. cannot allocate memory for %lu bytes.\n"
|
|
||||||
, len+1+sizeof(sllen) );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char *ret = NULL;
|
|
||||||
|
|
||||||
//fprintf(stderr, "be_add_keypair() key len = %d\n",len);
|
|
||||||
|
|
||||||
memcpy(_ret, &sllen, sizeof(sllen));
|
|
||||||
ret = _ret + sizeof(sllen);
|
|
||||||
memcpy(ret, str, len);
|
|
||||||
ret[len] = '\0';
|
|
||||||
|
|
||||||
dict->val.d[i].key = ret;
|
|
||||||
dict->val.d[i].val = node;
|
|
||||||
i++;
|
|
||||||
dict->val.d[i].val = NULL;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int be_add_list(be_node *list, be_node *node)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
/* only if dict type */
|
|
||||||
if (list->type != BE_LIST)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get to end of dict.
|
|
||||||
for(i = 0; list->val.l[i]; i++)
|
|
||||||
;//Silent empty body for loop for clang
|
|
||||||
|
|
||||||
/* realloc space */
|
|
||||||
list->val.l = (be_node **) realloc(list->val.l, (i + 2) * sizeof(*list->val.l));
|
|
||||||
list->val.l[i] = node;
|
|
||||||
++i;
|
|
||||||
list->val.l[i] = NULL;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* bitdht/bdencode.h *
|
|
||||||
* *
|
|
||||||
* BitDHT: An Flexible DHT library. *
|
|
||||||
* *
|
|
||||||
* Copyright 2011 by Robert Fernie <bitdht@lunamutt.com> *
|
|
||||||
* by Mike Frysinger <vapier@gmail.com> *
|
|
||||||
* *
|
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Affero General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Affero General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Affero General Public License *
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
||||||
* *
|
|
||||||
*******************************************************************************/
|
|
||||||
#ifndef _BENCODE_H
|
|
||||||
#define _BENCODE_H
|
|
||||||
|
|
||||||
/* USAGE:
|
|
||||||
* - pass the string full of the bencoded data to be_decode()
|
|
||||||
* - parse the resulting tree however you like
|
|
||||||
* - call be_free() on the tree to release resources
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BE_STR,
|
|
||||||
BE_INT,
|
|
||||||
BE_LIST,
|
|
||||||
BE_DICT,
|
|
||||||
} be_type;
|
|
||||||
|
|
||||||
struct be_dict;
|
|
||||||
struct be_node;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXX: the "val" field of be_dict and be_node can be confusing ...
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct be_dict {
|
|
||||||
char *key;
|
|
||||||
struct be_node *val;
|
|
||||||
} be_dict;
|
|
||||||
|
|
||||||
typedef struct be_node {
|
|
||||||
be_type type;
|
|
||||||
union {
|
|
||||||
char *s;
|
|
||||||
long long i;
|
|
||||||
struct be_node **l;
|
|
||||||
struct be_dict *d;
|
|
||||||
} val;
|
|
||||||
} be_node;
|
|
||||||
|
|
||||||
extern long long be_str_len(be_node *node);
|
|
||||||
// This function uses strlen, so is unreliable.
|
|
||||||
//extern be_node *be_decode(const char *bencode);
|
|
||||||
extern be_node *be_decoden(const char *bencode, long long bencode_len);
|
|
||||||
extern void be_free(be_node *node);
|
|
||||||
extern void be_dump(be_node *node);
|
|
||||||
extern void be_dump_str(be_node *node);
|
|
||||||
|
|
||||||
// New Functions for the other half of the work - encoding */
|
|
||||||
|
|
||||||
extern int be_encode(be_node *node, char *str, int len);
|
|
||||||
|
|
||||||
|
|
||||||
// Creating the data structure.
|
|
||||||
extern int be_add_list(be_node *list, be_node *node);
|
|
||||||
extern int be_add_keypair(be_node *dict, const char *str, be_node *node);
|
|
||||||
extern be_node *be_create_int(long long int num);
|
|
||||||
extern be_node *be_create_list();
|
|
||||||
extern be_node *be_create_str(const char *str);
|
|
||||||
extern be_node *be_create_str_wlen(const char *str, int len); /* not including \0 */
|
|
||||||
extern be_node *be_create_dict();
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,500 +0,0 @@
|
||||||
77.196.18.56 22750
|
|
||||||
77.84.97.16 31837
|
|
||||||
213.174.60.46 17919
|
|
||||||
50.113.92.209 6881
|
|
||||||
184.89.243.73 43344
|
|
||||||
210.195.47.196 19861
|
|
||||||
83.49.197.212 61627
|
|
||||||
184.145.109.37 31067
|
|
||||||
180.18.98.235 29543
|
|
||||||
186.254.61.185 40200
|
|
||||||
78.213.113.102 9182
|
|
||||||
89.92.251.113 16946
|
|
||||||
195.240.45.224 6881
|
|
||||||
188.142.164.252 43063
|
|
||||||
41.45.41.123 18636
|
|
||||||
219.84.184.204 61337
|
|
||||||
95.26.91.94 6881
|
|
||||||
79.114.193.207 17966
|
|
||||||
83.213.185.157 43235
|
|
||||||
37.110.127.110 6881
|
|
||||||
178.35.204.111 6881
|
|
||||||
174.48.201.143 41918
|
|
||||||
109.214.57.82 1042
|
|
||||||
121.214.57.226 51413
|
|
||||||
90.184.93.164 22828
|
|
||||||
98.214.166.21 38072
|
|
||||||
50.0.146.178 51413
|
|
||||||
81.13.253.217 46370
|
|
||||||
81.249.29.121 7812
|
|
||||||
92.80.201.189 20026
|
|
||||||
95.37.18.51 59118
|
|
||||||
50.53.143.88 57568
|
|
||||||
180.183.213.112 11823
|
|
||||||
112.206.13.117 41825
|
|
||||||
79.169.77.54 63189
|
|
||||||
76.174.205.156 8605
|
|
||||||
2.1.187.15 50269
|
|
||||||
175.151.131.80 16001
|
|
||||||
82.7.124.219 12334
|
|
||||||
217.209.125.15 26155
|
|
||||||
93.181.201.89 54631
|
|
||||||
197.87.68.102 25317
|
|
||||||
183.109.112.49 58359
|
|
||||||
203.198.141.201 7453
|
|
||||||
82.192.32.151 58864
|
|
||||||
184.146.76.179 13586
|
|
||||||
37.107.121.203 18429
|
|
||||||
186.54.1.246 38354
|
|
||||||
184.18.8.33 8784
|
|
||||||
77.101.130.178 61762
|
|
||||||
109.8.154.28 19120
|
|
||||||
74.96.156.188 31749
|
|
||||||
94.96.167.130 64130
|
|
||||||
93.81.126.53 6881
|
|
||||||
79.136.243.46 46486
|
|
||||||
78.29.75.248 6881
|
|
||||||
114.42.47.178 9089
|
|
||||||
31.147.61.11 23853
|
|
||||||
193.253.220.184 6881
|
|
||||||
80.57.45.239 28239
|
|
||||||
72.192.215.39 30028
|
|
||||||
91.74.119.134 49246
|
|
||||||
85.250.43.217 41490
|
|
||||||
188.176.218.22 35407
|
|
||||||
98.119.4.86 1024
|
|
||||||
89.143.138.33 64606
|
|
||||||
46.138.37.148 59039
|
|
||||||
178.120.85.170 24550
|
|
||||||
67.185.95.9 32173
|
|
||||||
98.197.42.116 19866
|
|
||||||
114.38.21.113 7694
|
|
||||||
77.46.26.128 38127
|
|
||||||
93.80.96.134 23683
|
|
||||||
60.241.209.107 57588
|
|
||||||
171.97.173.243 9327
|
|
||||||
50.43.117.21 42660
|
|
||||||
87.244.169.128 55807
|
|
||||||
94.190.105.157 6881
|
|
||||||
178.122.199.251 16480
|
|
||||||
76.88.254.191 27137
|
|
||||||
112.120.144.128 60152
|
|
||||||
77.249.124.77 49187
|
|
||||||
165.132.236.14 25390
|
|
||||||
87.16.197.67 20787
|
|
||||||
80.103.109.43 55260
|
|
||||||
195.234.21.119 6881
|
|
||||||
176.212.60.108 60378
|
|
||||||
178.185.98.43 12420
|
|
||||||
124.149.151.181 33603
|
|
||||||
85.220.66.170 35131
|
|
||||||
109.130.31.27 11460
|
|
||||||
72.223.102.189 11614
|
|
||||||
111.15.147.164 16001
|
|
||||||
83.202.163.16 6881
|
|
||||||
92.246.22.40 33576
|
|
||||||
94.41.249.131 10613
|
|
||||||
95.24.101.211 6881
|
|
||||||
98.232.199.100 29721
|
|
||||||
174.101.153.252 38195
|
|
||||||
91.157.230.16 1885
|
|
||||||
109.211.143.205 13722
|
|
||||||
84.123.4.247 29043
|
|
||||||
112.209.16.158 19102
|
|
||||||
114.34.46.63 6881
|
|
||||||
85.138.230.74 56197
|
|
||||||
62.169.127.9 26665
|
|
||||||
211.217.2.251 41870
|
|
||||||
81.221.84.77 20214
|
|
||||||
109.197.191.45 19604
|
|
||||||
46.118.116.209 20711
|
|
||||||
46.42.23.240 53559
|
|
||||||
199.127.250.15 29015
|
|
||||||
78.220.115.99 49482
|
|
||||||
71.232.195.149 56530
|
|
||||||
84.123.59.159 13963
|
|
||||||
213.251.184.146 64347
|
|
||||||
67.164.23.233 7119
|
|
||||||
86.194.215.166 14316
|
|
||||||
89.224.149.142 25365
|
|
||||||
94.23.49.143 8000
|
|
||||||
78.119.193.151 55227
|
|
||||||
78.222.160.139 37995
|
|
||||||
89.209.82.248 12425
|
|
||||||
178.137.112.35 14571
|
|
||||||
94.23.0.84 51582
|
|
||||||
78.247.176.4 18105
|
|
||||||
90.41.206.239 30502
|
|
||||||
78.241.70.65 22014
|
|
||||||
98.194.6.21 51413
|
|
||||||
174.119.150.115 17065
|
|
||||||
189.5.22.202 52412
|
|
||||||
93.124.97.171 49001
|
|
||||||
186.4.42.27 20837
|
|
||||||
24.144.184.102 14888
|
|
||||||
78.173.175.56 53453
|
|
||||||
79.114.14.206 4602
|
|
||||||
109.184.163.146 11789
|
|
||||||
98.200.252.137 18502
|
|
||||||
79.82.130.49 20757
|
|
||||||
5.165.66.132 63326
|
|
||||||
46.29.147.201 20232
|
|
||||||
114.32.184.15 25962
|
|
||||||
94.21.70.206 50541
|
|
||||||
92.98.171.108 51413
|
|
||||||
188.49.25.79 46883
|
|
||||||
90.149.227.168 49241
|
|
||||||
92.99.221.105 51405
|
|
||||||
123.139.45.71 16001
|
|
||||||
68.98.108.234 24290
|
|
||||||
88.169.60.195 17108
|
|
||||||
114.37.154.22 16120
|
|
||||||
121.219.232.47 65073
|
|
||||||
46.119.196.109 19075
|
|
||||||
123.110.104.200 29499
|
|
||||||
77.73.46.124 28966
|
|
||||||
87.253.26.85 45934
|
|
||||||
176.108.146.88 6881
|
|
||||||
188.187.45.126 43757
|
|
||||||
92.2.212.97 15078
|
|
||||||
178.140.169.137 22922
|
|
||||||
114.38.14.84 16958
|
|
||||||
80.98.106.227 9773
|
|
||||||
86.169.117.185 51938
|
|
||||||
201.53.229.60 1041
|
|
||||||
65.95.191.51 51413
|
|
||||||
24.78.8.98 6884
|
|
||||||
90.204.42.12 48402
|
|
||||||
76.7.214.210 35875
|
|
||||||
88.155.36.246 15856
|
|
||||||
78.227.88.161 23191
|
|
||||||
62.83.111.85 36398
|
|
||||||
130.43.29.146 52526
|
|
||||||
88.170.61.126 32761
|
|
||||||
85.246.109.226 6890
|
|
||||||
82.237.40.39 39052
|
|
||||||
95.239.56.106 62200
|
|
||||||
71.187.209.2 22274
|
|
||||||
178.148.68.18 53318
|
|
||||||
78.163.220.242 31758
|
|
||||||
188.235.149.202 63083
|
|
||||||
119.201.103.241 62715
|
|
||||||
83.87.5.5 43317
|
|
||||||
201.83.71.123 50579
|
|
||||||
83.6.22.221 52512
|
|
||||||
95.54.76.150 56930
|
|
||||||
207.255.112.154 6881
|
|
||||||
188.121.244.133 10980
|
|
||||||
41.212.221.164 33050
|
|
||||||
178.168.58.44 23476
|
|
||||||
142.161.41.171 41788
|
|
||||||
211.133.168.214 44631
|
|
||||||
220.18.72.3 64774
|
|
||||||
70.114.155.3 34892
|
|
||||||
97.85.86.199 6890
|
|
||||||
119.74.54.94 6881
|
|
||||||
114.34.239.242 22647
|
|
||||||
67.128.168.196 11524
|
|
||||||
86.145.211.200 49330
|
|
||||||
72.230.75.87 21095
|
|
||||||
31.35.57.129 13924
|
|
||||||
190.60.48.165 41301
|
|
||||||
213.245.41.143 40018
|
|
||||||
95.104.80.193 6881
|
|
||||||
120.208.30.229 16001
|
|
||||||
93.105.81.215 21000
|
|
||||||
93.96.13.136 12181
|
|
||||||
190.88.179.253 20701
|
|
||||||
58.7.210.130 51413
|
|
||||||
195.222.95.57 51413
|
|
||||||
121.223.47.224 41563
|
|
||||||
85.219.118.111 27483
|
|
||||||
78.43.137.174 10409
|
|
||||||
77.71.220.234 62357
|
|
||||||
85.107.182.248 19486
|
|
||||||
37.235.207.247 30166
|
|
||||||
176.97.212.163 22523
|
|
||||||
88.230.184.110 25432
|
|
||||||
94.44.164.74 60966
|
|
||||||
95.188.23.129 42927
|
|
||||||
78.242.168.94 34153
|
|
||||||
62.93.99.6 28010
|
|
||||||
78.105.105.87 42127
|
|
||||||
208.101.109.128 53329
|
|
||||||
164.215.87.224 57073
|
|
||||||
87.106.187.29 20277
|
|
||||||
91.121.114.171 58846
|
|
||||||
80.42.246.251 20502
|
|
||||||
188.72.98.36 15503
|
|
||||||
176.31.248.87 6338
|
|
||||||
118.160.199.38 63400
|
|
||||||
174.71.20.57 52193
|
|
||||||
113.161.204.192 6881
|
|
||||||
2.94.72.90 27587
|
|
||||||
89.204.110.192 6881
|
|
||||||
76.121.38.23 58982
|
|
||||||
93.95.160.156 13118
|
|
||||||
122.174.156.164 15004
|
|
||||||
94.155.59.112 57833
|
|
||||||
176.49.172.107 49001
|
|
||||||
23.16.200.217 51413
|
|
||||||
60.241.87.17 24478
|
|
||||||
108.242.252.38 39304
|
|
||||||
201.252.144.11 15506
|
|
||||||
92.125.17.239 25548
|
|
||||||
114.79.138.158 60635
|
|
||||||
76.103.79.28 36151
|
|
||||||
77.71.69.65 12087
|
|
||||||
138.199.66.212 26174
|
|
||||||
119.131.41.152 1231
|
|
||||||
119.202.178.119 45249
|
|
||||||
78.141.127.164 55618
|
|
||||||
88.245.188.55 28097
|
|
||||||
217.165.53.221 24579
|
|
||||||
46.22.234.12 14916
|
|
||||||
98.199.98.228 32970
|
|
||||||
203.213.94.200 14161
|
|
||||||
66.197.135.74 9870
|
|
||||||
213.167.206.125 38106
|
|
||||||
80.83.245.36 6993
|
|
||||||
112.203.171.200 25932
|
|
||||||
105.236.34.74 43961
|
|
||||||
92.49.5.186 38678
|
|
||||||
46.61.12.234 49001
|
|
||||||
91.148.14.62 11206
|
|
||||||
95.37.162.145 14476
|
|
||||||
68.192.162.202 31159
|
|
||||||
68.209.239.148 50375
|
|
||||||
75.185.11.189 23993
|
|
||||||
178.72.159.43 47954
|
|
||||||
118.160.199.38 61182
|
|
||||||
75.142.21.2 56117
|
|
||||||
46.187.88.219 48529
|
|
||||||
98.127.163.114 53062
|
|
||||||
94.245.153.136 23040
|
|
||||||
109.174.3.81 51413
|
|
||||||
77.232.162.51 14257
|
|
||||||
94.96.112.204 35187
|
|
||||||
118.160.199.38 51651
|
|
||||||
5.13.18.103 24121
|
|
||||||
79.226.190.78 18189
|
|
||||||
95.90.236.216 41463
|
|
||||||
83.134.60.207 10267
|
|
||||||
118.160.199.38 51532
|
|
||||||
176.31.109.159 24586
|
|
||||||
99.242.88.203 21704
|
|
||||||
88.174.176.173 56969
|
|
||||||
84.151.248.98 61500
|
|
||||||
123.195.214.39 20846
|
|
||||||
94.62.25.152 39020
|
|
||||||
89.33.72.233 1398
|
|
||||||
92.37.27.83 37375
|
|
||||||
83.110.225.79 17257
|
|
||||||
178.36.198.215 22849
|
|
||||||
112.234.202.158 16001
|
|
||||||
188.231.143.20 6881
|
|
||||||
5.12.126.206 34538
|
|
||||||
62.65.216.158 13414
|
|
||||||
92.43.189.45 3140
|
|
||||||
79.9.144.222 29037
|
|
||||||
93.77.32.187 57408
|
|
||||||
91.247.142.205 58199
|
|
||||||
85.114.60.149 17582
|
|
||||||
119.196.44.47 51763
|
|
||||||
178.88.3.227 33031
|
|
||||||
76.30.131.83 49366
|
|
||||||
86.168.167.166 55451
|
|
||||||
212.45.81.173 16427
|
|
||||||
188.224.10.109 46059
|
|
||||||
82.178.114.74 50836
|
|
||||||
78.55.114.191 42839
|
|
||||||
85.54.211.184 17283
|
|
||||||
95.135.101.164 55829
|
|
||||||
209.195.77.83 34603
|
|
||||||
79.153.101.234 11154
|
|
||||||
71.63.225.31 21053
|
|
||||||
184.147.116.143 49025
|
|
||||||
88.186.230.88 12048
|
|
||||||
89.132.181.63 61498
|
|
||||||
95.84.208.14 9372
|
|
||||||
79.93.218.69 28681
|
|
||||||
64.113.125.178 61127
|
|
||||||
174.100.51.253 44460
|
|
||||||
88.3.236.194 10926
|
|
||||||
109.194.234.36 14342
|
|
||||||
68.106.225.140 47417
|
|
||||||
78.24.231.166 6881
|
|
||||||
84.40.80.3 6890
|
|
||||||
177.5.36.152 12588
|
|
||||||
68.82.32.238 18307
|
|
||||||
64.121.118.201 61270
|
|
||||||
75.40.21.238 51413
|
|
||||||
99.59.129.46 26141
|
|
||||||
79.95.171.102 11092
|
|
||||||
67.71.140.245 15582
|
|
||||||
95.32.187.214 14778
|
|
||||||
213.112.177.129 43304
|
|
||||||
81.51.97.133 40039
|
|
||||||
89.133.89.51 55846
|
|
||||||
79.18.246.192 20356
|
|
||||||
109.124.197.42 31559
|
|
||||||
182.53.45.3 14895
|
|
||||||
74.219.135.69 30239
|
|
||||||
95.111.0.20 34295
|
|
||||||
84.154.235.198 59678
|
|
||||||
93.58.14.83 51413
|
|
||||||
213.114.48.42 38511
|
|
||||||
46.48.90.11 55025
|
|
||||||
5.2.58.49 49001
|
|
||||||
92.139.252.16 36535
|
|
||||||
94.68.144.118 10009
|
|
||||||
75.187.202.104 44822
|
|
||||||
84.52.169.26 10838
|
|
||||||
114.32.211.85 30116
|
|
||||||
75.69.72.31 51413
|
|
||||||
118.160.199.38 63151
|
|
||||||
142.59.218.136 11300
|
|
||||||
118.160.199.38 63619
|
|
||||||
118.160.199.38 59277
|
|
||||||
82.47.63.231 26035
|
|
||||||
67.8.141.69 63990
|
|
||||||
223.18.249.29 7221
|
|
||||||
82.136.113.22 6881
|
|
||||||
86.100.227.142 50497
|
|
||||||
188.186.13.95 21313
|
|
||||||
24.128.39.166 5223
|
|
||||||
31.8.136.66 11996
|
|
||||||
82.137.118.90 26474
|
|
||||||
84.217.43.156 45620
|
|
||||||
217.29.187.23 62523
|
|
||||||
108.254.5.66 58192
|
|
||||||
182.177.228.43 31532
|
|
||||||
118.160.199.38 60134
|
|
||||||
67.167.180.162 11451
|
|
||||||
188.164.212.104 28566
|
|
||||||
95.196.203.111 59402
|
|
||||||
213.27.20.223 53410
|
|
||||||
178.44.187.32 52209
|
|
||||||
70.83.35.78 31982
|
|
||||||
1.172.161.190 17526
|
|
||||||
78.237.111.89 45254
|
|
||||||
188.25.246.130 16313
|
|
||||||
67.173.33.90 33134
|
|
||||||
212.49.47.32 19949
|
|
||||||
176.214.214.73 64892
|
|
||||||
173.73.46.92 52828
|
|
||||||
71.237.6.246 41304
|
|
||||||
70.113.2.167 45645
|
|
||||||
88.84.191.25 30536
|
|
||||||
87.2.74.180 6783
|
|
||||||
96.63.15.208 34651
|
|
||||||
76.181.135.146 17016
|
|
||||||
79.168.31.62 2622
|
|
||||||
95.153.169.40 19697
|
|
||||||
88.217.36.182 2924
|
|
||||||
119.96.130.9 12038
|
|
||||||
90.225.103.241 40066
|
|
||||||
78.106.178.64 46183
|
|
||||||
220.136.37.144 27075
|
|
||||||
92.87.167.73 55624
|
|
||||||
188.232.61.83 6881
|
|
||||||
183.89.3.101 10618
|
|
||||||
111.242.54.149 15979
|
|
||||||
120.146.228.149 6881
|
|
||||||
67.242.169.143 6886
|
|
||||||
31.8.71.71 10170
|
|
||||||
78.236.77.65 32026
|
|
||||||
91.137.168.238 27616
|
|
||||||
93.109.84.235 21443
|
|
||||||
77.34.44.71 35691
|
|
||||||
109.209.40.17 55542
|
|
||||||
83.157.77.228 7812
|
|
||||||
88.233.167.39 20620
|
|
||||||
69.176.171.40 11254
|
|
||||||
93.11.175.201 41027
|
|
||||||
50.71.135.98 20332
|
|
||||||
69.181.169.181 7313
|
|
||||||
46.8.136.196 57085
|
|
||||||
180.64.39.48 14708
|
|
||||||
46.211.113.5 49001
|
|
||||||
142.163.53.182 58144
|
|
||||||
90.38.76.72 4699
|
|
||||||
83.252.23.84 10699
|
|
||||||
78.163.181.120 16519
|
|
||||||
221.118.191.176 17563
|
|
||||||
184.41.75.34 57537
|
|
||||||
99.192.77.139 33333
|
|
||||||
88.174.167.76 30032
|
|
||||||
46.116.177.103 22754
|
|
||||||
94.103.196.139 54378
|
|
||||||
188.77.246.133 35496
|
|
||||||
217.76.184.18 51413
|
|
||||||
108.160.185.132 31530
|
|
||||||
50.83.34.19 23846
|
|
||||||
193.77.159.24 43611
|
|
||||||
80.14.161.164 51789
|
|
||||||
114.185.184.10 23151
|
|
||||||
82.235.101.26 7816
|
|
||||||
92.83.188.95 10477
|
|
||||||
46.180.245.79 53580
|
|
||||||
46.37.83.122 37389
|
|
||||||
86.29.220.199 28527
|
|
||||||
92.137.208.191 29253
|
|
||||||
85.167.249.218 55649
|
|
||||||
221.127.216.99 21461
|
|
||||||
130.89.165.24 10110
|
|
||||||
99.60.78.40 18894
|
|
||||||
49.145.59.194 38935
|
|
||||||
92.247.248.50 23666
|
|
||||||
5.149.211.210 22277
|
|
||||||
176.226.153.243 61967
|
|
||||||
174.117.49.59 13052
|
|
||||||
121.141.14.57 30323
|
|
||||||
83.155.218.188 51413
|
|
||||||
129.21.122.81 32785
|
|
||||||
46.118.83.183 12324
|
|
||||||
92.255.208.221 34798
|
|
||||||
212.21.13.209 56909
|
|
||||||
220.120.236.151 11393
|
|
||||||
37.218.190.131 35691
|
|
||||||
46.41.109.26 39584
|
|
||||||
2.51.116.185 63433
|
|
||||||
67.86.174.199 33605
|
|
||||||
212.74.222.13 38345
|
|
||||||
115.240.98.113 51413
|
|
||||||
37.59.55.58 51413
|
|
||||||
109.72.144.240 41290
|
|
||||||
207.224.196.66 10731
|
|
||||||
78.128.52.177 24574
|
|
||||||
79.138.67.151 47942
|
|
||||||
50.201.138.122 10228
|
|
||||||
176.9.113.77 61059
|
|
||||||
94.21.30.143 63448
|
|
||||||
178.89.100.227 6881
|
|
||||||
91.67.129.216 1210
|
|
||||||
82.232.212.66 55826
|
|
||||||
78.228.230.130 12577
|
|
||||||
79.175.106.234 12684
|
|
||||||
213.231.145.208 12306
|
|
||||||
97.106.156.54 63552
|
|
||||||
79.176.173.50 33043
|
|
||||||
75.70.84.67 52856
|
|
||||||
31.220.168.41 35190
|
|
||||||
1.161.107.196 31811
|
|
||||||
80.98.158.177 29436
|
|
||||||
88.148.233.194 38081
|
|
||||||
184.166.72.229 63472
|
|
||||||
93.186.192.165 39020
|
|
||||||
151.25.110.226 49289
|
|
||||||
178.45.159.135 31825
|
|
||||||
98.225.11.98 51769
|
|
||||||
109.28.82.4 33620
|
|
||||||
90.16.53.195 31338
|
|
||||||
223.219.73.227 17107
|
|
||||||
92.96.51.71 56237
|
|
||||||
112.173.11.227 63314
|
|
||||||
37.229.60.103 6881
|
|
||||||
90.29.226.250 14329
|
|
||||||
182.210.49.84 11993
|
|
||||||
177.32.251.226 27655
|
|
||||||
189.54.195.49 50555
|
|
|
@ -1,349 +0,0 @@
|
||||||
/*
|
|
||||||
* libretroshare/src/dht: bdhandler.h
|
|
||||||
*
|
|
||||||
* BitDht example interface
|
|
||||||
*
|
|
||||||
* Copyright 2009-2010 by Robert Fernie.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License Version 2 as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
||||||
* USA.
|
|
||||||
*
|
|
||||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <udp/udpstack.h>
|
|
||||||
#include <udp/udpbitdht.h>
|
|
||||||
#include <bitdht/bdstddht.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "bdhandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
/****
|
|
||||||
* This example bitdht app is designed to perform a single shot DHT search.
|
|
||||||
* Ww want to minimise the dht work, and number of UDP packets sent.
|
|
||||||
*
|
|
||||||
* This means we need to add:
|
|
||||||
* - don't search for App network. (libbitdht option)
|
|
||||||
* - don't bother filling up Space. (libbitdht option)
|
|
||||||
* - Programmatically add bootstrap peers. (libbitdht option)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This is a conversion callback class
|
|
||||||
*/
|
|
||||||
|
|
||||||
class BdCallback: public BitDhtCallback
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
BdCallback(BitDhtHandler *parent)
|
|
||||||
:mParent(parent) { return; }
|
|
||||||
|
|
||||||
virtual int dhtNodeCallback(const bdId *id, uint32_t peerflags)
|
|
||||||
{
|
|
||||||
return mParent->NodeCallback(id, peerflags);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int dhtPeerCallback(const bdId *id, uint32_t status)
|
|
||||||
{
|
|
||||||
return mParent->PeerCallback(id, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status)
|
|
||||||
{
|
|
||||||
return mParent->ValueCallback(id, key, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int dhtConnectCallback(const bdId*, const bdId*, const bdId*, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int dhtInfoCallback(const bdId*, uint32_t, uint32_t, std::string)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
BitDhtHandler *mParent;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
BitDhtHandler::BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId, std::string bootstrapfile)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::BitDhtHandler()" << std::endl;
|
|
||||||
std::cerr << "Using Id: ";
|
|
||||||
bdStdPrintNodeId(std::cerr, ownId);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
std::cerr << "Using Bootstrap File: " << bootstrapfile;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "Converting OwnId to bdNodeId....";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
/* standard dht behaviour */
|
|
||||||
bdDhtFunctions *stdfns = new bdStdDht();
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler() startup ... creating UdpBitDht";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
/* create dht */
|
|
||||||
struct sockaddr_in local;
|
|
||||||
memset(&local, 0, sizeof(local));
|
|
||||||
local.sin_family = AF_INET;
|
|
||||||
local.sin_addr.s_addr = 0;
|
|
||||||
local.sin_port = htons(port);
|
|
||||||
|
|
||||||
mStack = new UdpStack(local);
|
|
||||||
|
|
||||||
mUdpBitDht = new UdpBitDht(mStack, ownId, appId, bootstrapfile, stdfns);
|
|
||||||
mStack->addReceiver(mUdpBitDht);
|
|
||||||
|
|
||||||
/* setup callback to here */
|
|
||||||
BdCallback *bdcb = new BdCallback(this);
|
|
||||||
mUdpBitDht->addCallback(bdcb);
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler() starting threads and dht";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
mUdpBitDht->start(); /* starts up the bitdht thread */
|
|
||||||
|
|
||||||
/* setup best mode for quick search */
|
|
||||||
uint32_t dhtFlags = BITDHT_MODE_TRAFFIC_MED | BITDHT_MODE_RELAYSERVERS_IGNORED;
|
|
||||||
mUdpBitDht->setDhtMode(dhtFlags);
|
|
||||||
mUdpBitDht->setAttachMode(false);
|
|
||||||
|
|
||||||
/* switch on the dht too */
|
|
||||||
mUdpBitDht->startDht();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pqiNetAssist - external interface functions */
|
|
||||||
void BitDhtHandler::enable(bool on)
|
|
||||||
{
|
|
||||||
std::cerr << "p3BitDht::enable(" << on << ")";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
if (on)
|
|
||||||
{
|
|
||||||
mUdpBitDht->startDht();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mUdpBitDht->stopDht();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BitDhtHandler::shutdown() /* blocking call */
|
|
||||||
{
|
|
||||||
mUdpBitDht->stopDht();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BitDhtHandler::restart()
|
|
||||||
{
|
|
||||||
mUdpBitDht->stopDht();
|
|
||||||
mUdpBitDht->startDht();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BitDhtHandler::getEnabled()
|
|
||||||
{
|
|
||||||
return (mUdpBitDht->stateDht() != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BitDhtHandler::getActive()
|
|
||||||
{
|
|
||||||
return (mUdpBitDht->stateDht() >= BITDHT_MGR_STATE_ACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* pqiNetAssistConnect - external interface functions */
|
|
||||||
/* add / remove peers */
|
|
||||||
bool BitDhtHandler::FindNode(bdNodeId *peerId)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::FindNode(";
|
|
||||||
bdStdPrintNodeId(std::cerr, peerId);
|
|
||||||
std::cerr << ")" << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
BssResult res;
|
|
||||||
res.id.id = *peerId;
|
|
||||||
res.mode = BSS_SINGLE_SHOT;
|
|
||||||
res.status = 0;
|
|
||||||
|
|
||||||
{
|
|
||||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
|
||||||
mSearchNodes[*peerId] = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add in peer */
|
|
||||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DISGUISE);
|
|
||||||
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BitDhtHandler::DropNode(bdNodeId *peerId)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::DropNode(";
|
|
||||||
bdStdPrintNodeId(std::cerr, peerId);
|
|
||||||
std::cerr << ")" << std::endl;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
/* remove in peer */
|
|
||||||
mUdpBitDht->removeFindNode(peerId);
|
|
||||||
|
|
||||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
|
||||||
|
|
||||||
/* find the node from our list */
|
|
||||||
std::map<bdNodeId, BssResult>::iterator it;
|
|
||||||
it = mSearchNodes.find(*peerId);
|
|
||||||
if (it != mSearchNodes.end())
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::DropNode() Found NodeId, removing";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
mSearchNodes.erase(it);
|
|
||||||
}
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BitDhtHandler::SearchResult(bdId *id, uint32_t &status)
|
|
||||||
{
|
|
||||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
|
||||||
|
|
||||||
/* find the node from our list */
|
|
||||||
std::map<bdNodeId, BssResult>::iterator it;
|
|
||||||
it = mSearchNodes.find(id->id);
|
|
||||||
if (it != mSearchNodes.end())
|
|
||||||
{
|
|
||||||
if (it->second.status != 0)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::SearchResults() Found Results";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
status = it->second.status;
|
|
||||||
*id = it->second.id;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::SearchResults() No Results Yet";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::SearchResults() ERROR: No Search Entry";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/********************** Callback Functions **************************/
|
|
||||||
|
|
||||||
int BitDhtHandler::NodeCallback(const bdId *id, uint32_t peerflags)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_BITDHT
|
|
||||||
std::cerr << "BitDhtHandler::NodeCallback()";
|
|
||||||
bdStdPrintNodeId(std::cerr, &(id->id));
|
|
||||||
std::cerr << " flags: " << peerflags;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() NodeId: ";
|
|
||||||
bdStdPrintId(std::cerr, id);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
|
||||||
|
|
||||||
/* find the node from our list */
|
|
||||||
std::map<bdNodeId, BssResult>::iterator it;
|
|
||||||
it = mSearchNodes.find(id->id);
|
|
||||||
if (it == mSearchNodes.end())
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() Unknown NodeId !!! ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
it->second.status = status;
|
|
||||||
|
|
||||||
bool connect = false;
|
|
||||||
switch(status)
|
|
||||||
{
|
|
||||||
case BITDHT_MGR_QUERY_FAILURE:
|
|
||||||
/* do nothing */
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY FAILURE ... do nothin ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BITDHT_MGR_QUERY_PEER_OFFLINE:
|
|
||||||
/* do nothing */
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER OFFLINE ... do nothin ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
|
|
||||||
/* do nothing */
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... saving address ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
it->second.id = *id;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BITDHT_MGR_QUERY_PEER_ONLINE:
|
|
||||||
/* do something */
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... saving address";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
it->second.id = *id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int BitDhtHandler::ValueCallback(const bdNodeId *id, std::string key, uint32_t status)
|
|
||||||
{
|
|
||||||
std::cerr << "BitDhtHandler::ValueCallback() NOOP for NOW";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
std::cerr << "BitDhtHandler::ValueCallback()";
|
|
||||||
bdStdPrintNodeId(std::cerr, id);
|
|
||||||
std::cerr << " key: " << key;
|
|
||||||
std::cerr << " status: " << status;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
/* ignore for now */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue