Merge branch 'master' into android

This commit is contained in:
Gio 2016-11-07 14:37:23 +01:00
commit 8ab3c7de26
84 changed files with 4132 additions and 1402 deletions

View File

@ -1,13 +1,36 @@
sudo: required
dist: trusty
language: cpp
compiler:
- gcc
matrix:
include:
- os: linux
dist: trusty
sudo: required
compiler: gcc
- os: osx
osx_image: xcode6.2
compiler: clang
sudo: false
before_install:
- sudo apt-get update
- sudo apt-get install -y build-essential checkinstall cmake libavutil-dev libavcodec-dev libavformat-dev libbz2-dev libcurl4-openssl-dev libcv-dev libopencv-highgui-dev libhighgui-dev libgnome-keyring-dev libgstreamer-plugins-base0.10-dev libgstreamer0.10-dev libjasper-dev libjpeg-dev libmicrohttpd-dev libopencv-dev libprotobuf-dev libqt4-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libssl-dev libswscale-dev libtbb-dev libtiff4-dev libupnp-dev libv4l-dev libxine-dev libxslt1-dev libxss-dev pkg-config protobuf-compiler python-dev qtmobility-dev
- if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update; fi
- if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -y build-essential checkinstall cmake libavutil-dev libavcodec-dev libavformat-dev libbz2-dev libcurl4-openssl-dev libcv-dev libopencv-highgui-dev libhighgui-dev libgnome-keyring-dev libgstreamer-plugins-base0.10-dev libgstreamer0.10-dev libjasper-dev libjpeg-dev libmicrohttpd-dev libopencv-dev libprotobuf-dev libqt4-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libssl-dev libswscale-dev libtbb-dev libtiff4-dev libupnp-dev libv4l-dev libxine-dev libxslt1-dev libxss-dev pkg-config protobuf-compiler python-dev qtmobility-dev; fi
# - if [ $TRAVIS_OS_NAME == osx ]; then xcode-select --install ; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew update ; fi
# - if [ $TRAVIS_OS_NAME == osx ]; then brew install qt55 openssl miniupnpc libmicrohttpd speex homebrew/science/opencv ffmpeg sqlcipher ; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew install qt55 openssl miniupnpc libmicrohttpd speex ffmpeg sqlcipher ; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew link --force qt55 ; fi
#Fix for opencv and numpy already installed by system
- if [ $TRAVIS_OS_NAME == osx ]; then rm '/usr/local/bin/f2py'; fi
- if [ $TRAVIS_OS_NAME == osx ]; then rm -r '/usr/local/lib/python2.7/site-packages/numpy'; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew install homebrew/science/opencv; fi
# FIX: Now openssl is not linked in /usr/local/include and lib
- if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/include/* /usr/local/include/; fi
- if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/lib/*.a /usr/local/lib/; fi
- if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/lib/*.dylib /usr/local/lib/; fi
# - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && sudo apt-get install -y llvm-3.4 llvm-3.4-dev; fi
# - rvm use $RVM --install --binary --fuzzy
# - gem update --system
@ -31,8 +54,9 @@ addons:
before_script:
- qmake QMAKE_CC=$CC QMAKE_CXX=$CXX CONFIG+=no_sqlcipher CONFIG+=tests
#script: make
script: if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make && tests/unittests/unittests >/dev/null 2>&1 ; fi
script:
- if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make && tests/unittests/unittests >/dev/null 2>&1 ; fi
- if [ $TRAVIS_OS_NAME == osx ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j 4 ; fi
#after_success:

View File

@ -1,27 +1,31 @@
##Compilation on MacOS
# Compilation on MacOS
### Qt Installation
## Qt Installation
Install Qt via: [Qt Download](http://www.qt.io/download/)
Use default options.
Add to the PATH environment variable with this temporary solution.
Use default options. And add Qt Script support.
export PATH=/users/$USER/Qt/5.5/clang_64/bin:$PATH
Add to the PATH environment variable by editing your *~/.profile* file.
export PATH="/users/$USER/Qt/5.5/clang_64/bin:$PATH"
Depends on wich version of Qt you use.
## ***Choose if you use MacPort or HomeBrew***
### MacPort Installation
Install MacPort and XCode following this guide: [MacPort and XCode](http://guide.macports.org/#installing.xcode)
Start XCode to get it updated and to able C compiler to create executables.
###Install libraries
#### Install libraries
$sudo port -v selfupdate
$sudo port install openssl
$sudo port install miniupnpc
$sudo port install libmicrohttpd
For VOIP Plugin:
@ -30,36 +34,50 @@ For VOIP Plugin:
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
###Last Settings
### HOMEBREW Installation
In QtCreator Option Git add its path:
Install HomeBrew following this guide: [HomeBrew](http://brew.sh/)
C:\Program Files\Git\bin
Install XCode command line developer tools:
and select "Pull" with "Rebase"
$xcode-select --install
###Compil missing libraries
####SQLCipher
Start XCode to get it updated and to able C compiler to create executables.
#### Install libraries
$brew install openssl
$brew install miniupnpc
$brew install libmicrohttpd
If you have error in linking, run this:
$sudo chown -R $(whoami) /usr/local/lib/pkgconfig
For VOIP Plugin:
$brew install speex
$brew install homebrew/science/opencv
$brew install ffmpeg
Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs)
## Last Settings
In QtCreator Option Git select "Pull" with "Rebase"
## Compil missing libraries
### SQLCipher
cd <your development directory>
git clone https://github.com/sqlcipher/sqlcipher.git
cd sqlcipher
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
./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
homebrew uses newer, non-stock ssl dependencies found there. configure might get confused.
####libMicroHTTPD
The one with port don't have good support.
cd <your development directory>
wget http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz
tar zxvf libmicrohttpd-0.9.46.tar.gz
cd libmicrohttpd-0.9.46
bash ./configure
sudo make install
homebrew uses newer, non-stock ssl dependencies found there. Configure might get confused.
You can now compile RS into Qt Creator or with terminal
@ -68,4 +86,6 @@ You can now compile RS into Qt Creator or with terminal
cd retroshare
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 find compiled application on *./retroshare/retroshare-gui/src/RetroShare06.app*

View File

@ -1,5 +1,95 @@
retroshare06 (0.6.1-1.XXXXXX~YYYYYY) YYYYYY; urgency=low
e4e3667 csoler Sat, 5 Nov 2016 17:32:40 +0100 fixed bug that caused hierarchies that contain files being hashed to not send updates when the hash is finished
390bdfe csoler Sat, 5 Nov 2016 17:03:31 +0100 added request for sync on double click item for shared file lists
a97fa1e csoler Sat, 5 Nov 2016 16:07:30 +0100 fixed generation of pseudo-random request ids in p3filelists
1e919a1 csoler Sat, 5 Nov 2016 15:30:07 +0100 set delay between directory sweep to 60 secs and a-synced sweeps for different friends. Set drop time to 600 for un-answered dir sync requests
ffcf44b csoler Fri, 4 Nov 2016 21:54:28 +0100 removing call to drand48(). RSRandom is safer
2ef51ed csoler Fri, 4 Nov 2016 21:51:18 +0100 fixed wrong comment about RS_FILE_HINT_SEARCHABLE flag
79632ed csoler Fri, 4 Nov 2016 21:48:58 +0100 fixed compilation on windows
f39272a csoler Thu, 3 Nov 2016 21:44:40 +0100 fixed compilation in debug mode for p3filelists.cc
8c1a653 csoler Fri, 4 Nov 2016 20:02:14 +0100 Merge pull request #557 from mr-alice/v0.6-FTEncryption
2bb9a87 mr-alice Fri, 4 Nov 2016 13:52:11 +0100 merged and fixed conflict with upstream/master
30860b8 mr-alice Fri, 4 Nov 2016 13:46:20 +0100 removed ^M that polluted unittests.pro
45cb442 csoler Fri, 4 Nov 2016 09:47:49 +0100 Merge pull request #558 from csoler/v0.6-FileListsOptim
2bf2465 csoler Fri, 4 Nov 2016 09:18:34 +0100 Merge pull request #498 from PhenomRetroShare/Fix_ElCapitanCompil
8dacb22 csoler Thu, 3 Nov 2016 22:32:27 +0100 reducing linear cost of allocateNewIndex to constant. Should improve huge lags when receiving big file lists for the first time
e324d7d mr-alice Thu, 3 Nov 2016 20:31:47 +0100 removed warning in ftserver for rejected non encrypted tunnels
8653649 mr-alice Thu, 3 Nov 2016 20:26:35 +0100 fixed two bugs in ShareManager popup menu
29b5bfe mr-alice Thu, 3 Nov 2016 08:50:13 +0100 attempt to fixed leading tabs
2db8dbd Phenom Sat, 16 Jul 2016 23:10:00 +0200 Fix El Capitan OSX 10.11 Compil
1c2cfb2 mr-alice Wed, 2 Nov 2016 21:32:14 +0100 removed debug info in ftServer
5aef67d mr-alice Wed, 2 Nov 2016 21:31:14 +0100 fixed tooltips in ShareManager, and fixed anonymous search mechanism
d2118c5 mr-alice Wed, 2 Nov 2016 20:51:42 +0100 supressed deadlock in ftController due to calling ftServer from ftcontroller itself
46dd5be csoler Tue, 1 Nov 2016 16:30:46 +0100 Merge pull request #554 from hunbernd/feature/paste-RS-link
02f442a mr-alice Tue, 1 Nov 2016 14:28:00 +0100 changed naming for files visibility
8c7c764 mr-alice Tue, 1 Nov 2016 14:23:13 +0100 fixed conflicts in merging upstream/master to v0.6-FTEncryption
6a3610e mr-alice Tue, 1 Nov 2016 14:13:43 +0100 disallow double tunnels (encrypted+clear) in Accepted mode, since it is not needed
ffdac64 mr-alice Tue, 1 Nov 2016 11:57:25 +0100 fixed swarming with encrypted end-to-end tunnels
c6df59a mr-alice Tue, 1 Nov 2016 11:11:28 +0100 fixed bug in duplication of virtual dir names
761d595 mr-alice Tue, 1 Nov 2016 10:46:29 +0100 fixed layout and names in ShareManager and SharedFilesDialog
3430eec mr-alice Tue, 1 Nov 2016 10:30:36 +0100 fixed display of share flags as a proper nice icon set
8fe85b9 mr-alice Mon, 31 Oct 2016 23:24:35 +0100 improved ShareManager a little bit more
9d586bc mr-alice Mon, 31 Oct 2016 16:28:26 +0100 made a drastic simplification pass on the ShareManager, which now only needs a single window except for selecting files using a QFileDialog
e8e054e mr-alice Mon, 31 Oct 2016 14:26:01 +0100 addednew flag for anonymous search. Merged the two browsable flags in one single flag.
f934e88 csoler Mon, 31 Oct 2016 12:12:40 +0100 Merge pull request #555 from hunbernd/fix/random-emoji-order
36dc532 hunbernd Mon, 31 Oct 2016 00:23:39 +0100 Automatically detect retroshare links when pasting text
05b5c08 hunbernd Sat, 10 Sep 2016 21:59:45 +0200 Fixed emoticon order
5b9ef04 mr-alice Sun, 30 Oct 2016 15:33:05 +0100 improved debug output in ftserver
def20a3 mr-alice Sun, 30 Oct 2016 15:11:22 +0100 encrypted FT works. Fixed last bugs in ftServer
34dcb41 mr-alice Sun, 30 Oct 2016 11:36:00 +0100 fixed a few bugs in ftServer for encrypted tunnel management
9a88161 mr-alice Sat, 29 Oct 2016 18:35:48 +0200 added record for H(H(F)) in LocalDirectoryStorage
d843c1c mr-alice Sat, 29 Oct 2016 18:18:02 +0200 put consts behind serial_size() and serialise() in turtle items and ft items
babc126 mr-alice Sat, 29 Oct 2016 17:59:03 +0200 added default encryption policy variable and GUI to change it
8486346 mr-alice Wed, 26 Oct 2016 22:05:56 +0200 added new encryption/authentication format AEAD_chacha20_sha256
c87ca67 mr-alice Wed, 26 Oct 2016 18:15:47 +0200 improved efficiency of AEAD
88298b9 mr-alice Wed, 26 Oct 2016 14:45:21 +0200 added check for cleartext in AEAD test vector #1
42f6f26 mr-alice Wed, 26 Oct 2016 14:36:35 +0200 fixed bug in AEAD
7e536ef csoler Wed, 26 Oct 2016 11:35:30 +0200 Merge pull request #549 from PhenomRetroShare/Fix_PR#536
177752e mr-alice Tue, 25 Oct 2016 23:16:36 +0200 fixed a few bugs in AEAD construction based on test results
32e54e5 Phenom Tue, 25 Oct 2016 14:58:06 +0200 Fix PR#536 revealing of bad factor management in StyledElidedLabel.
0570427 mr-alice Tue, 25 Oct 2016 14:09:39 +0200 added google test for chacha20 code
0387a28 mr-alice Tue, 25 Oct 2016 00:08:27 +0200 added methods to get files from hash(hash) in directory_storage and ftServer
5f5b0d4 csoler Mon, 24 Oct 2016 20:16:21 +0200 Merge pull request #548 from PhenomRetroShare/Fix_PR#540
fd5a5cc Phenom Mon, 24 Oct 2016 20:11:47 +0200 Fix PR#540
2d72b88 mr-alice Mon, 24 Oct 2016 15:59:34 +0200 added code for AEAD construction
bd4c252 csoler Sun, 23 Oct 2016 23:30:56 +0200 Merge pull request #539 from RetroShare/md-fix
f3bebc0 csoler Sun, 23 Oct 2016 23:29:06 +0200 Merge pull request #540 from PhenomRetroShare/Fix_EmbedInHtmlAhref
c77d052 csoler Sun, 23 Oct 2016 23:25:53 +0200 Merge pull request #536 from PhenomRetroShare/Add_ElidedLabelToGroupTreeWidget
04992c9 csoler Sun, 23 Oct 2016 23:15:32 +0200 Merge pull request #543 from PhenomRetroShare/Add_TooltipOnComments
e525461 csoler Sun, 23 Oct 2016 23:14:29 +0200 Merge pull request #542 from PhenomRetroShare/Add_PasteRsLinkInTextFields
07564c7 csoler Sun, 23 Oct 2016 23:12:22 +0200 Merge pull request #541 from PhenomRetroShare/Fix_RsLinkCopyToClipBoard
5ccdc28 csoler Sun, 23 Oct 2016 22:51:32 +0200 Merge pull request #547 from hunbernd/fix/upload
54ba617 hunbernd Sun, 23 Oct 2016 20:42:59 +0200 Fix: unable to upload files on Windows Caused by multiple unneeded / character in file path.
46cf25d Phenom Sat, 22 Oct 2016 15:17:49 +0200 Fix Copy RsLink in Clipboard.
a67cf92 Phenom Sat, 22 Oct 2016 16:15:29 +0200 Add Tooltip on comments column to see too long text.
9eafdd3 Phenom Sat, 22 Oct 2016 16:02:38 +0200 Add ability to past RsLink in some more text fields.
58a4d39 Phenom Sat, 22 Oct 2016 14:48:23 +0200 Fix handle of url in EmbedInHtmlAhref.
f20ee21 cave Fri, 21 Oct 2016 19:56:02 +0200 Update README.md
9d32406 mr-alice Wed, 19 Oct 2016 22:49:51 +0200 added ft decryption routine
3ad0a81 mr-alice Wed, 19 Oct 2016 21:30:37 +0200 added encryption routine for FT
b8b78dd csoler Wed, 19 Oct 2016 15:50:22 +0200 Merge pull request #538 from Hopetech/master
ecaea05 hopetech Wed, 19 Oct 2016 15:41:25 +0200 Fix some compilation warnings
8483c0d Phenom Sun, 16 Oct 2016 15:48:50 +0200 Add ElidedLabel to GroupTreeWidget
997154f mr-alice Thu, 13 Oct 2016 15:13:56 +0200 added preliminary implementation of chacha20/poly1305
0e1fad0 csoler Thu, 13 Oct 2016 13:48:32 +0200 Merge pull request #533 from PhenomRetroShare/Fix_MissingDesktopFileShow
4db6d6b Phenom Thu, 13 Oct 2016 13:26:44 +0200 Fix the "Desktop file is missing" shown in option page.
64129a7 csoler Thu, 13 Oct 2016 10:05:14 +0200 Merge pull request #532 from G10h4ck/less_warning
8de0548 Gio Thu, 13 Oct 2016 00:09:53 +0200 Merge branch 'master' into less_warning
633a6cf Gio Wed, 12 Oct 2016 20:43:38 +0200 Fixed a bunch of warnings in safe ways
10c269e csoler Wed, 12 Oct 2016 23:31:32 +0200 removed warning when friend directory list cannot be found
bd9a464 csoler Wed, 12 Oct 2016 23:20:38 +0200 added deterministic but unredictable hash generation for dir hashes, which should be preserved accross reboots. Should fix the msg from friends sending requests for the "wrong" dir hashes.
3c5e12a csoler Mon, 10 Oct 2016 11:29:03 +0200 fixed compilation on windows
4e48005 csoler Sun, 9 Oct 2016 21:43:00 +0200 replaced explicit old code in cleanupDirectory() by new code based on FolderIterator
957d48b csoler Sun, 9 Oct 2016 21:03:01 +0200 removed folderIterator::d_name() because it duplicates file_name()
32816ed csoler Sun, 9 Oct 2016 18:23:25 +0200 Merge pull request #531 from PhenomRetroShare/Fix_AvatarOnEditCircle
6e8e5d0 csoler Sun, 9 Oct 2016 18:20:00 +0200 Merge pull request #529 from cavebeat/rus_patch
3d9fb60 Phenom Sun, 9 Oct 2016 12:37:09 +0200 Fix Missing ID-Avatars in Create Circle Menu
-- Cyril Soler <csoler@users.sourceforge.net> Sat, 5 Nov 2016 21:00:00 +0100
retroshare06 (0.6.1-1.20161008.9e1f21b9~xenial) xenial; urgency=low
9a3eb1c csoler Sat, 8 Oct 2016 14:30:58 +0200 Merge pull request #528 from sehraf/pr-drop-ssh-protobuf
c55fb0d csoler Sat, 8 Oct 2016 14:11:43 +0200 Merge pull request #524 from cavebeat/compile
97f2589 csoler Sat, 8 Oct 2016 14:09:34 +0200 Merge pull request #513 from grennvyper/patch-1

View File

@ -0,0 +1,44 @@
Source: retroshare06
Section: devel
Priority: standard
Maintainer: Cyril Soler <csoler@users.sourceforge.net>
Build-Depends: debhelper (>= 7), libglib2.0-dev, libupnp-dev, libssl-dev, libxss-dev, libgnome-keyring-dev, libbz2-dev, libspeex-dev, libspeexdsp-dev, libxslt1-dev, cmake, libcurl4-openssl-dev, libopencv-dev, tcl8.6, libsqlcipher-dev, libmicrohttpd-dev, libavcodec-dev, qtmultimedia5-dev, qttools5-dev, libqt5x11extras5-dev, qt5-default
Standards-Version: 3.9.6
Homepage: http://retroshare.sourceforge.net
Package: retroshare06-voip-plugin
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, retroshare06, libspeex1, libspeexdsp1, libqt5multimedia5
Description: RetroShare VOIP plugin
This package provides a plugin for RetroShare, a secured Friend-to-Friend communication
plateform. The plugin adds voice-over-IP functionality to the private chat window. Both
friends chatting together need the plugin installed to be able to talk together.
Package: retroshare06-feedreader-plugin
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, retroshare06
Description: RetroShare FeedReader plugin
This package provides a plugin for RetroShare, a secured Friend-to-Friend communication
plateform. The plugin adds a RSS feed reader tab to retroshare.
Package: retroshare06-nogui
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, gnome-keyring
Conflicts: retroshare06
Description: Secure communication with friends
This is the command-line client for RetroShare network. This client
can be contacted and talked-to using SSL. Clients exist for portable
devices running e.g. Android.
Package: retroshare06
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, gnome-keyring
Conflicts: retroshare06-nogui
Description: Secure communication with friends
RetroShare is a Open Source cross-platform, private and secure decentralised
commmunication platform. It lets you to securely chat and share files with your
friends and family, using a web-of-trust to authenticate peers and OpenSSL to
encrypt all communication. RetroShare provides filesharing, chat, messages,
forums and channels.

View File

@ -135,6 +135,8 @@ for i in ${dist}; do
cp ../control.precise debian/control
elif test "${i}" = "xenial" ; then
cp ../control.xenial debian/control
elif test "${i}" = "yakkety" ; then
cp ../control.yakkety debian/control
elif test "${i}" = "stretch" ; then
cp ../control.${i} debian/control
elif test "${i}" = "jessie" ; then

View File

@ -25,13 +25,13 @@ if errorlevel 1 goto error_env
:: Check MSYS environment
set MSYSSH=%EnvMSYSPath%\msys\1.0\bin\sh.exe
if not exist "%MSYSSH%" echo Please install MSYS first.& exit /B 1
if not exist "%MSYSSH%" %cecho% error "Please install MSYS first." & exit /B 1
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
call "%ToolsPath%\msys-path.bat" "%CurPath%" MSYSCurPath
call "%ToolsPath%\msys-path.bat" "%~dp0" MSYSCurPath
call "%ToolsPath%\msys-path.bat" "%BuildLibsPath%" MSYSBuildLibsPath
if not exist "%BuildLibsPath%" mkdir "%BuildLibsPath%"

View File

@ -1,13 +1,11 @@
set CurPath=%~dp0
:: Check MinGW environment
set MinGWPath=
call "%ToolsPath%\find-in-path.bat" MinGWPath gcc.exe
if "%MinGWPath%"=="" echo Please run command in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable.& exit /B 1
if "%MinGWPath%"=="" %cecho% error "Please run command in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable." & exit /B 1
:: Get gcc versions
call "%ToolsPath%\get-gcc-version.bat" GCCVersion
if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1
if "%GCCVersion%"=="" %cecho% error "Cannot get gcc version." & exit /B 1
set BuildLibsPath=%EnvRootPath%\build-libs\gcc-%GCCVersion%

View File

@ -0,0 +1,31 @@
@echo off
setlocal
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env.bat"
if errorlevel 1 goto error_env
%cecho% info "Build libraries"
call "%~dp0build-libs\build-libs.bat" auto-copy
if errorlevel 1 %cecho% error "Failed to build libraries." & exit /B %ERRORLEVEL%
%cecho% info "Build %SourceName%"
call "%~dp0build\build.bat"
if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL%
%cecho% info "Pack %SourceName%"
call "%~dp0build\pack.bat"
if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL%
%cecho% info "Build installer"
call "%~dp0build\build-installer.bat"
if errorlevel 1 %cecho% error "Failed to build installer." & exit /B %ERRORLEVEL%
exit /B 0
:error_env
echo Failed to initialize environment.
exit /B 1

View File

@ -1,4 +1,3 @@
set CurPath=%~dp0
set BuildPath=%EnvRootPath%\builds
set DeployPath=%EnvRootPath%\deploy

View File

@ -169,7 +169,7 @@ if exist "%SourcePath%\libresapi\src\webui" (
rem pack files
title Pack - %SourceName%-%RsBuildConfig% [pack files]
"%SevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*"
"%EnvSevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*"
title %COMSPEC%

View File

@ -1,5 +1,5 @@
:: Usage:
:: call find-in-path.bat [reinstall|clean]
:: call env-msys.bat [reinstall|clean]
:: Initialize environment
call "%~dp0env.bat"
@ -12,5 +12,4 @@ exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

23
build_scripts/Windows/env/env-qt.bat vendored Normal file
View File

@ -0,0 +1,23 @@
:: Usage:
:: call env-qt4.bat version [reinstall|clean]
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
set EnvQtBasePath=%EnvRootPath%\qt
:: Create folders
if not exist "%EnvQtBasePath%" mkdir "%EnvQtBasePath%"
call "%~dp0tools\prepare-qt.bat" %1 %2
if errorlevel 1 exit /B %ERRORLEVEL%
if "%MinGWDir%" NEQ "" set PATH=%MinGWDir%\bin;%PATH%
if "%QtDir%" NEQ "" set PATH=%QtDir%\bin;%PATH%
exit /B 0
:error_env
echo Failed to initialize environment.
exit /B 1

View File

@ -7,13 +7,16 @@ set EnvToolsPath=%EnvRootPath%\tools
set EnvTempPath=%EnvRootPath%\tmp
set EnvDownloadPath=%EnvRootPath%\download
set EnvCurlExe=%EnvToolsPath%\curl.exe
::set EnvCurlExe=%EnvToolsPath%\curl.exe
set EnvWgetExe=%EnvToolsPath%\wget.exe
set EnvSevenZipExe=%EnvToolsPath%\7z.exe
set EnvJomExe=%EnvToolsPath%\jom.exe
set EnvSedExe=%EnvToolsPath%\sed.exe
set EnvCutExe=%EnvToolsPath%\cut.exe
set EnvDependsExe=%EnvToolsPath%\depends.exe
set EnvMakeNSISExe=%EnvToolsPath%\NSIS\makensis.exe
set EnvCEchoExe=%EnvToolsPath%\cecho.exe
set cecho=call "%ToolsPath%\cecho.bat"
:: Create folders
if not exist "%EnvRootPath%" mkdir "%EnvRootPath%"
@ -25,5 +28,4 @@ exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

View File

@ -9,7 +9,7 @@ if not exist "%EnvRootPath%"=="" exit /B 1
copy "%~dp0root\update-msys.bat" "%EnvRootPath%" >nul
if "%~1"=="clean" (
echo Clean MSYS
%cecho% info "Clean MSYS"
call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%"
goto exit
)
@ -24,23 +24,25 @@ if exist "%EnvMSYSPath%\bin\mingw-get.exe" (
)
set MSYSInstall=mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip
set MSYSUrl=http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download
set CMakeInstall=cmake-3.1.0-win32-x86.zip
set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall%
set CMakeUnpackPath=%EnvMSYSPath%\msys\1.0
echo Remove previous MSYS version
%cecho% info "Remove previous MSYS version"
call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%"
echo Download installation files
if not exist "%EnvDownloadPath%\%MSYSInstall%" "%EnvCurlExe%" -L -k http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download -o "%EnvDownloadPath%\%MSYSInstall%"
if not exist "%EnvDownloadPath%%\MSYSInstall%" echo Cannot download MSYS& goto error
%cecho% info "Download installation files"
if not exist "%EnvDownloadPath%\%MSYSInstall%" call "%ToolsPath%\download-file.bat" "%MSYSUrl%" "%EnvDownloadPath%\%MSYSInstall%"
if not exist "%EnvDownloadPath%\%MSYSInstall%" %cecho% error "Cannot download MSYS" & goto error
if not exist "%EnvDownloadPath%\%CMakeInstall%" "%EnvCurlExe%" -L -k http://www.cmake.org/files/v3.1/cmake-3.1.0-win32-x86.zip -o "%EnvDownloadPath%\%CMakeInstall%"
if not exist "%EnvDownloadPath%\%CMakeInstall%" echo Cannot download CMake& goto error
if not exist "%EnvDownloadPath%\%CMakeInstall%" call "%ToolsPath%\download-file.bat" "%CMakeUrl%" "%EnvDownloadPath%\%CMakeInstall%"
if not exist "%EnvDownloadPath%\%CMakeInstall%" %cecho% error "Cannot download CMake" & goto error
echo Unpack MSYS
%cecho% info "Unpack MSYS"
"%EnvSevenZipExe%" x -o"%EnvMSYSPath%" "%EnvDownloadPath%\%MSYSInstall%"
echo Install MSYS
%cecho% info "Install MSYS"
if not exist "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml" copy "%EnvMSYSPath%\var\lib\mingw-get\data\defaults.xml" "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml"
pushd "%EnvMSYSPath%\bin"
mingw-get.exe install mingw32-mingw-get
@ -53,14 +55,14 @@ mingw-get.exe install msys-mktemp
mingw-get.exe install msys-wget
popd
echo Unpack CMake
%cecho% info "Unpack CMake"
"%EnvSevenZipExe%" x -o"%CMakeUnpackPath%" "%EnvDownloadPath%\%CMakeInstall%"
echo Install CMake
%cecho% info "Install CMake"
set CMakeVersion=
for /D %%F in (%CMakeUnpackPath%\cmake*) do set CMakeVersion=%%~nxF
if "%CMakeVersion%"=="" echo CMake version not found.& goto :exit
echo Found CMake version %CMakeVersion%
if "%CMakeVersion%"=="" %cecho% error "CMake version not found." & goto :exit
%cecho% info "Found CMake version %CMakeVersion%"
set FoundProfile=
for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%EnvMSYSPath%\msys\1.0\etc\profile"') do set FoundProfile=%%F
@ -76,8 +78,3 @@ exit /B 0
:error
endlocal
exit /B 1
:error_vars
echo Failed to initialize variables.
endlocal
exit /B 1

View File

@ -0,0 +1,204 @@
:: Usage:
:: call prepare-qt.bat version [reinstall|clean]
setlocal enabledelayedexpansion
if "%EnvQtBasePath%"=="" exit /B 1
if not exist "%EnvRootPath%"=="" exit /B 1
set EnvQtVersion=%~1
if "%EnvQtVersion%"=="" (
%cecho% error "Please specify Qt version"
goto error
)
for /f "tokens=1,2 delims=." %%A in ("%EnvQtVersion%") do set EnvQtMainVersion=%%A& set EnvQtBaseVersion=%%A.%%B
set EnvQtPath=%EnvQtBasePath%\%EnvQtVersion%
if "%~2"=="clean" (
%cecho% info "Clean Qt %EnvQtVersion%"
call "%ToolsPath%\remove-dir.bat" "%EnvQtPath%"
goto exit
)
set CheckQmakeExe=
if "%EnvQtMainVersion%"=="4" (
set CheckQmakeExe=%EnvQtPath%\Qt\bin\qmake.exe
) else (
if "%EnvQtMainVersion%" GEQ "5" (
call :get_mingw_version EnvQtMinGWVersion "%EnvQtPath%\%EnvQtBaseVersion%"
if "!EnvQtMinGWVersion!" NEQ "" (
set CheckQmakeExe=%EnvQtPath%\%EnvQtBaseVersion%\!EnvQtMinGWVersion!\bin\qmake.exe
)
)
)
if "%CheckQmakeExe%" NEQ "" (
if exist "%CheckQmakeExe%" (
if "%~2"=="reinstall" (
choice /M "Found existing Qt %EnvQtVersion% version. Do you want to proceed?"
if !ERRORLEVEL!==2 goto exit
) else (
goto exit
)
)
)
set QtInstall=qt-opensource-windows-x86-mingw-%EnvQtVersion%.exe
set QtInstallWildcard=qt-opensource-windows-x86-mingw*-%EnvQtVersion%.exe
set QtUrl=http://download.qt.io/official_releases/qt/%EnvQtBaseVersion%/%EnvQtVersion%
%cecho% info "Remove previous Qt %EnvQtVersion% version"
call "%ToolsPath%\remove-dir.bat" "%EnvQtPath%"
%cecho% info "Download Qt installation files"
if not exist "%EnvDownloadPath%\%QtInstall%" (
call "%ToolsPath%\download-file-wildcard.bat" "%QtUrl%" "%QtInstallWildcard%" "%EnvDownloadPath%" QtInstallDownload
if "!QtInstallDownload!"=="" %cecho% error "Cannot download Qt %EnvQtVersion%" & goto error
ren "%EnvDownloadPath%\!QtInstallDownload!" "%QtInstall%"
)
if not exist "%EnvDownloadPath%\%QtInstall%" %cecho% error "Cannot download Qt %EnvQtVersion%" & goto error
mkdir "%EnvQtPath%"
if "%EnvQtMainVersion%"=="4" (
rem Qt 4
goto install_qt4
)
if "%EnvQtMainVersion%" GEQ "5" (
rem Qt >= 5
goto install_qt5
)
%cecho% error "Unknown Qt version %EnvQtVersion%"
:error
endlocal & set QtDir=& set MinGWDir=
exit /B 1
:exit
set QtDir=
set MinGWDir=
if "%EnvQtMainVersion%"=="4" (
rem Qt 4
set QtDir=%EnvQtBasePath%\%EnvQtVersion%\Qt
set MinGWDir=%EnvQtBasePath%\%EnvQtVersion%\mingw32
) else (
if "%EnvQtMainVersion%" GEQ "5" (
call :get_mingw_version EnvQtToolsMinGWVersion "%EnvQtPath%\Tools"
set QtDir=%EnvQtPath%\%EnvQtBaseVersion%\!EnvQtMinGWVersion!
set MinGWDir=%EnvQtPath%\Tools\!EnvQtToolsMinGWVersion!
)
)
endlocal & set QtDir=%QtDir%& set MinGWDir=%MinGWDir%
exit /B 0
:get_mingw_version
setlocal enabledelayedexpansion
set Variable=%~1
set Result=
for /D %%A in (%~2\*) do set Name=%%~nA& if "!Name:~0,5!"=="mingw" set Result=!Name!
endlocal & set %Variable%=%Result%
goto :EOF
:replace
set InFile=%~1
set InFileName=%~nx1
set OutFile=%~1.tmp
set SearchText=%~2
set ReplaceText=%~3
if exist "%OutFile%" del /Q "%OutFile%"
for /f "tokens=1* delims=]" %%A in ('find /n /v ""^<%InFile%') do (
set string=%%B
if "!string!"=="" (
echo.>>%OutFile%
) else (
set modified=!string:%SearchText%=%ReplaceText%!
echo !modified!>> %OutFile%
)
)
del "%InFile%"
rename "%OutFile%" "%InFileName%"
goto :EOF
:install_qt4
set MinGWInstall=i686-4.8.2-release-posix-dwarf-rt_v3-rev3.7z
set MinGWUrl=http://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/4.8.2/threads-posix/dwarf/%MinGWInstall%/download
%cecho% info "Download MinGW installation files"
if not exist "%EnvDownloadPath%\%MinGWInstall%" call "%ToolsPath%\download-file.bat" "%MinGWUrl%" "%EnvDownloadPath%\%MinGWInstall%"
if not exist "%EnvDownloadPath%\%MinGWInstall%" %cecho% error "Cannot download MinGW" & goto error
%cecho% info "Unpack Qt %EnvQtVersion%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%QtInstall%" $_14_
move "%EnvTempPath%\$_14_" "%EnvQtPath%\Qt"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
%cecho% info "Unpack MinGW"
"%EnvSevenZipExe%" x -o"%EnvQtPath%" "%EnvDownloadPath%\%MinGWInstall%"
echo Prepare Qt %EnvQtVersion%
echo [Paths]>"%EnvQtPath%\Qt\bin\qt.conf"
echo Prefix=..>>"%EnvQtPath%\Qt\bin\qt.conf"
goto exit
:install_qt5
set EnvQtInstallerFrameworkVersion=2.0.3
set QtInstallerFrameworkInstall=QtInstallerFramework-%EnvQtInstallerFrameworkVersion%-win-x86.exe
set QtInstallerFrameworkUrl=http://download.qt.io/official_releases/qt-installer-framework/%EnvQtInstallerFrameworkVersion%/QtInstallerFramework-win-x86.exe
%cecho% info "Download QtInstallerFramework installation files"
if not exist "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" call "%ToolsPath%\download-file.bat" "%QtInstallerFrameworkUrl%" "%EnvDownloadPath%\%QtInstallerFrameworkInstall%"
if not exist "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" %cecho% error "Cannot download Qt Installer Framework %EnvQtInstallerFrameworkVersion%" & goto error
%cecho% info "Unpack Qt Installer Framework"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" bin\devtool.exe
move "%EnvTempPath%\bin\devtool.exe" "%EnvQtPath%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
%cecho% info "Unpack Qt %EnvQtVersion%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
"%EnvQtPath%\devtool.exe" "%EnvDownloadPath%\%QtInstall%" --dump "%EnvTempPath%"
pushd "%EnvTempPath%"
del /S *vcredist*.7z
del /S *qtcreator*.7z
del /S *1installer-changelog.7z
for /R %%F in (*.7z) do "%EnvSevenZipExe%" x -y -o"%EnvQtPath%" "%%F"
popd
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
call :get_mingw_version EnvQtMinGWVersion "%EnvQtPath%\%EnvQtBaseVersion%"
%cecho% info "Prepare Qt %EnvQtVersion%"
echo [Paths]>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf"
echo Documentation=../../Docs/Qt-%EnvQtBaseVersion%>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf"
echo Examples=../../Examples/Qt-%EnvQtBaseVersion%>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf"
echo Prefix=..>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf"
call :replace "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\mkspecs\qconfig.pri" "Enterprise" "OpenSource"
for /R "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\lib" %%A in (*.pc) do (
call :replace "%%A" "c:/Users/qt/work/install" "%EnvQtPath:\=\\%\%EnvQtBaseVersion%\\%EnvQtMinGWVersion%"
call :replace "%%A" "c:\Users\qt\work\install" "%EnvQtPath:\=/%\%EnvQtBaseVersion%/%EnvQtMinGWVersion%"
)
for /R "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\lib" %%A in (*.prl) do (
call :replace "%%A" "c:/Users/qt/work/install" "%EnvQtPath:\=\\%\%EnvQtBaseVersion%\\%EnvQtMinGWVersion%"
call :replace "%%A" "c:\Users\qt\work\install" "%EnvQtPath:\=/%\%EnvQtBaseVersion%/%EnvQtMinGWVersion%"
)
goto exit

View File

@ -2,10 +2,14 @@ setlocal
if "%EnvRootPath%"=="" exit /B 1
set CEchoUrl=https://github.com/lordmulder/cecho/releases/download/2015-10-10/cecho.2015-10-10.zip
set CEchoInstall=cecho.2015-10-10.zip
set SevenZipUrl=http://7-zip.org/a/7z1602.msi
set SevenZipInstall=7z1602.msi
set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z
set CurlInstall=curl-7.50.1-win32-mingw.7z
::set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z
::set CurlInstall=curl-7.50.1-win32-mingw.7z
set WgetUrl=https://eternallybored.org/misc/wget/current/wget.exe
set WgetInstall=wget.exe
set JomUrl=http://download.qt.io/official_releases/jom/jom.zip
set JomInstall=jom.zip
set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip
@ -33,32 +37,58 @@ if not exist "%EnvToolsPath%\7z.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
)
if not exist "%EnvToolsPath%\curl.exe" (
if not exist "%EnvToolsPath%\cecho.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download Curl installation
echo Download cecho installation
if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%"
if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error
if not exist "%EnvDownloadPath%\%CEchoInstall%" call "%ToolsPath%\winhttpjs.bat" "%CEchoUrl%" -saveTo "%EnvDownloadPath%\%CEchoInstall%"
if not exist "%EnvDownloadPath%\%cCEhoInstall%" echo Cannot download cecho installation& goto error
echo Unpack Curl
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%"
copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%"
echo Unpack cecho
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CEchoInstall%"
copy "%EnvTempPath%\cecho.exe" "%EnvToolsPath%"
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
)
::if not exist "%EnvToolsPath%\curl.exe" (
:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
:: mkdir "%EnvTempPath%"
::
:: echo Download Curl installation
::
:: if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%"
:: if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error
::
:: echo Unpack Curl
:: "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%"
:: copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%"
::
:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
::)
if not exist "%EnvToolsPath%\wget.exe" (
%cecho% info "Download Wget installation"
if not exist "%EnvDownloadPath%\%WgetInstall%" call "%ToolsPath%\winhttpjs.bat" %WgetUrl% -saveTo "%EnvDownloadPath%\%WgetInstall%"
if not exist "%EnvDownloadPath%\%WgetInstall%" %cecho% error "Cannot download Wget installation" & goto error
%cecho% info "Copy Wget"
copy "%EnvDownloadPath%\wget.exe" "%EnvToolsPath%"
)
if not exist "%EnvToolsPath%\jom.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download jom installation
%cecho% info "Download jom installation"
if not exist "%EnvDownloadPath%\%JomInstall%" call "%ToolsPath%\winhttpjs.bat" %JomUrl% -saveTo "%EnvDownloadPath%\%JomInstall%"
if not exist "%EnvDownloadPath%\%JomInstall%" echo Cannot download jom installation& goto error
if not exist "%EnvDownloadPath%\%JomInstall%" %cecho% error "Cannot download jom installation" & goto error
echo Unpack jom
%cecho% info "Unpack jom"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%JomInstall%"
copy "%EnvTempPath%\jom.exe" "%EnvToolsPath%"
@ -69,12 +99,12 @@ if not exist "%EnvToolsPath%\depends.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download Dependency Walker installation
%cecho% info "Download Dependency Walker installation"
if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\winhttpjs.bat" %DependsUrl% -saveTo "%EnvDownloadPath%\%DependsInstall%"
if not exist "%EnvDownloadPath%\%DependsInstall%" echo Cannot download Dependendy Walker installation& goto error
if not exist "%EnvDownloadPath%\%DependsInstall%" %cecho% error "Cannot download Dependendy Walker installation" & goto error
echo Unpack Dependency Walker
%cecho% info "Unpack Dependency Walker"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%DependsInstall%"
copy "%EnvTempPath%\*" "%EnvToolsPath%"
@ -85,12 +115,12 @@ if not exist "%EnvToolsPath%\cut.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download Unix Tools installation
%cecho% info "Download Unix Tools installation"
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%"
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download unix Tools installation& goto error
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error ""Cannot download Unix Tools installation" & goto error
echo Unpack Unix Tools
%cecho% info "Unpack Unix Tools"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%"
copy "%EnvTempPath%\cut.exe" "%EnvToolsPath%"
@ -101,12 +131,12 @@ if not exist "%EnvToolsPath%\sed.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download Unix Tools installation
%cecho% info "Download Unix Tools installation"
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%"
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download Unix Tools installation& goto error
if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error ""Cannot download Unix Tools installation" & goto error
echo Unpack Unix Tools
%cecho% info "Unpack Unix Tools"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%"
copy "%EnvTempPath%\sed.exe" "%EnvToolsPath%"
@ -117,12 +147,12 @@ if not exist "%EnvToolsPath%\NSIS\nsis.exe" (
call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
echo Download NSIS installation
%cecho% info "Download NSIS installation"
if not exist "%EnvDownloadPath%\%NSISInstall%" "%EnvCurlExe%" -L -k %NSISUrl% -o "%EnvDownloadPath%\%NSISInstall%"
if not exist "%EnvDownloadPath%\%NSISInstall%" echo Cannot download NSIS installation& goto error
if not exist "%EnvDownloadPath%\%NSISInstall%" call "%ToolsPath%\download-file.bat" "%NSISUrl%" "%EnvDownloadPath%\%NSISInstall%"
if not exist "%EnvDownloadPath%\%NSISInstall%" %cecho% error "Cannot download NSIS installation" & goto error
echo Unpack NSIS
%cecho% info "Unpack NSIS"
"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%NSISInstall%"
if not exist "%NSISInstallPath%" mkdir "%NSISInstallPath%"
xcopy /s "%EnvTempPath%" "%NSISInstallPath%"

View File

@ -0,0 +1,27 @@
:: Usage:
:: call qt-cmd.bat <Qt version> [command]
@echo off
setlocal
set QtVersion=%~1
:: Initialize environment
call "%~dp0env.bat"
if errorlevel 1 goto error_env
call "%EnvPath%\env-qt.bat" %QtVersion%
if errorlevel 1 goto error_env
if "%~2"=="" (
"%ComSpec%"
) else (
"%ComSpec%" /c %2 %3 %4 %5 %6 %7 %8 %9
)
exit /B %ERRORLEVEL%
:error_env
echo Failed to initialize environment.
endlocal
exit /B 1

View File

@ -1,12 +0,0 @@
#!/bin/sh
if [ $# -le 0 ]
then
echo usage $0 directory
exit
fi
echo find $1 -name .svn
rm -vrf `find $1 -name .svn`

View File

@ -0,0 +1,6 @@
:: Usage:
:: call cecho.bat [info|error|std] "text"
if "%~1"=="std" echo %~2
if "%~1"=="info" "%EnvCEchoExe%" green "%~2"
if "%~1"=="error" "%EnvCEchoExe%" red "%~2"

View File

@ -0,0 +1,46 @@
:: Usage:
:: call download-file-wildcard.bat url file-wildcard download-path variable
if "%~4"=="" (
echo.
echo Parameter error.
exit /B 1
)
if "%EnvTempPath%"=="" (
echo.
echo Environment error.
exit /B 1
)
setlocal
set Url=%~1
set FileWildcard=%~2
set DownloadPath=%~3
set Var=%~4
set File=
call "%~dp0remove-dir.bat" "%EnvTempPath%"
mkdir "%EnvTempPath%"
"%EnvWgetExe%" --recursive --continue --no-directories --no-parent -A "%FileWildcard%" --directory-prefix="%EnvTempPath%" "%Url%"
if errorlevel 1 (
call "%~dp0remove-dir.bat" "%EnvTempPath%"
endlocal & set %Var%=
exit /B %ERRORLEVEL%
)
for %%A in (%EnvTempPath%\%FileWildcard%) do set File=%%~nxA
if "%File%"=="" (
call "%~dp0remove-dir.bat" "%EnvTempPath%"
endlocal & set %Var%=
exit /B %ERRORLEVEL%
)
move "%EnvTempPath%\%File%" "%DownloadPath%"
call "%~dp0remove-dir.bat" "%EnvTempPath%"
endlocal & set %Var%=%File%
exit /B 0

View File

@ -0,0 +1,13 @@
:: Usage:
:: call download-file.bat url file
if "%~2"=="" (
echo.
echo Parameter error.
exit /B 1
)
::"%EnvCurlExe%" -L -k "%~1" -o "%~2"
"%EnvWgetExe%" --continue "%~1" --output-document="%~2"
exit /B %ERRORLEVEL%

View File

@ -113,7 +113,8 @@ libresapihttpserver {
} else {
mac {
INCLUDEPATH += . $$INC_DIR
for(lib, LIB_DIR):exists($$lib/libmicrohttpd.a){ LIBS *= $$lib/libmicrohttpd.a}
#for(lib, LIB_DIR):exists($$lib/libmicrohttpd.a){ LIBS *= $$lib/libmicrohttpd.a}
LIBS *= -lmicrohttpd
} else {
LIBS *= -lmicrohttpd
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,116 @@
/*
* RetroShare C++ File sharing default variables
*
* crypto/chacha20.h
*
* Copyright 2016 by Mr.Alice
*
* 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 "retroshare.project@gmail.com".
*
*/
#include <stdint.h>
namespace librs
{
namespace crypto
{
/*!
* \brief chacha20_encrypt
* Performs in place encryption/decryption of the supplied data, using chacha20, using the supplied key and nonce.
*
* \param key secret encryption key. *Should never* be re-used.
* \param block_counter any integer. 0 is fine.
* \param nonce acts as an initialzation vector. /!\ it is extremely important to make sure that this nounce *is* everytime different. Using a purely random value is fine.
* \param data data that gets encrypted/decrypted in place
* \param size size of the data.
*/
void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) ;
/*!
* \brief poly1305_tag
* Computes an authentication tag for the supplied data, using the given secret key.
* \param key secret key. *Should not* be used multiple times.
* \param message message to generate a tag for
* \param size size of the message
* \param tag place where the tag is stored.
*/
void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]);
/*!
* \brief AEAD_chacha20_poly1305
* Provides in-place authenticated encryption using the AEAD construction as described in RFC7539.
* The data is first encrypted in place then 16-padded and concatenated to its size, than concatenated to the
* 16-padded AAD (additional authenticated data) and its size, authenticated using poly1305.
*
* \param key key that is used to derive a one time secret key for poly1305 and that is also used to encrypt the data
* \param nonce nonce. *Should be unique* in order to make the chacha20 stream cipher unique.
* \param data data that is encrypted/decrypted in place.
* \param size size of the data
* \param aad additional authenticated data. Can be used to authenticate the nonce.
* \param aad_size
* \param tag generated poly1305 tag.
* \param encrypt true to encrypt, false to decrypt and check the tag.
* \return
* always true for encryption.
* authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is.
*/
bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ;
/*!
* \brief AEAD_chacha20_sha256
* Provides authenticated encryption using a simple construction that associates chacha20 encryption with HMAC authentication using
* the same 32 bytes key. The authenticated tag is the 16 first bytes of the sha256 HMAC.
*
* \param key encryption/authentication key
* \param nonce nonce. *Should be unique* in order to make chacha20 stream cipher unique.
* \param data data that is encrypted/decrypted in place
* \param data_size size of data to encrypt/authenticate
* \param aad additional authenticated data. Can be used to authenticate the nonce.
* \param aad_size
* \param tag 16 bytes authentication tag result
* \param encrypt true to encrypt, false to decrypt and check the tag.
* \return
* always true for encryption.
* authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is.
*/
bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ;
/*!
* \brief constant_time_memcmp
* Provides a constant time comparison of two memory chunks. Calls CRYPTO_memcmp.
*
* \param m1 memory block 1
* \param m2 memory block 2
* \param size common size of m1 and m2
* \return
* false if the two chunks are different
* true if the two chunks are identical
*/
bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) ;
/*!
* \brief perform_tests
* Tests all methods in this class, using the tests supplied in RFC7539
* \return
* true is all tests pass
*/
bool perform_tests() ;
}
}

View File

@ -299,8 +299,7 @@ bool InternalFileHierarchyStorage::updateSubFilesList(const DirectoryStorage::En
std::cerr << "[directory storage] removing non existing file " << f.file_name << " at index " << d.subfiles[i] << std::endl;
#endif
delete mNodes[d.subfiles[i]] ;
mNodes[d.subfiles[i]] = NULL ;
deleteNode(d.subfiles[i]) ;
d.subfiles[i] = d.subfiles[d.subfiles.size()-1] ;
d.subfiles.pop_back();
@ -374,24 +373,30 @@ bool InternalFileHierarchyStorage::updateFile(const DirectoryStorage::EntryIndex
return true;
}
DirectoryStorage::EntryIndex InternalFileHierarchyStorage::allocateNewIndex()
void InternalFileHierarchyStorage::deleteNode(uint32_t index)
{
int found = -1;
for(uint32_t j=0;j<mNodes.size();++j)
if(mNodes[j] == NULL)
if(mNodes[index] != NULL)
{
found = j;
break;
delete mNodes[index] ;
mFreeNodes.push_back(index) ;
mNodes[index] = NULL ;
}
}
if(found < 0)
DirectoryStorage::EntryIndex InternalFileHierarchyStorage::allocateNewIndex()
{
while(!mFreeNodes.empty())
{
uint32_t index = mFreeNodes.front();
mFreeNodes.pop_front();
if(mNodes[index] == NULL)
return DirectoryStorage::EntryIndex(index) ;
}
mNodes.push_back(NULL) ;
return mNodes.size()-1 ;
}
else
return found ;
}
bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryIndex& indx,const std::string& dir_name,time_t most_recent_time,time_t dir_modtime,const std::vector<RsFileHash>& subdirs_hash,const std::vector<FileEntry>& subfiles_array)
{
@ -534,8 +539,7 @@ bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryI
std::cerr << "(EE) Cannot delete node of index " << it->second << " because it is not a file. Inconsistency error!" << std::endl;
continue ;
}
delete mNodes[it->second] ;
mNodes[it->second] = NULL ;
deleteNode(it->second) ;
}
// now update row and parent index for all subnodes
@ -590,12 +594,12 @@ bool InternalFileHierarchyStorage::setTS(const DirectoryStorage::EntryIndex& ind
// Do a complete recursive sweep over sub-directories and files, and update the lst modf TS. This could be also performed by a cleanup method.
time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index)
time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index,bool& unfinished_files_present)
{
DirEntry& d(*static_cast<DirEntry*>(mNodes[dir_index])) ;
time_t largest_modf_time = d.dir_modtime ;
bool unfinished_files_present = false ;
unfinished_files_present = false ;
for(uint32_t i=0;i<d.subfiles.size();++i)
{
@ -608,7 +612,12 @@ time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectorySto
}
for(uint32_t i=0;i<d.subdirs.size();++i)
largest_modf_time = std::max(largest_modf_time,recursUpdateLastModfTime(d.subdirs[i])) ;
{
bool unfinished_files_below = false ;
largest_modf_time = std::max(largest_modf_time,recursUpdateLastModfTime(d.subdirs[i],unfinished_files_below)) ;
unfinished_files_present = unfinished_files_present || unfinished_files_below ;
}
// now if some files are not hashed in this directory, reduce the recurs time by 1, so that the TS wil be updated when all hashes are ready.
@ -673,18 +682,9 @@ DirectoryStorage::EntryIndex InternalFileHierarchyStorage::getSubDirIndex(Direct
return static_cast<DirEntry*>(mNodes[parent_index])->subdirs[dir_tab_index];
}
bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results)
bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& result)
{
DirectoryStorage::EntryIndex indx ;
if(getIndexFromFileHash(hash,indx))
{
results.clear();
results.push_back(indx) ;
return true ;
}
else
return false;
return getIndexFromFileHash(hash,result);
}
class DirectoryStorageExprFileEntry: public RsRegularExpression::ExpFileEntry
@ -749,6 +749,8 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co
std::vector<uint32_t> hits(mNodes.size(),0) ; // count hits of children. Should be 1 for all in the end. Otherwise there's an error.
hits[0] = 1 ; // because 0 is never the child of anyone
mFreeNodes.clear();
for(uint32_t i=0;i<mNodes.size();++i)
if(mNodes[i] != NULL && mNodes[i]->type() == FileStorageNode::TYPE_DIR)
{
@ -796,13 +798,15 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co
}
}
}
else if(mNodes[i] == NULL)
mFreeNodes.push_back(i) ;
for(uint32_t i=0;i<hits.size();++i)
if(hits[i] == 0 && mNodes[i] != NULL)
{
error_string += " - Orphean node!" ;
delete mNodes[i] ;
mNodes[i] = NULL ;
deleteNode(i) ;
}
return error_string.empty();;
@ -896,12 +900,9 @@ bool InternalFileHierarchyStorage::recursRemoveDirectory(DirectoryStorage::Entry
recursRemoveDirectory(d.subdirs[i]);
for(uint32_t i=0;i<d.subfiles.size();++i)
{
delete mNodes[d.subfiles[i]] ;
mNodes[d.subfiles[i]] = NULL ;
}
delete mNodes[dir] ;
mNodes[dir] = NULL ;
deleteNode(d.subfiles[i]);
deleteNode(dir) ;
mDirHashes.erase(hash) ;
@ -1014,6 +1015,8 @@ bool InternalFileHierarchyStorage::load(const std::string& fname)
uint32_t buffer_size = 0 ;
uint32_t buffer_offset = 0 ;
mFreeNodes.clear();
try
{
if(!FileListIO::loadEncryptedDataFromFile(fname,buffer,buffer_size) )

View File

@ -110,7 +110,7 @@ public:
// Do a complete recursive sweep over sub-directories and files, and update the lst modf TS. This could be also performed by a cleanup method.
time_t recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index);
time_t recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index, bool &unfinished_files_present);
// hash stuff
@ -122,6 +122,7 @@ public:
bool findSubDirectory(DirectoryStorage::EntryIndex e,const std::string& s) const ; // returns true when s is the name of a sub-directory in the given entry e
uint32_t mRoot ;
std::list<uint32_t > mFreeNodes ; // keeps a list of free nodes in order to make insert effcieint
std::vector<FileStorageNode*> mNodes;// uses pointers to keep information about valid/invalid objects.
void compress() ; // use empty space in the vector, mostly due to deleted entries. This is a complicated operation, mostly due to
@ -142,7 +143,7 @@ public:
// search. SearchHash is logarithmic. The other two are linear.
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
bool searchHash(const RsFileHash& hash, DirectoryStorage::EntryIndex &result);
int searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ; // does a logical OR between items of the list of terms
@ -159,6 +160,10 @@ private:
DirectoryStorage::EntryIndex allocateNewIndex();
// Deletes an existing entry in mNodes, and keeps record of the indices that get freed.
void deleteNode(DirectoryStorage::EntryIndex);
// Removes the given subdirectory from the parent node and all its pendign subdirs. Files are kept, and will go during the cleaning
// phase. That allows to keep file information when moving them around.

View File

@ -168,12 +168,6 @@ bool DirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash
return mFileHierarchy->updateHash(index,hash);
}
int DirectoryStorage::searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const
{
RS_STACK_MUTEX(mDirStorageMtx) ;
return mFileHierarchy->searchHash(hash,results);
}
bool DirectoryStorage::load(const std::string& local_file_name)
{
RS_STACK_MUTEX(mDirStorageMtx) ;
@ -295,6 +289,36 @@ bool DirectoryStorage::getIndexFromDirHash(const RsFileHash& hash,EntryIndex& in
/* Local Directory Storage */
/******************************************************************************************************************/
RsFileHash LocalDirectoryStorage::makeEncryptedHash(const RsFileHash& hash)
{
return RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES);
}
bool LocalDirectoryStorage::locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const
{
std::map<RsFileHash,RsFileHash>::const_iterator it = mEncryptedHashes.find(hash) ;
if(it == mEncryptedHashes.end())
return false ;
real_hash = it->second ;
return true ;
}
int LocalDirectoryStorage::searchHash(const RsFileHash& hash, RsFileHash& real_hash, EntryIndex& result) const
{
RS_STACK_MUTEX(mDirStorageMtx) ;
if(locked_findRealHash(hash,real_hash) && mFileHierarchy->searchHash(real_hash,result))
return true ;
if(mFileHierarchy->searchHash(hash,result))
{
real_hash.clear();
return true ;
}
return false ;
}
void LocalDirectoryStorage::setSharedDirectoryList(const std::list<SharedDirInfo>& lst)
{
RS_STACK_MUTEX(mDirStorageMtx) ;
@ -422,11 +446,13 @@ void LocalDirectoryStorage::updateTimeStamps()
std::cerr << "Updating recursive TS for local shared dirs..." << std::endl;
#endif
time_t last_modf_time = mFileHierarchy->recursUpdateLastModfTime(EntryIndex(0)) ;
bool unfinished_files_below ;
time_t last_modf_time = mFileHierarchy->recursUpdateLastModfTime(EntryIndex(0),unfinished_files_below) ;
mTSChanged = false ;
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago)" << std::endl;
std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago), unfinished files below=" << unfinished_files_below << std::endl;
#else
// remove unused variable warning
// variable is only used for debugging
@ -434,7 +460,15 @@ void LocalDirectoryStorage::updateTimeStamps()
#endif
}
}
bool LocalDirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash)
{
{
RS_STACK_MUTEX(mDirStorageMtx) ;
mEncryptedHashes[makeEncryptedHash(hash)] = hash ;
}
return mFileHierarchy->updateHash(index,hash);
}
std::string LocalDirectoryStorage::locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const
{
/**** MUST ALREADY BE LOCKED ****/
@ -724,7 +758,9 @@ RemoteDirectoryStorage::RemoteDirectoryStorage(const RsPeerId& pid,const std::st
{
load(fname) ;
std::cerr << "Loaded remote directory for peer " << pid << std::endl;
mLastSweepTime = time(NULL) - (RSRandom::random_u32() % DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP) ;
std::cerr << "Loaded remote directory for peer " << pid << ", inited last sweep time to " << time(NULL) - mLastSweepTime << " secs ago." << std::endl;
#ifdef DEBUG_REMOTE_DIRECTORY_STORAGE
mFileHierarchy->print();
#endif

View File

@ -53,7 +53,6 @@ class DirectoryStorage
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const ;
virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list<EntryIndex> &results) const ;
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ;
// gets/sets the various time stamps:
//
@ -140,7 +139,9 @@ class DirectoryStorage
// Updates relevant information for the file at the given index.
bool updateFile(const EntryIndex& index,const RsFileHash& hash, const std::string& fname, uint64_t size, time_t modf_time) ;
bool updateHash(const EntryIndex& index,const RsFileHash& hash);
// This is derived in LocalDirectoryStorage in order to also store H(H(F))
virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash);
// Returns the hash of the directory at the given index and reverse. This hash is set as random the first time it is used (when updating directories). It will be
// used by the sync system to designate the directory without referring to index (index could be used to figure out the existance of hidden directories)
@ -193,8 +194,15 @@ public:
*/
void checkSave() ;
/*!
* \brief lastSweepTime
* returns the last time a sweep has been done over the directory in order to check update TS.
* \return
*/
time_t& lastSweepTime() { return mLastSweepTime ; }
private:
time_t mLastSavedTime ;
time_t mLastSweepTime ;
bool mChanged ;
std::string mFileName;
};
@ -216,6 +224,20 @@ public:
void updateShareFlags(const SharedDirInfo& info) ;
bool convertSharedFilePath(const std::string& path_with_virtual_name,std::string& fullpath) ;
virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash);
/*!
* \brief searchHash
* Looks into local database of shared files for the given hash. Also looks for files such that the hash of the hash
* matches the given hash, and returns the real hash.
* \param hash hash to look for
* \param real_hash hash such that H(real_hash) = hash, or null hash if not found.
* \param results Entry index of the file that is found
* \return
* true is a file is found
* false otherwise.
*/
virtual int searchHash(const RsFileHash& hash, RsFileHash &real_hash, EntryIndex &results) const ;
/*!
* \brief updateTimeStamps
* Checks recursive TS and update the if needed.
@ -261,6 +283,8 @@ public:
bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ;
private:
static RsFileHash makeEncryptedHash(const RsFileHash& hash);
bool locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const;
std::string locked_getVirtualPath(EntryIndex indx) const ;
std::string locked_getVirtualDirName(EntryIndex indx) const ;
@ -268,6 +292,7 @@ private:
std::string locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const;
std::map<std::string,SharedDirInfo> mLocalDirs ; // map is better for search. it->first=it->second.filename
std::map<RsFileHash,RsFileHash> mEncryptedHashes; // map such that hash(it->second) = it->first
std::string mFileName;
bool mTSChanged ;

View File

@ -54,10 +54,10 @@ void LocalDirectoryUpdater::setEnabled(bool b)
if(mIsEnabled == b)
return ;
if(b)
start("fs dir updater") ;
else
if(!b)
shutdown();
else if(!isRunning())
start("fs dir updater") ;
mIsEnabled = b ;
}

View File

@ -28,7 +28,8 @@
static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 minutes
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. Buy we only update for real if something has changed.
static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed.
static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec.
static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time
static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files
@ -43,3 +44,8 @@ static const uint32_t MIN_INTERVAL_BETWEEN_REMOTE_DIRECTORY_SAVE = 23 ; //
static const uint32_t MAX_DIR_SYNC_RESPONSE_DATA_SIZE = 20000 ; // Maximum RsItem data size in bytes for serialised directory transmission
static const uint32_t DEFAULT_HASH_STORAGE_DURATION_DAYS = 30 ; // remember deleted/inaccessible files for 30 days
static const uint32_t NB_FRIEND_INDEX_BITS = 10 ; // Do not change this!
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not change this!
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change!
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min

View File

@ -46,11 +46,6 @@ static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_LOCAL_DIRS_CHANGED = 0x0002 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ;
static const uint32_t NB_FRIEND_INDEX_BITS = 10 ;
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ;
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer.
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 55 ; // every 55 secs, for debugging. Should be evey 10 minutes or so.
p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
: mServCtrl(mpeers), mFLSMtx("p3FileLists")
{
@ -209,7 +204,7 @@ int p3FileDatabase::tick()
for(uint32_t i=0;i<mRemoteDirectories.size();++i)
if(mRemoteDirectories[i] != NULL)
{
if(online_peers.find(mRemoteDirectories[i]->peerId()) != online_peers.end())
if(online_peers.find(mRemoteDirectories[i]->peerId()) != online_peers.end() && mRemoteDirectories[i]->lastSweepTime() + DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP < now)
{
#ifdef DEBUG_FILE_HIERARCHY
P3FILELISTS_DEBUG() << "Launching recurs sweep of friend directory " << mRemoteDirectories[i]->peerId() << ". Content currently is:" << std::endl;
@ -217,6 +212,7 @@ int p3FileDatabase::tick()
#endif
locked_recursSweepRemoteDirectory(mRemoteDirectories[i],mRemoteDirectories[i]->root(),0) ;
mRemoteDirectories[i]->lastSweepTime() = now ;
}
mRemoteDirectories[i]->checkSave() ;
@ -345,7 +341,7 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
/* for each item, check it exists ....
* - remove any that are dead (or flag?)
*/
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ;
static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_PERMISSIONS_MASK;
#ifdef DEBUG_FILE_HIERARCHY
P3FILELISTS_DEBUG() << "Load list" << std::endl;
@ -400,7 +396,6 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
info.virtualname = fi->file.name;
info.shareflags = FileStorageFlags(fi->flags) ;
info.shareflags &= PERMISSION_MASK ;
info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons
for(std::set<RsNodeGroupId>::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt)
info.parent_groups.push_back(*itt) ;
@ -498,7 +493,6 @@ void p3FileDatabase::cleanup()
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " removing pending request " << std::hex << it->first << std::dec << " for peer " << it->second.peer_id << ", because peer is offline or request is too old." << std::endl;
#endif
std::map<DirSyncRequestId,DirSyncRequestData>::iterator tmp(it);
++tmp;
mPendingSyncRequests.erase(it) ;
@ -543,7 +537,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid)
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl;
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl;
#endif
}
@ -570,7 +564,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid)
mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl;
P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl;
#endif
}
@ -644,17 +638,15 @@ void p3FileDatabase::requestDirUpdate(void *ref)
bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
FileSearchFlags flags ) const
{
RS_STACK_MUTEX(mFLSMtx);
result = NULL;
if (ref == NULL)
{
if(flags & RS_FILE_HINTS_LOCAL)
{
if(row != 0) return false;
if(row != 0)
return false ;
convertEntryIndexToPointer(0,0,result);
return true ;
}
else if((uint32_t)row < mRemoteDirectories.size())
@ -662,7 +654,8 @@ bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
convertEntryIndexToPointer(mRemoteDirectories[row]->root(),row+1,result);
return true;
}
else return false;
else
return false;
}
uint32_t fi;
@ -999,16 +992,20 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
if(hintflags & RS_FILE_HINTS_LOCAL)
{
std::list<EntryIndex> res;
mLocalSharedDirs->searchHash(hash,res) ;
RsFileHash real_hash ;
EntryIndex indx;
if(res.empty())
if(!mLocalSharedDirs->searchHash(hash,real_hash,indx))
return false;
EntryIndex indx = *res.begin() ; // no need to report duplicates
mLocalSharedDirs->getFileInfo(indx,info) ;
if(!real_hash.isNull())
{
info.hash = real_hash ;
info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ;
}
return true;
}
@ -1457,25 +1454,23 @@ void p3FileDatabase::locked_recursSweepRemoteDirectory(RemoteDirectoryStorage *r
p3FileDatabase::DirSyncRequestId p3FileDatabase::makeDirSyncReqId(const RsPeerId& peer_id,const RsFileHash& hash)
{
static uint64_t random_bias = RSRandom::random_u64();
uint64_t r = 0 ;
uint8_t mem[RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES];
memcpy(mem,peer_id.toByteArray(),RsPeerId::SIZE_IN_BYTES) ;
memcpy(&mem[RsPeerId::SIZE_IN_BYTES],hash.toByteArray(),RsFileHash::SIZE_IN_BYTES) ;
RsFileHash tmp = RsDirUtil::sha1sum(mem,RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES) ;
// This is kind of arbitrary. The important thing is that the same ID needs to be generated every time for a given (peer_id,entry index) pair, in a way
// that cannot be brute-forced or reverse-engineered, which explains the random bias and the usage of the hash, that is itself random.
for(uint32_t i=0;i<RsPeerId::SIZE_IN_BYTES;++i)
{
r ^= (0x011933ff92892a94 + peer_id.toByteArray()[i] * 0x1001fff92ee640f9) ;
r <<= 8 ;
r += 0xf392843890321808;
}
for(uint32_t i=0;i<RsFileHash::SIZE_IN_BYTES;++i)
{
r ^= (0x011933ff92892a94 + hash.toByteArray()[i] * 0x1001fff92ee640f9) ;
r <<= 8 ;
r += 0xf392843890321808;
}
uint64_t r = random_bias ^ *((uint64_t*)tmp.toByteArray()) ;
return r ^ random_bias;
#ifdef DEBUG_P3FILELISTS
std::cerr << "Creating ID " << std::hex << r << std::dec << " from peer id " << peer_id << " and hash " << hash << std::endl;
#endif
return r ;
}
bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *rds,const DirectoryStorage::EntryIndex& e)
@ -1525,7 +1520,7 @@ bool p3FileDatabase::locked_generateAndSendSyncRequest(RemoteDirectoryStorage *r
data.flags = item->flags;
#ifdef DEBUG_P3FILELISTS
P3FILELISTS_DEBUG() << " Pushing req in pending list with peer id " << data.peer_id << std::endl;
P3FILELISTS_DEBUG() << " Pushing req " << std::hex << sync_req_id << std::dec << " in pending list with peer id " << data.peer_id << std::endl;
#endif
mPendingSyncRequests[sync_req_id] = data ;

View File

@ -113,6 +113,7 @@ ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t f
{
_max_active_downloads = 5 ; // default queue size
_min_prioritized_transfers = 3 ;
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE;
/* TODO */
cnt = 0 ;
}
@ -580,7 +581,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
mTurtle->monitorTunnels(_queue[pos]->mHash,mFtServer,true) ;
mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,true);
}
if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED)
@ -589,7 +590,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
_queue[pos]->mCreator->closeFile() ;
if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
mTurtle->stopMonitoringTunnels(_queue[pos]->mHash) ;
mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,false);
}
}
@ -833,7 +834,7 @@ bool ftController::completeFile(const RsFileHash& hash)
mDownloads.erase(it);
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
mTurtle->stopMonitoringTunnels(hash_to_suppress) ;
mFtServer->activateTunnels(hash_to_suppress,mDefaultEncryptionPolicy,flags,false);
} // UNLOCK: RS_STACK_MUTEX(ctrlMutex);
@ -976,6 +977,21 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
if(alreadyHaveFile(hash, info))
return false ;
// the strategy for requesting encryption is the following:
//
// if policy is STRICT
// - disable clear, enforce encryption
// else
// - if not specified, use clear
//
if(mDefaultEncryptionPolicy == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)
{
flags |= RS_FILE_REQ_ENCRYPTED ;
flags &= ~RS_FILE_REQ_UNENCRYPTED ;
}
else if(!(flags & ( RS_FILE_REQ_ENCRYPTED | RS_FILE_REQ_UNENCRYPTED )))
flags |= RS_FILE_REQ_UNENCRYPTED ;
if(size == 0) // we treat this special case because
{
/* if no destpath - send to download directory */
@ -1172,7 +1188,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash
// We check that flags are consistent.
if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
mTurtle->monitorTunnels(hash,mFtServer,true) ;
mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,flags,true);
bool assume_availability = false;
@ -1273,7 +1289,7 @@ bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::Chunk
bool ftController::FileCancel(const RsFileHash& hash)
{
rsTurtle->stopMonitoringTunnels(hash) ;
mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,TransferRequestFlags(0),false);
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileCancel" << std::endl;
@ -1597,7 +1613,7 @@ bool ftController::FileDetails(const RsFileHash &hash, FileInfo &info)
info.queue_position = it->second->mQueuePosition ;
if(it->second->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING)
info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available.
info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ; // file being downloaded anonymously are always anonymously available.
/* get list of sources from transferModule */
std::list<RsPeerId> peerIds;
@ -1811,6 +1827,7 @@ const std::string download_dir_ss("DOWN_DIR");
const std::string partial_dir_ss("PART_DIR");
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
const std::string free_space_limit_ss("FREE_SPACE_LIMIT");
const std::string default_encryption_policy_ss("DEFAULT_ENCRYPTION_POLICY");
/* p3Config Interface */
@ -1858,6 +1875,8 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
break ;
}
configMap[default_encryption_policy_ss] = (mDefaultEncryptionPolicy==RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE)?"PERMISSIVE":"STRICT" ;
rs_sprintf(s, "%lu", RsDiscSpace::freeSpaceLimit());
configMap[free_space_limit_ss] = s ;
@ -2100,6 +2119,25 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
setPartialsDirectory(mit->second);
}
if (configMap.end() != (mit = configMap.find(default_encryption_policy_ss)))
{
if(mit->second == "STRICT")
{
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT ;
std::cerr << "Note: loading default value for encryption policy: STRICT" << std::endl;
}
else if(mit->second == "PERMISSIVE")
{
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
std::cerr << "Note: loading default value for encryption policy: PERMISSIVE" << std::endl;
}
else
{
std::cerr << "(EE) encryption policy not recognized: \"" << mit->second << "\"" << std::endl;
mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ;
}
}
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
{
if(mit->second == "STREAMING")
@ -2133,6 +2171,17 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
return true;
}
void ftController::setDefaultEncryptionPolicy(uint32_t p)
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
mDefaultEncryptionPolicy = p ;
IndicateConfigChanged();
}
uint32_t ftController::defaultEncryptionPolicy()
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
return mDefaultEncryptionPolicy ;
}
void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb)
{
RsDiscSpace::setFreeSpaceLimit(size_in_mb) ;

View File

@ -140,9 +140,11 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s);
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
void setDefaultEncryptionPolicy(uint32_t s);
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
uint32_t freeDiskSpaceLimit() const ;
void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
uint32_t defaultEncryptionPolicy();
bool FileCancel(const RsFileHash& hash);
bool FileControl(const RsFileHash& hash, uint32_t flags);
@ -237,6 +239,7 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C
ftServer *mFtServer ;
p3ServiceControl *mServiceCtrl;
uint32_t mFtServiceId;
uint32_t mDefaultEncryptionPolicy ;
uint32_t cnt ;
RsMutex ctrlMutex;

View File

@ -350,9 +350,10 @@ bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags*
// Now setup the file storage flags so that the client can know how to handle permissions
//
info.storage_permission_flags = DIR_FLAGS_BROWSABLE_OTHERS ;
#warning make sure this is right
info.storage_permission_flags = FileStorageFlags(0) ;//DIR_FLAGS_BROWSABLE_OTHERS ;
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ;
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
return true;
}

View File

@ -27,6 +27,8 @@
#include <time.h>
#include "util/rsdebug.h"
#include "util/rsdir.h"
#include "util/rsprint.h"
#include "crypto/chacha20.h"
#include "retroshare/rstypes.h"
#include "retroshare/rspeers.h"
const int ftserverzone = 29539;
@ -55,6 +57,9 @@ const int ftserverzone = 29539;
* #define SERVER_DEBUG_CACHE 1
***/
#define FTSERVER_DEBUG() std::cerr << time(NULL) << " : FILE_SERVER : " << __FUNCTION__ << " : "
#define FTSERVER_ERROR() std::cerr << "(EE) FILE_SERVER ERROR : "
static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds
/* Setup */
@ -240,7 +245,9 @@ bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info)
bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<RsPeerId>& srcIds)
{
std::cerr << "Requesting " << fname << std::endl ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "Requesting " << fname << std::endl ;
#endif
if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds))
return false ;
@ -248,6 +255,41 @@ bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uin
return true ;
}
bool ftServer::activateTunnels(const RsFileHash& hash,uint32_t encryption_policy,TransferRequestFlags flags,bool onoff)
{
RsFileHash hash_of_hash ;
encryptHash(hash,hash_of_hash) ;
mEncryptedHashes.insert(std::make_pair(hash_of_hash,hash)) ;
if(onoff)
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "Activating tunnels for hash " << hash << std::endl;
#endif
if(flags & RS_FILE_REQ_ENCRYPTED)
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl;
#endif
mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ;
}
if((flags & RS_FILE_REQ_UNENCRYPTED) && (encryption_policy != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT))
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl;
#endif
mTurtleRouter->monitorTunnels(hash,this,true) ;
}
}
else
{
mTurtleRouter->stopMonitoringTunnels(hash_of_hash);
mTurtleRouter->stopMonitoringTunnels(hash);
}
return true ;
}
bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name)
{
return mFtController->setDestinationName(hash,name);
@ -272,6 +314,14 @@ void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s)
{
mFtController->setDefaultChunkStrategy(s) ;
}
uint32_t ftServer::defaultEncryptionPolicy()
{
return mFtController->defaultEncryptionPolicy() ;
}
void ftServer::setDefaultEncryptionPolicy(uint32_t s)
{
mFtController->setDefaultEncryptionPolicy(s) ;
}
FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy()
{
return mFtController->defaultChunkStrategy() ;
@ -414,11 +464,11 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c
uint32_t rstype = getRsItemId(data);
#ifdef SERVER_DEBUG
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ;
#endif
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
{
std::cerr << " Wrong type !!" << std::endl ;
FTSERVER_ERROR() << " Wrong type !!" << std::endl ;
return NULL; /* wrong type */
}
@ -439,28 +489,94 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c
}
catch(std::exception& e)
{
std::cerr << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl;
FTSERVER_ERROR() << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl;
return NULL ;
}
}
bool ftServer::isEncryptedSource(const RsPeerId& virtual_peer_id)
{
RS_STACK_MUTEX(srvMutex) ;
return mEncryptedPeerIds.find(virtual_peer_id) != mEncryptedPeerIds.end();
}
void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir)
{
if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
mFtController->addFileSource(hash,virtual_peer_id) ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl;
#endif
RsFileHash real_hash ;
{
if(findRealHash(hash,real_hash))
{
RS_STACK_MUTEX(srvMutex) ;
mEncryptedPeerIds[virtual_peer_id] = hash ;
}
else
real_hash = hash;
}
if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl;
#endif
mFtController->addFileSource(real_hash,virtual_peer_id) ;
}
}
void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id)
{
RsFileHash real_hash ;
if(findRealHash(hash,real_hash))
mFtController->removeFileSource(real_hash,virtual_peer_id) ;
else
mFtController->removeFileSource(hash,virtual_peer_id) ;
RS_STACK_MUTEX(srvMutex) ;
mEncryptedPeerIds.erase(virtual_peer_id) ;
}
bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id)
{
FileInfo info ;
bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info);
RsFileHash real_hash ;
bool found = false ;
if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info))
if(FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info))
{
if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED)
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl;
#endif
RS_STACK_MUTEX(srvMutex) ;
mEncryptedHashes[hash] = info.hash;
real_hash = info.hash ;
}
else
real_hash = hash ;
found = true ;
}
else // try to see if we're already swarming the file
{
{
RS_STACK_MUTEX(srvMutex) ;
std::map<RsFileHash,RsFileHash>::const_iterator it = mEncryptedHashes.find(hash) ;
if(it != mEncryptedHashes.end())
real_hash = it->second ;
else
real_hash = hash ;
}
if(FileDetails(real_hash,RS_FILE_HINTS_DOWNLOAD,info))
{
// This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to
// share the file!
@ -470,31 +586,47 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i
for(uint32_t i=0;i<info2.chunks.size();++i)
if(info2.chunks[i] == FileChunksInfo::CHUNK_DONE)
{
res = true ;
found = true ;
if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING)
info.storage_permission_flags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; // this is to allow swarming
break ;
}
}
#ifdef SERVER_DEBUG
std::cerr << "ftServer: performing local hash search for hash " << hash << std::endl;
}
if(res)
if(found && mFtController->defaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash)
{
std::cerr << "Found hash: " << std::endl;
std::cerr << " hash = " << hash << std::endl;
std::cerr << " peer = " << peer_id << std::endl;
std::cerr << " flags = " << info.storage_permission_flags << std::endl;
std::cerr << " local = " << rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info) << std::endl;
std::cerr << " groups= " ; for(std::list<std::string>::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl;
std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl;
#ifdef SERVER_DEBUG
std::cerr << "(WW) rejecting file transfer for hash " << hash << " because the hash is not encrypted and encryption policy requires it." << std::endl;
#endif
return false ;
}
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl;
if(found)
{
FTSERVER_DEBUG() << "Found hash: " << std::endl;
FTSERVER_DEBUG() << " hash = " << real_hash << std::endl;
FTSERVER_DEBUG() << " peer = " << peer_id << std::endl;
FTSERVER_DEBUG() << " flags = " << info.storage_permission_flags << std::endl;
FTSERVER_DEBUG() << " groups= " ;
for(std::list<RsNodeGroupId>::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it)
FTSERVER_DEBUG() << (*it) << ", " ;
FTSERVER_DEBUG() << std::endl;
FTSERVER_DEBUG() << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl;
}
#endif
// The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE
// This is an additional computation cost, but the way it's written here, it's only called when res is true.
//
res = res && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ;
found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ;
return res ;
return found ;
}
/***************************************************************/
@ -599,7 +731,7 @@ bool ftServer::getSharedDirectories(std::list<SharedDirInfo> &dirs)
return true;
}
bool ftServer::setSharedDirectories(std::list<SharedDirInfo> &dirs)
bool ftServer::setSharedDirectories(const std::list<SharedDirInfo>& dirs)
{
mFileDatabase->setSharedDirectories(dirs);
return true;
@ -640,34 +772,27 @@ bool ftServer::removeSharedDirectory(std::string dir)
std::list<SharedDirInfo>::iterator it;
#ifdef SERVER_DEBUG
std::cerr << "ftServer::removeSharedDirectory(" << dir << ")";
std::cerr << std::endl;
FTSERVER_DEBUG() << "ftServer::removeSharedDirectory(" << dir << ")" << std::endl;
#endif
mFileDatabase->getSharedDirectories(dirList);
#ifdef SERVER_DEBUG
for(it = dirList.begin(); it != dirList.end(); ++it)
{
std::cerr << "ftServer::removeSharedDirectory()";
std::cerr << " existing: " << (*it).filename;
std::cerr << std::endl;
}
FTSERVER_DEBUG() << " existing: " << (*it).filename << std::endl;
#endif
for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ;
if(it == dirList.end())
{
std::cerr << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl;
FTSERVER_ERROR() << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl;
return false;
}
#ifdef SERVER_DEBUG
std::cerr << "ftServer::removeSharedDirectory()";
std::cerr << " Updating Directories";
std::cerr << std::endl;
FTSERVER_DEBUG() << " Updating Directories" << std::endl;
#endif
dirList.erase(it);
@ -703,7 +828,7 @@ bool ftServer::shareDownloadDirectory(bool share)
/* Share */
SharedDirInfo inf ;
inf.filename = mFtController->getDownloadDirectory();
inf.shareflags = DIR_FLAGS_NETWORK_WIDE_OTHERS ;
inf.shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
return addSharedDirectory(inf);
}
@ -728,11 +853,46 @@ bool ftServer::shareDownloadDirectory(bool share)
/********************** Data Flow **********************/
/***************************************************************/
bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item)
{
// we cannot look in the encrypted hash map, since the same hash--on this side of the FT--can be used with both
// encrypted and unencrypted peers ids. So the information comes from the virtual peer Id.
RsFileHash encrypted_hash;
if(findEncryptedHash(peerId,encrypted_hash))
{
// we encrypt the item
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using encrypted tunnel." << std::endl;
#endif
RsTurtleGenericDataItem *encrypted_item ;
if(!encryptItem(item, hash, encrypted_item))
return false ;
delete item ;
mTurtleRouter->sendTurtleData(peerId,encrypted_item) ;
}
else
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using non uncrypted tunnel." << std::endl;
#endif
mTurtleRouter->sendTurtleData(peerId,item) ;
}
return true ;
}
/* Client Send */
bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
FTSERVER_DEBUG() << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl;
#endif
if(mTurtleRouter->isTurtlePeer(peerId))
{
@ -741,7 +901,7 @@ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, u
item->chunk_offset = offset ;
item->chunk_size = chunksize ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -769,12 +929,12 @@ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, u
bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash,bool is_client)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
FTSERVER_DEBUG() << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl;
#endif
if(mTurtleRouter->isTurtlePeer(peerId))
{
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -798,13 +958,13 @@ bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash
bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const CompressedChunkMap& map,bool is_client)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
FTSERVER_DEBUG() << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl;
#endif
if(mTurtleRouter->isTurtlePeer(peerId))
{
RsTurtleFileMapItem *item = new RsTurtleFileMapItem ;
item->compressed_map = map ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -829,14 +989,14 @@ bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const
bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
FTSERVER_DEBUG() << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
#endif
if(mTurtleRouter->isTurtlePeer(peerId))
{
RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem;
item->chunk_number = chunk_number ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -860,7 +1020,7 @@ bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash
bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
FTSERVER_DEBUG() << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl;
#endif
if(mTurtleRouter->isTurtlePeer(peerId))
{
@ -868,7 +1028,7 @@ bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,
item->chunk_number = chunk_number ;
item->check_sum = crc ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -900,12 +1060,7 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t
uint32_t chunk;
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendData() to " << peerId << std::endl;
std::cerr << "hash: " << hash;
std::cerr << " offset: " << baseoffset;
std::cerr << " chunk: " << chunksize;
std::cerr << " data: " << data;
std::cerr << std::endl;
FTSERVER_DEBUG() << "ftServer::sendData() to " << peerId << ", hash: " << hash << " offset: " << baseoffset << " chunk: " << chunksize << " data: " << data << std::endl;
#endif
while(tosend > 0)
@ -939,7 +1094,7 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t
}
memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ;
mTurtleRouter->sendTurtleData(peerId,item) ;
sendTurtleItem(peerId,hash,item) ;
}
else
{
@ -965,12 +1120,7 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t
/* print the data pointer */
#ifdef SERVER_DEBUG
std::cerr << "ftServer::sendData() Packet: " << std::endl;
std::cerr << " offset: " << rfd->fd.file_offset;
std::cerr << " chunk: " << chunk;
std::cerr << " len: " << rfd->fd.binData.bin_len;
std::cerr << " data: " << rfd->fd.binData.bin_data;
std::cerr << std::endl;
FTSERVER_DEBUG() << "ftServer::sendData() Packet: " << " offset: " << rfd->fd.file_offset << " chunk: " << chunk << " len: " << rfd->fd.binData.bin_len << " data: " << rfd->fd.binData.bin_data << std::endl;
#endif
}
@ -984,6 +1134,240 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t
return true;
}
// Encrypts the given item using aead-chacha20-poly1305
//
// The format is the following
//
// [encryption format] [random initialization vector] [encrypted data size] [encrypted data] [authentication tag]
// 4 bytes 12 bytes 4 bytes variable 16 bytes
//
// +-------------------- authenticated data part ----------------------+
//
//
// Encryption format:
// ae ad 01 01 : encryption using AEAD, format 01 (authed with Poly1305 ), version 01
// ae ad 02 01 : encryption using AEAD, format 02 (authed with HMAC Sha256), version 01
//
//
void ftServer::deriveEncryptionKey(const RsFileHash& hash, uint8_t *key)
{
// The encryption key is simply the 256 hash of the
SHA256_CTX sha_ctx ;
if(SHA256_DIGEST_LENGTH != 32)
throw std::runtime_error("Warning: can't compute Sha1Sum with sum size != 32") ;
SHA256_Init(&sha_ctx);
SHA256_Update(&sha_ctx, hash.toByteArray(), hash.SIZE_IN_BYTES);
SHA256_Final (key, &sha_ctx);
}
static const uint32_t ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE = 12 ;
static const uint32_t ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE = 16 ;
static const uint32_t ENCRYPTED_FT_HEADER_SIZE = 4 ;
static const uint32_t ENCRYPTED_FT_EDATA_SIZE = 4 ;
static const uint8_t ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 = 0x01 ;
static const uint8_t ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 = 0x02 ;
bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item)
{
uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ;
RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "ftServer::Encrypting ft item." << std::endl;
FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl;
#endif
uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " clear part size : " << clear_item->serial_size() << std::endl;
FTSERVER_DEBUG() << " total item size : " << total_data_size << std::endl;
#endif
encrypted_item = new RsTurtleGenericDataItem ;
encrypted_item->data_bytes = rs_malloc( total_data_size ) ;
encrypted_item->data_size = total_data_size ;
if(encrypted_item->data_bytes == NULL)
return false ;
uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ;
uint32_t edata_size = clear_item->serial_size() ;
uint32_t offset = 0;
edata[0] = 0xae ;
edata[1] = 0xad ;
edata[2] = ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256
edata[3] = 0x01 ;
offset += ENCRYPTED_FT_HEADER_SIZE;
uint32_t aad_offset = offset ;
uint32_t aad_size = ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE ;
memcpy(&edata[offset], initialization_vector, ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ;
offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ;
edata[offset+0] = (edata_size >> 0) & 0xff ;
edata[offset+1] = (edata_size >> 8) & 0xff ;
edata[offset+2] = (edata_size >> 16) & 0xff ;
edata[offset+3] = (edata_size >> 24) & 0xff ;
offset += ENCRYPTED_FT_EDATA_SIZE ;
uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset);
clear_item->serialize(&edata[offset], ser_size);
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl;
#endif
uint32_t clear_item_offset = offset ;
offset += edata_size ;
uint32_t authentication_tag_offset = offset ;
assert(ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + offset == total_data_size) ;
uint8_t encryption_key[32] ;
deriveEncryptionKey(hash,encryption_key) ;
if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305)
librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ;
else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256)
librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ;
else
return false ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl;
FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl;
FTSERVER_DEBUG() << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl;
#endif
return true ;
}
// Decrypts the given item using aead-chacha20-poly1305
bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericTunnelItem *& decrypted_item)
{
uint8_t encryption_key[32] ;
deriveEncryptionKey(hash,encryption_key) ;
uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ;
uint32_t offset = 0;
if(encrypted_item->data_size < ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE) return false ;
if(edata[0] != 0xae) return false ;
if(edata[1] != 0xad) return false ;
if(edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 && edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) return false ;
if(edata[3] != 0x01) return false ;
offset += ENCRYPTED_FT_HEADER_SIZE ;
uint32_t aad_offset = offset ;
uint32_t aad_size = ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ;
uint8_t *initialization_vector = &edata[offset] ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "ftServer::decrypting ft item." << std::endl;
FTSERVER_DEBUG() << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl;
FTSERVER_DEBUG() << " hash : " << hash << std::endl;
FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl;
FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl;
#endif
offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ;
uint32_t edata_size = 0 ;
edata_size += ((uint32_t)edata[offset+0]) << 0 ;
edata_size += ((uint32_t)edata[offset+1]) << 8 ;
edata_size += ((uint32_t)edata[offset+2]) << 16 ;
edata_size += ((uint32_t)edata[offset+3]) << 24 ;
if(edata_size + ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE != encrypted_item->data_size)
{
FTSERVER_ERROR() << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl;
return false ;
}
offset += ENCRYPTED_FT_EDATA_SIZE ;
uint32_t clear_item_offset = offset ;
uint32_t authentication_tag_offset = offset + edata_size ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl;
#endif
bool result ;
if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305)
result = librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ;
else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256)
result = librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ;
else
return false ;
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << " authen. result : " << result << std::endl;
FTSERVER_DEBUG() << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl;
#endif
if(!result)
{
FTSERVER_ERROR() << "(EE) decryption/authentication went wrong." << std::endl;
return false ;
}
decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ;
if(decrypted_item == NULL)
return false ;
return true ;
}
bool ftServer::encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash)
{
hash_of_hash = RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES);
return true ;
}
bool ftServer::findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash)
{
RS_STACK_MUTEX(srvMutex);
std::map<RsPeerId,RsFileHash>::const_iterator it = mEncryptedPeerIds.find(virtual_peer_id) ;
if(it != mEncryptedPeerIds.end())
{
encrypted_hash = it->second ;
return true ;
}
else
return false ;
}
bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash)
{
RS_STACK_MUTEX(srvMutex);
std::map<RsFileHash,RsFileHash>::const_iterator it = mEncryptedHashes.find(hash) ;
if(it != mEncryptedHashes.end())
{
real_hash = it->second ;
return true ;
}
else
return false ;
}
// Dont delete the item. The client (p3turtle) is doing it after calling this.
//
void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
@ -991,6 +1375,33 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
const RsPeerId& virtual_peer_id,
RsTurtleGenericTunnelItem::Direction direction)
{
if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA)
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "Received encrypted data item. Trying to decrypt" << std::endl;
#endif
RsFileHash real_hash ;
if(!findRealHash(hash,real_hash))
{
FTSERVER_ERROR() << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl;
return ;
}
RsTurtleGenericTunnelItem *decrypted_item ;
if(!decryptItem(dynamic_cast<RsTurtleGenericDataItem *>(i),real_hash,decrypted_item))
{
FTSERVER_ERROR() << "(EE) decryption error." << std::endl;
return ;
}
receiveTurtleData(decrypted_item, real_hash, virtual_peer_id,direction) ;
delete decrypted_item ;
return ;
}
switch(i->PacketSubType())
{
case RS_TURTLE_SUBTYPE_FILE_REQUEST:
@ -999,7 +1410,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
if (item)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ;
}
@ -1012,7 +1423,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
if (item)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ;
@ -1028,7 +1439,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
if (item)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
}
@ -1039,7 +1450,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
{
//RsTurtleFileMapRequestItem *item = dynamic_cast<RsTurtleFileMapRequestItem *>(i) ;
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
}
@ -1051,7 +1462,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
if (item)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ;
}
@ -1064,14 +1475,14 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
if (item)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif
getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ;
}
}
break ;
default:
std::cerr << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast<void*>(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ;
FTSERVER_ERROR() << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast<void*>(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ;
}
}
@ -1107,9 +1518,6 @@ int ftServer::handleIncoming()
int nhandled = 0 ;
RsItem *item = NULL ;
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming() " << std::endl;
#endif
while(NULL != (item = recvItem()))
{
@ -1123,7 +1531,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl;
#endif
mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize);
}
@ -1136,7 +1544,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl;
#endif
mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data);
@ -1153,7 +1561,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl;
#endif
mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ;
}
@ -1166,7 +1574,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl;
#endif
mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ;
}
@ -1179,7 +1587,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl;
#endif
mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ;
}
@ -1192,7 +1600,7 @@ int ftServer::handleIncoming()
if (f)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl;
FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl;
#endif
mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum);
}

View File

@ -135,7 +135,8 @@ public:
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
virtual uint32_t freeDiskSpaceLimit() const ;
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ;
virtual void setDefaultEncryptionPolicy(uint32_t policy) ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
virtual uint32_t defaultEncryptionPolicy() ;
/***
* Control of Downloads Priority.
@ -156,6 +157,7 @@ public:
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info);
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ;
virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ;
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) ;
/***
@ -200,7 +202,7 @@ public:
virtual std::string getPartialsDirectory();
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs);
virtual bool setSharedDirectories(std::list<SharedDirInfo> &dirs);
virtual bool setSharedDirectories(const std::list<SharedDirInfo> &dirs);
virtual bool addSharedDirectory(const SharedDirInfo& dir);
virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist !
virtual bool removeSharedDirectory(std::string dir);
@ -217,6 +219,8 @@ public:
/*************** Data Transfer Interface ***********************/
/***************************************************************/
public:
virtual bool activateTunnels(const RsFileHash& hash,uint32_t default_encryption_policy,TransferRequestFlags flags,bool onoff);
virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize);
virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ;
@ -224,6 +228,11 @@ public:
virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ;
virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ;
static void deriveEncryptionKey(const RsFileHash& hash, uint8_t *key);
bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item);
bool decryptItem(RsTurtleGenericDataItem *encrypted_item, const RsFileHash& hash, RsTurtleGenericTunnelItem *&decrypted_item);
/*************** Internal Transfer Fns *************************/
virtual int tick();
@ -237,6 +246,22 @@ protected:
int handleIncoming() ;
bool handleCacheData() ;
/*!
* \brief sendTurtleItem
* Sends the given item into a turtle tunnel, possibly encrypting it if the type of tunnel requires it, which is known from the hash itself.
* \param peerId Peer id to send to (this is a virtual peer id from turtle service)
* \param hash hash of the file. If the item needs to be encrypted
* \param item item to send.
* \return
* true if everything goes right
*/
bool sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item);
// fnds out what is the real hash of encrypted hash hash
bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash);
bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash);
bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash);
private:
/**** INTERNAL FUNCTIONS ***/
@ -261,6 +286,9 @@ private:
std::string mConfigPath;
std::string mDownloadPath;
std::string mPartialsPath;
std::map<RsFileHash,RsFileHash> mEncryptedHashes ; // This map is such that sha1(it->second) = it->first
std::map<RsPeerId,RsFileHash> mEncryptedPeerIds ; // This map holds the hash to be used with each peer id
};

View File

@ -30,7 +30,7 @@
#include <serialiser/itempriorities.h>
#include <ft/ftturtlefiletransferitem.h>
uint32_t RsTurtleFileRequestItem::serial_size()
uint32_t RsTurtleFileRequestItem::serial_size() const
{
uint32_t s = 0 ;
@ -42,7 +42,7 @@ uint32_t RsTurtleFileRequestItem::serial_size()
return s ;
}
uint32_t RsTurtleFileDataItem::serial_size()
uint32_t RsTurtleFileDataItem::serial_size() const
{
uint32_t s = 0 ;
@ -55,7 +55,7 @@ uint32_t RsTurtleFileDataItem::serial_size()
return s ;
}
uint32_t RsTurtleFileMapRequestItem::serial_size()
uint32_t RsTurtleFileMapRequestItem::serial_size() const
{
uint32_t s = 0 ;
@ -66,7 +66,7 @@ uint32_t RsTurtleFileMapRequestItem::serial_size()
return s ;
}
uint32_t RsTurtleFileMapItem::serial_size()
uint32_t RsTurtleFileMapItem::serial_size() const
{
uint32_t s = 0 ;
@ -80,7 +80,7 @@ uint32_t RsTurtleFileMapItem::serial_size()
return s ;
}
uint32_t RsTurtleChunkCrcItem::serial_size()
uint32_t RsTurtleChunkCrcItem::serial_size() const
{
uint32_t s = 0 ;
@ -91,7 +91,7 @@ uint32_t RsTurtleChunkCrcItem::serial_size()
return s ;
}
uint32_t RsTurtleChunkCrcRequestItem::serial_size()
uint32_t RsTurtleChunkCrcRequestItem::serial_size() const
{
uint32_t s = 0 ;
@ -101,7 +101,7 @@ uint32_t RsTurtleChunkCrcRequestItem::serial_size()
return s ;
}
bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -134,7 +134,7 @@ bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize)
return ok;
}
bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -171,7 +171,7 @@ bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize)
return ok;
}
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) const
{
#ifdef P3TURTLE_DEBUG
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
@ -206,7 +206,7 @@ bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize)
return ok;
}
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize) const
{
#ifdef P3TURTLE_DEBUG
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
@ -345,7 +345,7 @@ RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pkt
throw std::runtime_error("Unknown error while deserializing.") ;
#endif
}
bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -459,7 +459,7 @@ RsTurtleFileDataItem::RsTurtleFileDataItem(void *data,uint32_t pktsize)
#endif
}
bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;

View File

@ -44,8 +44,8 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};
class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
@ -64,8 +64,8 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};
class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
@ -78,8 +78,8 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};
class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
@ -96,8 +96,8 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
@ -113,8 +113,8 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};
class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
@ -130,6 +130,6 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
Sha1CheckSum check_sum ;
virtual std::ostream& print(std::ostream& o, uint16_t) ;
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
};

View File

@ -294,7 +294,7 @@ mac {
OBJECTS_DIR = temp/obj
MOC_DIR = temp/moc
#DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW
DEFINES *= MINIUPNPC_VERSION=13
#DEFINES *= MINIUPNPC_VERSION=13
CONFIG += upnp_miniupnpc
CONFIG += c++11
@ -314,6 +314,7 @@ mac {
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
INCLUDEPATH += ../../../.
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
LIBS += /usr/local/lib/libsqlcipher.a
@ -379,6 +380,8 @@ HEADERS += ft/ftchunkmap.h \
ft/fttransfermodule.h \
ft/ftturtlefiletransferitem.h
HEADERS += crypto/chacha20.h
HEADERS += directory_updater.h \
directory_list.h \
p3filelists.h
@ -537,6 +540,8 @@ SOURCES += ft/ftchunkmap.cc \
ft/fttransfermodule.cc \
ft/ftturtlefiletransferitem.cc
SOURCES += crypto/chacha20.cpp
SOURCES += chat/distantchat.cc \
chat/p3chatservice.cc \
chat/distributedchat.cc \

View File

@ -64,6 +64,10 @@ static const int PQISTREAM_PACKET_SLICING_PROBE_DELAY = 60; // send every 6
static uint8_t PACKET_SLICING_PROBE_BYTES[8] = { 0x02, 0xaa, 0xbb, 0xcc, 0x00, 0x00, 0x00, 0x08 } ;
/* Change to true to disable packet slicing and/or packet grouping, if needed */
#define DISABLE_PACKET_SLICING false
#define DISABLE_PACKET_GROUPING false
/* This removes the print statements (which hammer pqidebug) */
/***
#define RSITEM_DEBUG 1
@ -629,7 +633,7 @@ int pqistreamer::handleoutgoing_locked()
++k ;
}
}
while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE ) ;
while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE && !DISABLE_PACKET_GROUPING) ;
#ifdef DEBUG_PQISTREAMER
if(k > 1)
@ -787,7 +791,7 @@ start_packet_read:
if(!memcmp(block,PACKET_SLICING_PROBE_BYTES,8))
{
mAcceptsPacketSlicing = true ;
mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING;
#ifdef DEBUG_PACKET_SLICING
std::cerr << "(II) Enabling packet slicing!" << std::endl;
#endif
@ -815,7 +819,7 @@ continue_packet:
#endif
is_partial_packet = true ;
mAcceptsPacketSlicing = true ; // this is needed
mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING; // this is needed
}
else
extralen = getRsItemSize(block) - blen; // old style packet type

View File

@ -43,6 +43,9 @@ const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100;
const uint32_t RS_FILE_CTRL_START = 0x00000200;
const uint32_t RS_FILE_CTRL_FORCE_CHECK = 0x00000400;
const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT = 0x00000001 ;
const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE = 0x00000002 ;
const uint32_t RS_FILE_RATE_TRICKLE = 0x00000001;
const uint32_t RS_FILE_RATE_SLOW = 0x00000002;
const uint32_t RS_FILE_RATE_STANDARD = 0x00000003;
@ -71,15 +74,18 @@ const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 );
const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 );
const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 );
const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network
const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// can be downloaded anonymously
const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends
const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out.
const FileSearchFlags RS_FILE_HINTS_SEARCHABLE ( 0x00000200 );// can be searched anonymously
const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000380 );// OR of the last tree flags. Used to filter out.
// Flags used when requesting a transfer
//
const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file.
const TransferRequestFlags RS_FILE_REQ_ENCRYPTED ( 0x00000080 ); // Asks for end-to-end encryption of file at the level of ftServer
const TransferRequestFlags RS_FILE_REQ_UNENCRYPTED ( 0x00000100 ); // Asks for no end-to-end encryption of file at the level of ftServer
const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Old stuff used for cache files. Not used anymore.
const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 );
const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 );
const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly.
@ -96,7 +102,7 @@ struct SharedDirInfo
{
std::string filename ;
std::string virtualname ;
FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ...
FileStorageFlags shareflags ; // combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ...
std::list<RsNodeGroupId> parent_groups ;
};
@ -141,6 +147,8 @@ class RsFiles
virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0;
virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0;
virtual bool FileClearCompleted() = 0;
virtual void setDefaultEncryptionPolicy(uint32_t policy)=0 ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE
virtual uint32_t defaultEncryptionPolicy()=0 ;
/***
* Control of Downloads Priority.
@ -159,6 +167,7 @@ class RsFiles
virtual void FileDownloads(std::list<RsFileHash> &hashs) = 0;
virtual bool FileUploads(std::list<RsFileHash> &hashs) = 0;
virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) = 0;
virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0;
/// Gives chunk details about the downloaded file with given hash.
virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) = 0 ;
@ -210,6 +219,7 @@ class RsFiles
virtual std::string getPartialsDirectory() = 0;
virtual bool getSharedDirectories(std::list<SharedDirInfo>& dirs) = 0;
virtual bool setSharedDirectories(const std::list<SharedDirInfo>& dirs) = 0;
virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0;
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
virtual bool removeSharedDirectory(std::string dir) = 0;

View File

@ -155,12 +155,13 @@ const FileStorageFlags DIR_FLAGS_PARENT ( 0x0001 );
const FileStorageFlags DIR_FLAGS_DETAILS ( 0x0002 ); // apparently unused
const FileStorageFlags DIR_FLAGS_CHILDREN ( 0x0004 ); // apparently unused
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_OTHERS ( 0x0080 ); // Flags for directory sharing permissions. The last
const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS ( 0x0100 ); // one should be the OR of the all four flags.
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS ( 0x0200 );
const FileStorageFlags DIR_FLAGS_BROWSABLE_GROUPS ( 0x0400 );
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_OTHERS
| DIR_FLAGS_NETWORK_WIDE_GROUPS | DIR_FLAGS_BROWSABLE_GROUPS );
const FileStorageFlags DIR_FLAGS_ANONYMOUS_DOWNLOAD ( 0x0080 ); // Flags for directory sharing permissions. The last
//const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS ( 0x0100 ); // one should be the OR of the all four flags.
//const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS ( 0x0200 );
const FileStorageFlags DIR_FLAGS_BROWSABLE ( 0x0400 );
const FileStorageFlags DIR_FLAGS_ANONYMOUS_SEARCH ( 0x0800 );
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_ANONYMOUS_DOWNLOAD | /*DIR_FLAGS_BROWSABLE_OTHERS
DIR_FLAGS_NETWORK_WIDE_GROUPS*/ DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_SEARCH);
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );

View File

@ -1359,7 +1359,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
// very simple algorithm.
//
bool found = false ;
bool found = directory_parent_groups.empty() ; // by default, empty list means browsable by everyone.
RsPgpId pgp_id = getGPGId(peer_ssl_id) ;
for(std::list<RsNodeGroupId>::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it)
@ -1378,13 +1378,15 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
// found = true ;
}
bool network_wide = (share_flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ;
bool browsable = (share_flags & DIR_FLAGS_BROWSABLE_OTHERS) || ( (share_flags & DIR_FLAGS_BROWSABLE_GROUPS) && found) ;
bool network_wide = (share_flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ;
bool browsable = (share_flags & DIR_FLAGS_BROWSABLE) && found ;
bool searchable = (share_flags & DIR_FLAGS_ANONYMOUS_SEARCH) ;
FileSearchFlags final_flags ;
if(network_wide) final_flags |= RS_FILE_HINTS_NETWORK_WIDE ;
if(browsable ) final_flags |= RS_FILE_HINTS_BROWSABLE ;
if(searchable ) final_flags |= RS_FILE_HINTS_SEARCHABLE ;
return final_flags ;
}

View File

@ -1729,7 +1729,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
std::cerr << "Performing rsFiles->search()" << std::endl ;
#endif
// now, search!
rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
#ifdef P3TURTLE_DEBUG
std::cerr << initialResults.size() << " matches found." << std::endl ;
@ -1767,7 +1767,7 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
return ;
// now, search!
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId());
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
result.clear() ;

View File

@ -16,7 +16,7 @@
// ---------------------------------- Packet sizes -----------------------------------//
//
uint32_t RsTurtleStringSearchRequestItem::serial_size()
uint32_t RsTurtleStringSearchRequestItem::serial_size() const
{
uint32_t s = 0 ;
@ -27,7 +27,7 @@ uint32_t RsTurtleStringSearchRequestItem::serial_size()
return s ;
}
uint32_t RsTurtleRegExpSearchRequestItem::serial_size()
uint32_t RsTurtleRegExpSearchRequestItem::serial_size() const
{
uint32_t s = 0 ;
@ -48,7 +48,7 @@ uint32_t RsTurtleRegExpSearchRequestItem::serial_size()
return s ;
}
uint32_t RsTurtleSearchResultItem::serial_size()
uint32_t RsTurtleSearchResultItem::serial_size()const
{
uint32_t s = 0 ;
@ -67,7 +67,7 @@ uint32_t RsTurtleSearchResultItem::serial_size()
return s ;
}
uint32_t RsTurtleOpenTunnelItem::serial_size()
uint32_t RsTurtleOpenTunnelItem::serial_size()const
{
uint32_t s = 0 ;
@ -80,7 +80,7 @@ uint32_t RsTurtleOpenTunnelItem::serial_size()
return s ;
}
uint32_t RsTurtleTunnelOkItem::serial_size()
uint32_t RsTurtleTunnelOkItem::serial_size() const
{
uint32_t s = 0 ;
@ -91,7 +91,7 @@ uint32_t RsTurtleTunnelOkItem::serial_size()
return s ;
}
uint32_t RsTurtleGenericDataItem::serial_size()
uint32_t RsTurtleGenericDataItem::serial_size() const
{
uint32_t s = 0 ;
@ -159,7 +159,7 @@ RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size)
}
bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -193,7 +193,7 @@ bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize)
return ok;
}
bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -313,7 +313,7 @@ RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint
#endif
}
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -398,7 +398,7 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize)
#endif
}
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -464,7 +464,7 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize)
#endif
}
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
@ -572,7 +572,7 @@ RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize)
#endif
}
bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize)
bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;

View File

@ -35,8 +35,8 @@ class RsTurtleItem: public RsItem
public:
RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {}
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
virtual bool serialize(void *data,uint32_t& size) const = 0 ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor
virtual void clear() {}
};
@ -63,8 +63,8 @@ class RsTurtleSearchResultItem: public RsTurtleItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
class RsTurtleSearchRequestItem: public RsTurtleItem
@ -92,8 +92,8 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
@ -109,8 +109,8 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
/***********************************************************************************/
@ -131,8 +131,8 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
class RsTurtleTunnelOkItem: public RsTurtleItem
@ -147,8 +147,8 @@ class RsTurtleTunnelOkItem: public RsTurtleItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
/***********************************************************************************/
@ -208,8 +208,8 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem
virtual std::ostream& print(std::ostream& o, uint16_t) ;
protected:
virtual bool serialize(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual bool serialize(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
};
/***********************************************************************************/

View File

@ -30,7 +30,17 @@
#include <iostream>
#include <time.h>
#ifdef __APPLE__
int __attribute__((weak)) pthread_setname_np(const char *__buf) ;
int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) {
return pthread_setname_np(__buf);
}
#else
int __attribute__((weak)) pthread_setname_np(pthread_t __target_thread, const char *__buf) ;
int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) {
return pthread_setname_np(__target_thread, __buf);
}
#endif
#ifdef RSMUTEX_DEBUG
#include <stdio.h>
@ -147,6 +157,11 @@ void RsTickingThread::fullstop()
void RsThread::start(const std::string &threadName)
{
if(isRunning())
{
std::cerr << "(EE) RsThread \"" << threadName << "\" is already running. Will not start twice!" << std::endl;
return ;
}
pthread_t tid;
void *data = (void *)this ;
@ -167,6 +182,7 @@ void RsThread::start(const std::string &threadName)
// set name
if(pthread_setname_np)
{
if(!threadName.empty())
{
// thread names are restricted to 16 characters including the terminating null byte
@ -175,9 +191,10 @@ void RsThread::start(const std::string &threadName)
#ifdef DEBUG_THREADS
THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl;
#endif
pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
RS_pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
} else {
pthread_setname_np(mTid, threadName.c_str());
RS_pthread_setname_np(mTid, threadName.c_str());
}
}
}
}

View File

@ -1,11 +1,7 @@
!include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri")
TEMPLATE = lib
macx {
CONFIG = staticlib
} else {
CONFIG += staticlib
}
DEFINES *= OPENSSL_NO_IDEA
@ -13,8 +9,8 @@ QMAKE_CXXFLAGS *= -Wall -Werror -W
TARGET = ops
DESTDIR = lib
DEPENDPATH += .
INCLUDEPATH += .
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
#################################### Windows #####################################
@ -34,9 +30,13 @@ win32 {
# Switch on optimization for debug version
#QMAKE_CXXFLAGS_DEBUG += -O2
#QMAKE_CFLAGS_DEBUG += -O2
}
DEPENDPATH += $$INC_DIR
INCLUDEPATH += $$INC_DIR
macx {
for(lib, LIB_DIR):LIBS += -L"$$lib"
for(bin, BIN_DIR):LIBS += -L"$$bin"
DEFINES += OPENSSL_NO_CAMELLIA
}
# Input
@ -73,8 +73,10 @@ HEADERS += openpgpsdk/writer.h \
openpgpsdk/armour.h \
openpgpsdk/parse_local.h \
openpgpsdk/keyring_local.h \
openpgpsdk/opsdir.h \
openpgpsdk/opsstring.h
openpgpsdk/opsdir.h
win32{
HEADERS += openpgpsdk/opsstring.h
}
SOURCES += openpgpsdk/accumulate.c \
openpgpsdk/compress.c \
@ -113,8 +115,10 @@ SOURCES += openpgpsdk/accumulate.c \
openpgpsdk/writer_memory.c \
openpgpsdk/writer_skey_checksum.c \
openpgpsdk/writer_stream_encrypt_se_ip.c \
openpgpsdk/opsdir.c \
openpgpsdk/opsstring.c
openpgpsdk/opsdir.c
win32{
SOURCES += openpgpsdk/opsstring.c
}
################################# Android #####################################

View File

@ -1,6 +1,7 @@
#include "opsdir.h"
#ifdef WIN32
#include "opsstring.h"
#endif
#include <fcntl.h>
int ops_open(const char* filename, int flag, int pmode)

View File

@ -1387,7 +1387,12 @@ QString TransfersDialog::getPeerName(const RsPeerId& id) const
// connect mgr). In such a case their id can suitably hold for a name.
//
if(res == "")
{
if(rsFiles->isEncryptedSource(id))
return tr("Anonymous end-to-end encrypted tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ;
else
return tr("Anonymous tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ;
}
else
return res ;
}

View File

@ -584,10 +584,13 @@ void GenCertDialog::genPerson()
QCoreApplication::processEvents();
QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance();
std::cout << "Waiting ed->processEvents()" << std::endl;
time_t waitEnd = time(NULL) + 10;//Wait no more than 10 sec to processEvents
if (ed->hasPendingEvents())
while(ed->processEvents(QEventLoop::AllEvents));
while(ed->processEvents(QEventLoop::AllEvents) && (time(NULL) < waitEnd));
std::string email_str = "" ;
std::cout << "RsAccounts::GeneratePGPCertificate" << std::endl;
RsAccounts::GeneratePGPCertificate(
ui.name_input->text().toUtf8().constData(),
email_str.c_str(),
@ -609,6 +612,7 @@ void GenCertDialog::genPerson()
std::cerr << "GenCertDialog::genPerson() Generating SSL cert with gpg id : " << PGPId << std::endl;
std::string err;
this->hide();//To show dialog asking password PGP Key.
std::cout << "RsAccounts::GenerateSSLCertificate" << std::endl;
bool okGen = RsAccounts::GenerateSSLCertificate(PGPId, "", genLoc, "", isHiddenLoc, sslPasswd, sslId, err);
if (okGen)

View File

@ -235,7 +235,7 @@ void QuickStartWizard::on_pushButtonSharesAdd_clicked()
{
SharedDirInfo sdi ;
sdi.filename = dir ;
sdi.shareflags = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS ;
sdi.shareflags = DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
rsFiles->addSharedDirectory(sdi);
@ -331,8 +331,8 @@ void QuickStartWizard::loadShare()
QCheckBox *cb1 = new QCheckBox ;
QCheckBox *cb2 = new QCheckBox ;
cb1->setChecked( (*it).shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS ) ;
cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE_OTHERS ) ;
cb1->setChecked( (*it).shareflags & DIR_FLAGS_ANONYMOUS_DOWNLOAD ) ;
cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE ) ;
cb1->setToolTip(tr("If checked, the share is anonymously shared to anybody.")) ;
cb2->setToolTip(tr("If checked, the share is browsable by your friends.")) ;
@ -364,8 +364,8 @@ void QuickStartWizard::updateFlags(bool b)
{
std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
FileStorageFlags current_flags(0u) ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_NETWORK_WIDE_OTHERS:(FileStorageFlags)0u ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE_OTHERS :(FileStorageFlags)0u ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_ANONYMOUS_DOWNLOAD:(FileStorageFlags)0u ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE :(FileStorageFlags)0u ;
if( ((*it).shareflags ^ current_flags).toUInt32() )
{

View File

@ -30,6 +30,7 @@
#include <gui/common/RsUrlHandler.h>
#include <gui/common/FilesDefs.h>
#include <gui/common/GroupDefs.h>
#include <gui/gxs/GxsIdDetails.h>
#include "RemoteDirModel.h"
#include <retroshare/rsfiles.h>
#include <retroshare/rstypes.h>
@ -216,16 +217,21 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags)
{
char str[11] = "- - -" ;
if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ;
//if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[3] = 'N' ;
if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[3] = 'B' ;
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[6] = 'N' ;
if(flags & DIR_FLAGS_BROWSABLE) str[0] = 'B' ;
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH) str[3] = 'S' ;
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) str[6] = 'N' ;
return QString(str) ;
}
QString RetroshareDirModel::getGroupsString(const std::list<RsNodeGroupId>& group_ids)
QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::list<RsNodeGroupId>& group_ids)
{
QString groups_str ;
if(!(flags & DIR_FLAGS_BROWSABLE))
return QString();
if(group_ids.empty())
return tr("[All friend nodes]") ;
QString groups_str = tr("Only ");
RsGroupInfo group_info ;
for(std::list<RsNodeGroupId>::const_iterator it(group_ids.begin());it!=group_ids.end();)
@ -271,8 +277,55 @@ QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) con
return ret;
}
const QIcon& RetroshareDirModel::getFlagsIcon(FileStorageFlags flags)
{
static QIcon *static_icons[8] = {NULL};
int n=0;
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) n += 1 ;
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH ) n += 2 ;
if(flags & DIR_FLAGS_BROWSABLE ) n += 4 ;
n-= 1;
if(static_icons[n] == NULL)
{
QList<QIcon> icons ;
if(flags & DIR_FLAGS_ANONYMOUS_SEARCH)
icons.push_back(QIcon(":icons/search_red_128.png")) ;
else
icons.push_back(QIcon(":icons/void_128.png")) ;
if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD)
icons.push_back(QIcon(":icons/anonymous_blue_128.png")) ;
else
icons.push_back(QIcon(":icons/void_128.png")) ;
if(flags & DIR_FLAGS_BROWSABLE)
icons.push_back(QIcon(":icons/browsable_green_128.png")) ;
else
icons.push_back(QIcon(":icons/void_128.png")) ;
QPixmap pix ;
GxsIdDetails::GenerateCombinedPixmap(pix, icons, 128);
static_icons[n] = new QIcon(pix);
std::cerr << "Generated icon for flags " << std::hex << flags << std::endl;
}
return *static_icons[n] ;
}
QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const
{
if(coln == 3)
{
if(details.type == DIR_TYPE_PERSON) return QVariant() ;
return getFlagsIcon(details.flags) ;
}
if(coln > 0)
return QVariant() ;
@ -352,16 +405,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
case 2:
return misc::userFriendlyDuration(details.min_age);
case 3:
return getFlagsString(details.flags);
// case 4:
// {
// QString ind("");
// if (ageIndicator != IND_ALWAYS)
// ind = getAgeIndicatorString(details);
// return ind;
// }
return QVariant();
case 4:
return getGroupsString(details.parent_groups) ;
return getGroupsString(details.flags,details.parent_groups) ;
default:
return tr("FILE");
@ -383,9 +429,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
case 2:
return misc::userFriendlyDuration(details.min_age);
case 3:
return getFlagsString(details.flags);
return QVariant();
case 4:
return getGroupsString(details.parent_groups) ;
return getGroupsString(details.flags,details.parent_groups) ;
default:
return tr("DIR");
@ -663,12 +709,12 @@ QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int
if (RemoteMode)
return tr("Friend");
else
return tr("Share Flags");
return tr("Access");
case 4:
if (RemoteMode)
return tr("What's new");
else
return tr("Groups");
return tr("Visibility");
}
return QString("Column %1").arg(section);
}

View File

@ -94,9 +94,10 @@ class RetroshareDirModel : public QAbstractItemModel
void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen);
static QString getFlagsString(FileStorageFlags f) ;
static QString getGroupsString(const std::list<RsNodeGroupId> &) ;
static QString getGroupsString(FileStorageFlags flags, const std::list<RsNodeGroupId> &) ;
QString getAgeIndicatorString(const DirDetails &) const;
// void getAgeIndicatorRec(const DirDetails &details, QString &ret) const;
static const QIcon& getFlagsIcon(FileStorageFlags flags) ;
virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0;

View File

@ -1587,46 +1587,8 @@ void RSLinkClipboard::parseClipboard(QList<RetroShareLink> &links)
{
// parse clipboard for links.
//
links.clear();
QString text = QApplication::clipboard()->text() ;
std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ;
QRegExp rx(QString("retroshare://(%1)[^\r\n]+").arg(HOST_REGEXP));
int pos = 0;
while((pos = rx.indexIn(text, pos)) != -1)
{
QString url(text.mid(pos, rx.matchedLength()));
RetroShareLink link(url);
if(link.valid())
{
// check that the link is not already in the list:
bool already = false ;
for (int i = 0; i <links.size(); ++i)
if(links[i] == link)
{
already = true ;
break ;
}
if(!already)
{
links.push_back(link) ;
#ifdef DEBUG_RSLINK
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
#endif
}
}
#ifdef DEBUG_RSLINK
else
std::cerr << "invalid link" << std::endl ;
#endif
pos += rx.matchedLength();
}
parseText(text, links);
}
QString RSLinkClipboard::toString()
@ -1690,3 +1652,46 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /* = RetroShareLink::T
return RetroShareLink::process(linksToProcess, flag);
}
void RSLinkClipboard::parseText(QString text, QList<RetroShareLink> &links)
{
links.clear();
std::cerr << "Parsing text:" << text.toStdString() << std::endl ;
QRegExp rx(QString("retroshare://(%1)[^\r\n]+").arg(HOST_REGEXP));
int pos = 0;
while((pos = rx.indexIn(text, pos)) != -1)
{
QString url(text.mid(pos, rx.matchedLength()));
RetroShareLink link(url);
if(link.valid())
{
// check that the link is not already in the list:
bool already = false ;
for (int i = 0; i <links.size(); ++i)
if(links[i] == link)
{
already = true ;
break ;
}
if(!already)
{
links.push_back(link) ;
#ifdef DEBUG_RSLINK
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
#endif
}
}
#ifdef DEBUG_RSLINK
else
std::cerr << "invalid link" << std::endl ;
#endif
pos += rx.matchedLength();
}
}

View File

@ -208,6 +208,8 @@ class RSLinkClipboard
//
static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
static void parseText(QString text, QList<RetroShareLink> &links) ;
private:
static void parseClipboard(QList<RetroShareLink> &links) ;
};

View File

@ -57,7 +57,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent)
hb2->addWidget(new QLabel(tr("Share flags and groups:")+" ")) ;
groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ;
groupflagsbox->setFlags(DIR_FLAGS_NETWORK_WIDE_OTHERS) ; // default value
groupflagsbox->setFlags(DIR_FLAGS_ANONYMOUS_DOWNLOAD) ; // default value
messageBox = new QTextEdit(ui.shareflags_GB) ;
messageBox->setReadOnly(true) ;

View File

@ -34,7 +34,8 @@
#include "ShareManager.h"
#include "ShareDialog.h"
#include "settings/rsharesettings.h"
#include <gui/common/GroupFlagsWidget.h>
#include "gui/common/GroupFlagsWidget.h"
#include "gui/common/GroupSelectionBox.h"
#include "gui/common/GroupDefs.h"
#include "gui/notifyqt.h"
#include "util/QtVersion.h"
@ -61,33 +62,83 @@ ShareManager::ShareManager()
ui.headerFrame->setHeaderText(tr("Share Manager"));
isLoading = false;
load();
Settings->loadWidgetInformation(this);
connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( showShareDialog() ) );
connect(ui.editButton, SIGNAL(clicked( bool ) ), this , SLOT( editShareDirectory() ) );
connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) );
connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( addShare() ) );
connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(applyAndClose()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint)));
connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int)));
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCustomPopupMenu(QPoint)));
connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int)));
connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int)));
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(updateGroups()));
ui.editButton->setEnabled(false);
ui.removeButton->setEnabled(false);
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload()));
QHeaderView* header = ui.shareddirList->horizontalHeader();
QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch);
//header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed);
//header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed);
header->setHighlightSections(false);
setAcceptDrops(true);
setAttribute(Qt::WA_DeleteOnClose, true);
reload();
}
void ShareManager::handleCellChange(int row,int column)
{
if(isLoading)
return ;
if(column == COLUMN_VIRTUALNAME)
{
// check if the thing already exists
for(uint32_t i=0;i<mDirInfos.size();++i)
if(i != (uint32_t)row && (mDirInfos[row].virtualname == std::string(ui.shareddirList->item(i,COLUMN_VIRTUALNAME)->text().toUtf8())))
{
ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->setText(QString::fromUtf8(mDirInfos[row].virtualname.c_str())) ;
return ;
}
mDirInfos[row].virtualname = std::string(ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->text().toUtf8()) ;
}
}
void ShareManager::editShareDirectory()
{
QTableWidget *listWidget = ui.shareddirList;
int row = listWidget -> currentRow();
doubleClickedCell(row,COLUMN_PATH) ;
}
void ShareManager::doubleClickedCell(int row,int column)
{
if(column == COLUMN_PATH)
{
QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Choose directory"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly);
if(!dirname.isNull())
{
std::string new_name( dirname.toUtf8() );
for(uint32_t i=0;i<mDirInfos.size();++i)
if(mDirInfos[row].filename == new_name)
return ;
mDirInfos[row].filename = new_name ;
load();
}
}
else if(column == COLUMN_GROUPS)
{
std::list<RsNodeGroupId> selected_groups = GroupSelectionDialog::selectGroups(mDirInfos[row].parent_groups) ;
mDirInfos[row].parent_groups = selected_groups ;
load();
}
}
ShareManager::~ShareManager()
@ -97,15 +148,25 @@ ShareManager::~ShareManager()
Settings->saveWidgetInformation(this);
}
void ShareManager::cancel()
{
close();
}
void ShareManager::applyAndClose()
{
// std::cerr << "ShareManager:::close(): updating!" << std::endl;
// This is the only place where we change things.
std::list<SharedDirInfo> infos ;
for(uint32_t i=0;i<mDirInfos.size();++i)
infos.push_back(mDirInfos[i]) ;
rsFiles->setSharedDirectories(infos) ;
updateFlags() ;
close() ;
}
void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ )
void ShareManager::shareddirListCustomPopupMenu( QPoint /*point*/ )
{
QMenu contextMnu( this );
@ -121,6 +182,19 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ )
contextMnu.exec(QCursor::pos());
}
void ShareManager::reload()
{
std::list<SharedDirInfo> dirs ;
rsFiles->getSharedDirectories(dirs) ;
mDirInfos.clear();
for(std::list<SharedDirInfo>::const_iterator it(dirs.begin());it!=dirs.end();++it)
mDirInfos.push_back(*it) ;
load();
}
/** Loads the settings for this page */
void ShareManager::load()
{
@ -128,25 +202,19 @@ void ShareManager::load()
return ;
isLoading = true;
// std::cerr << "ShareManager:: In load !!!!!" << std::endl ;
std::list<SharedDirInfo>::const_iterator it;
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
/* get a link to the table */
QTableWidget *listWidget = ui.shareddirList;
/* set new row count */
listWidget->setRowCount(dirs.size());
listWidget->setRowCount(mDirInfos.size());
int row=0 ;
for(it = dirs.begin(); it != dirs.end(); ++it,++row)
for(uint32_t row=0;row<mDirInfos.size();++row)
{
listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8((*it).filename.c_str())));
listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8((*it).virtualname.c_str())));
listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].filename.c_str())));
listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].virtualname.c_str())));
GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,(*it).shareflags);
GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,mDirInfos[row].shareflags);
listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0);
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
@ -154,18 +222,26 @@ void ShareManager::load()
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ;
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
//connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
listWidget->item(row,COLUMN_PATH)->setToolTip(tr("Double click to change shared directory path")) ;
listWidget->item(row,COLUMN_GROUPS)->setToolTip(tr("Double click to select which groups of friends can see the files")) ;
listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the name that friends will see")) ;
listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups));
QFont font = listWidget->item(row,COLUMN_GROUPS)->font();
font.setBold(mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE) ;
listWidget->item(row,COLUMN_GROUPS)->setTextColor( (mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE)? (Qt::black):(Qt::lightGray)) ;
listWidget->item(row,COLUMN_GROUPS)->setFont(font);
}
listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ;
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
listWidget->update(); /* update display */
update();
isLoading = false ;
updateGroups();
}
void ShareManager::showYourself()
@ -173,6 +249,7 @@ void ShareManager::showYourself()
if(_instance == NULL)
_instance = new ShareManager() ;
_instance->reload() ;
_instance->show() ;
_instance->activateWindow();
}
@ -184,109 +261,39 @@ void ShareManager::showYourself()
}
if (update_local) {
_instance->load();
_instance->reload();
}
}
void ShareManager::updateFlags()
{
if(isLoading)
return ;
isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check
// what has changed => fail!
// std::cerr << "Updating flags" << std::endl;
std::list<SharedDirInfo>::iterator it;
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
std::map<QString, FileStorageFlags> mapped_flags ;
for(int row=0;row<ui.shareddirList->rowCount();++row)
{
QString dirpath = ui.shareddirList->item(row,COLUMN_PATH)->text() ;
FileStorageFlags flags = (dynamic_cast<GroupFlagsWidget*>(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ;
mapped_flags[dirpath] = flags ;
// std::cerr << "Getting new flags " << flags << " for path " << dirpath.toStdString() << std::endl;
mDirInfos[row].shareflags = flags ;
}
for(std::list<SharedDirInfo>::iterator it(dirs.begin());it!=dirs.end();++it)
{
FileStorageFlags newf = mapped_flags[QString::fromUtf8((*it).filename.c_str())] ;
if( (*it).shareflags != newf )
{
(*it).shareflags = newf ;
rsFiles->updateShareFlags(*it) ; // modifies the flags
// std::cerr << "Updating flags to " << newf << " for dir " << (*it).filename << std::endl ;
}
}
isLoading = false ; // re-enable GUI load
load() ; // update the GUI.
}
void ShareManager::updateGroups()
QString ShareManager::getGroupString(const std::list<RsNodeGroupId>& groups)
{
if(isLoading)
return ;
if(groups.empty())
return tr("[All friend nodes]") ;
// std::cerr << "Updating groups" << std::endl;
std::list<SharedDirInfo>::iterator it;
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
int row=0 ;
for(it = dirs.begin(); it != dirs.end(); ++it,++row)
{
QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_GROUPS);
QString group_string;
int n = 0;
for (std::list<RsNodeGroupId>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n)
QString group_string ;
for (std::list<RsNodeGroupId>::const_iterator it(groups.begin());it!=groups.end();++it,++n)
{
if (n>0)
group_string += ", " ;
RsGroupInfo groupInfo;
rsPeers->getGroupInfo(*it2, groupInfo);
rsPeers->getGroupInfo(*it, groupInfo);
group_string += GroupDefs::name(groupInfo);
}
item->setText(group_string);
}
}
void ShareManager::editShareDirectory()
{
/* id current dir */
int row = ui.shareddirList->currentRow();
QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH);
if (item) {
std::string filename = item->text().toUtf8().constData();
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
std::list<SharedDirInfo>::const_iterator it;
for (it = dirs.begin(); it != dirs.end(); ++it) {
if (it->filename == filename) {
/* file name found, show dialog */
ShareDialog sharedlg (it->filename, this);
sharedlg.setWindowTitle(tr("Edit Shared Folder"));
sharedlg.exec();
load();
break;
}
}
}
return group_string ;
}
void ShareManager::removeShareDirectory()
@ -301,7 +308,10 @@ void ShareManager::removeShareDirectory()
{
if ((QMessageBox::question(this, tr("Warning!"),tr("Do you really want to stop sharing this directory ?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes)
{
rsFiles->removeSharedDirectory( qdir->text().toUtf8().constData());
for(uint32_t i=row;i+1<mDirInfos.size();++i)
mDirInfos[i] = mDirInfos[i+1] ;
mDirInfos.pop_back() ;
load();
}
}
@ -315,6 +325,30 @@ void ShareManager::showEvent(QShowEvent *event)
}
}
void ShareManager::addShare()
{
QString fname = QFileDialog::getExistingDirectory(NULL,tr("Choose a directory to share"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly);
if(fname.isNull())
return;
std::string dir_name ( fname.toUtf8() );
// check that the directory does not already exist
for(uint32_t i=0;i<mDirInfos.size();++i)
if(mDirInfos[i].filename == dir_name)
return ;
mDirInfos.push_back(SharedDirInfo());
mDirInfos.back().filename = dir_name ;
mDirInfos.back().virtualname = std::string();
mDirInfos.back().shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_ANONYMOUS_SEARCH;
mDirInfos.back().parent_groups.clear();
load();
}
void ShareManager::showShareDialog()
{
ShareDialog sharedlg ("", this);
@ -327,14 +361,6 @@ void ShareManager::shareddirListCurrentCellChanged(int currentRow, int currentCo
Q_UNUSED(currentColumn);
Q_UNUSED(previousRow);
Q_UNUSED(previousColumn);
if (currentRow >= 0) {
ui.editButton->setEnabled(true);
ui.removeButton->setEnabled(true);
} else {
ui.editButton->setEnabled(false);
ui.removeButton->setEnabled(false);
}
}
void ShareManager::dragEnterEvent(QDragEnterEvent *event)

View File

@ -26,6 +26,7 @@
#include <QDialog>
#include <QFileDialog>
#include <retroshare/rsfiles.h>
#include "ui_ShareManager.h"
class ShareManager : public QDialog
@ -54,15 +55,20 @@ protected:
private slots:
/** Create the context popup menu and it's submenus */
void shareddirListCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
void shareddirListCostumPopupMenu( QPoint point );
void shareddirListCustomPopupMenu( QPoint point );
void addShare();
void doubleClickedCell(int,int);
void handleCellChange(int row,int column);
void editShareDirectory();
void showShareDialog();
void editShareDirectory();
void removeShareDirectory();
void updateFlags();
void updateGroups();
void applyAndClose() ;
void cancel() ;
void reload() ;
static QString getGroupString(const std::list<RsNodeGroupId>& groups);
private:
static ShareManager *_instance;
bool isLoading;
@ -72,6 +78,8 @@ private:
/** Qt Designer generated object */
Ui::ShareManager ui;
std::vector<SharedDirInfo> mDirInfos ;
};
#endif

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>741</width>
<width>1210</width>
<height>334</height>
</rect>
</property>
@ -18,7 +18,16 @@
<normaloff>:/images/logo/logo_16.png</normaloff>:/images/logo/logo_16.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
@ -49,7 +58,7 @@
<property name="topMargin">
<number>6</number>
</property>
<item row="1" column="0" colspan="6">
<item row="1" column="0" colspan="4">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Shared Folder Manager</string>
@ -64,7 +73,7 @@
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::DoubleClicked</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
@ -92,17 +101,17 @@
</attribute>
<column>
<property name="text">
<string>Directory</string>
<string>Shared directory</string>
</property>
</column>
<column>
<property name="text">
<string>Virtual Folder</string>
<string>Visible name</string>
</property>
</column>
<column>
<property name="text">
<string>Share flags</string>
<string>Access</string>
</property>
<property name="toolTip">
<string comment="If activated, the share is anonymously accessible to anybody"/>
@ -110,7 +119,7 @@
</column>
<column>
<property name="text">
<string>Groups</string>
<string>Visibility</string>
</property>
<property name="toolTip">
<string comment="If checked, the share is browsable by your friends"/>
@ -139,7 +148,7 @@
<string>Add a Share Directory</string>
</property>
<property name="text">
<string>Add</string>
<string>Add new</string>
</property>
<property name="iconSize">
<size>
@ -149,35 +158,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="removeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="toolTip">
<string>Stop sharing selected Directory</string>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item row="2" column="3">
<item row="2" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -190,24 +171,14 @@
</property>
</spacer>
</item>
<item row="2" column="4">
<item row="2" column="2">
<widget class="QPushButton" name="closeButton">
<property name="text">
<string>Apply and close</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="editButton">
<property name="toolTip">
<string>Edit selected Shared Directory</string>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<item row="0" column="0" colspan="3">
<widget class="StyledLabel" name="labelInstructions">
<property name="palette">
<palette>
@ -290,6 +261,13 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -25,8 +25,10 @@
#include <QTreeView>
#include <QClipboard>
#include <QMenu>
#include <QPainter>
#include <QProcess>
#include <QSortFilterProxyModel>
#include <QStyledItemDelegate>
#include "SharedFilesDialog.h"
#include "settings/AddFileAssociationDialog.h"
@ -114,6 +116,36 @@ private:
RetroshareDirModel *m_dirModel;
};
// This class allows to draw the item in the share flags column using an appropriate size
class ShareFlagsItemDelegate: public QStyledItemDelegate
{
public:
ShareFlagsItemDelegate() {}
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_ASSERT(index.isValid());
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);
// disable default icon
opt.icon = QIcon();
// draw default item
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
const QRect r = option.rect;
// get pixmap
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
QPixmap pix = icon.pixmap(r.size());
// draw pixmap at center of item
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
painter->drawPixmap(r.topLeft() + p, pix);
}
};
/** Constructor */
SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareDirModel *_flat_model,QWidget *parent)
: RsAutoUpdatePage(1000,parent),model(NULL)
@ -221,6 +253,8 @@ LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent)
connect(editshareAct, SIGNAL(triggered()), this, SLOT(editSharePermissions())) ;
ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ;
ui.dirTreeView->setItemDelegateForColumn(COLUMN_FRIEND,new ShareFlagsItemDelegate()) ;
}
RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent)
@ -232,6 +266,7 @@ RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent)
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadRemoteSelected()));
connect(ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), this, SLOT( expanded(const QModelIndex & ) ) );
connect(ui.dirTreeView, SIGNAL( doubleClicked(const QModelIndex & ) ), this, SLOT( expanded(const QModelIndex & ) ) );
// load settings
processSettings(true);

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>737</width>
<width>1156</width>
<height>402</height>
</rect>
</property>
@ -86,7 +86,7 @@
<item>
<widget class="QPushButton" name="addShares_PB">
<property name="text">
<string>Add Share</string>
<string>Configure shared directories</string>
</property>
<property name="icon">
<iconset resource="images.qrc">

View File

@ -34,6 +34,7 @@
#include "util/HandleRichText.h"
static QHash<QString, QString> Smileys;
static QVector<QString> order;
void Emoticons::load()
{
@ -115,6 +116,7 @@ void Emoticons::load()
} else {
Smileys.insert(smcode, smfile);
}
order.append(smcode);
}
}
@ -174,15 +176,15 @@ void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *s
x = 0;
y = 0;
QHashIterator<QString, QString> i(Smileys);
QVectorIterator<QString> i(order);
while(i.hasNext())
{
i.next();
QString key = i.next();
QPushButton *smButton = new QPushButton("", smWidget);
smButton->setGeometry(x*buttonWidth, y*buttonHeight, buttonWidth, buttonHeight);
smButton->setIconSize(QSize(buttonWidth, buttonHeight));
smButton->setIcon(QPixmap(i.value()));
smButton->setToolTip(i.key());
smButton->setIcon(QPixmap(Smileys.value(key)));
smButton->setToolTip(key);
smButton->setStyleSheet("QPushButton:hover {border: 3px solid white; border-radius: 2px;}");
smButton->setFlat(true);
++x;

View File

@ -3,31 +3,26 @@
#include "GroupFlagsWidget.h"
#include <retroshare/rsfiles.h>
#define FLAGS_GROUP_NETWORK_WIDE_ICON ":images/anonymous_128_green.png"
#define FLAGS_GROUP_BROWSABLE_ICON ":images/browsable_128_green.png"
#define FLAGS_GROUP_UNCHECKED ":images/blank_128_green.png"
#define FLAGS_OTHER_NETWORK_WIDE_ICON ":images/anonymous_128_blue.png"
#define FLAGS_OTHER_BROWSABLE_ICON ":images/browsable_128_blue.png"
#define FLAGS_OTHER_UNCHECKED ":images/blank_128_blue.png"
#define FLAGS_ANONYMOUS_SEARCH_ON ":icons/search_red_128.png"
#define FLAGS_ANONYMOUS_SEARCH_OFF ":icons/blank_red_128.png"
#define FLAGS_BROWSABLE_ON ":icons/browsable_green_128.png"
#define FLAGS_BROWSABLE_OFF ":icons/blank_green_128.png"
#define FLAGS_ANONYMOUS_DL_ON ":icons/anonymous_blue_128.png"
#define FLAGS_ANONYMOUS_DL_OFF ":icons/blank_blue_128.png"
#define INDEX_GROUP_BROWSABLE 0
#define INDEX_GROUP_NETWORK_W 1
#define INDEX_OTHER_BROWSABLE 2
#define INDEX_OTHER_NETWORK_W 3
#define INDEX_GROUP_UNCHECKED 4
#define INDEX_OTHER_UNCHECKED 5
#define INDEX_ANON_SEARCH 0
#define INDEX_ANON_DL 1
#define INDEX_BROWSABLE 2
/*QString GroupFlagsWidget::_tooltips_on[4] = {
QObject::tr("Directory is browsable for friends from groups"),
QObject::tr("Directory is accessible by anonymous tunnels from friends from groups"),
QObject::tr("Directory is browsable for any friend"),
QObject::tr("Directory is accessible by anonymous tunnels from any friend")
QObject::tr("Directory is visible to friends"),
QObject::tr("Directory can be search anonymously"),
QObject::tr("Directory is accessible by anonymous tunnels")
};
QString GroupFlagsWidget::_tooltips_off[4] = {
QObject::tr("Directory is NOT browsable for friends from groups"),
QObject::tr("Directory is NOT accessible by anonymous tunnels from friends from groups"),
QObject::tr("Directory is NOT browsable for any friend"),
QObject::tr("Directory is NOT accessible by anonymous tunnels from any friend")
QObject::tr("Directory is not visible to friends"),
QObject::tr("Directory cannot be searched anonymously"),
QObject::tr("Directory is NOT accessible by anonymous tunnels")
};
*/
GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
@ -39,35 +34,33 @@ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
setMaximumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ;
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
_icons[INDEX_GROUP_BROWSABLE] = new QIcon(FLAGS_GROUP_BROWSABLE_ICON) ;
_icons[INDEX_GROUP_NETWORK_W] = new QIcon(FLAGS_GROUP_NETWORK_WIDE_ICON) ;
_icons[INDEX_OTHER_BROWSABLE] = new QIcon(FLAGS_OTHER_BROWSABLE_ICON) ;
_icons[INDEX_OTHER_NETWORK_W] = new QIcon(FLAGS_OTHER_NETWORK_WIDE_ICON) ;
_icons[INDEX_GROUP_UNCHECKED] = new QIcon(FLAGS_GROUP_UNCHECKED) ;
_icons[INDEX_OTHER_UNCHECKED] = new QIcon(FLAGS_OTHER_UNCHECKED) ;
_icons[2*INDEX_BROWSABLE+0] = new QIcon(FLAGS_BROWSABLE_OFF) ;
_icons[2*INDEX_BROWSABLE+1] = new QIcon(FLAGS_BROWSABLE_ON) ;
_icons[2*INDEX_ANON_SEARCH+0] = new QIcon(FLAGS_ANONYMOUS_SEARCH_OFF) ;
_icons[2*INDEX_ANON_SEARCH+1] = new QIcon(FLAGS_ANONYMOUS_SEARCH_ON) ;
_icons[2*INDEX_ANON_DL+0] = new QIcon(FLAGS_ANONYMOUS_DL_OFF) ;
_icons[2*INDEX_ANON_DL+1] = new QIcon(FLAGS_ANONYMOUS_DL_ON) ;
setLayout(_layout) ;
_flags[0] = DIR_FLAGS_BROWSABLE_GROUPS ;
_flags[1] = DIR_FLAGS_NETWORK_WIDE_GROUPS ;
_flags[2] = DIR_FLAGS_BROWSABLE_OTHERS ;
_flags[3] = DIR_FLAGS_NETWORK_WIDE_OTHERS ;
_flags[INDEX_BROWSABLE ] = DIR_FLAGS_BROWSABLE ;
_flags[INDEX_ANON_SEARCH] = DIR_FLAGS_ANONYMOUS_SEARCH ;
_flags[INDEX_ANON_DL ] = DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
_buttons[i] = new QPushButton(this) ;
_buttons[i]->setCheckable(true) ;
_buttons[i]->setChecked(flags & _flags[i]) ;
_buttons[i]->setIconSize(QSize(32 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0));
update_button_state(_buttons[i]->isChecked(),i) ;
_layout->addWidget(_buttons[i]) ;
}
_buttons[INDEX_GROUP_NETWORK_W]->setHidden(true);
connect(_buttons[INDEX_GROUP_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_GN_button(bool))) ;
connect(_buttons[INDEX_OTHER_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_ON_button(bool))) ;
connect(_buttons[INDEX_GROUP_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_GB_button(bool))) ;
connect(_buttons[INDEX_OTHER_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_OB_button(bool))) ;
connect(_buttons[INDEX_ANON_DL ],SIGNAL(toggled(bool)),this,SLOT(update_DL_button(bool))) ;
connect(_buttons[INDEX_ANON_SEARCH],SIGNAL(toggled(bool)),this,SLOT(update_SR_button(bool))) ;
connect(_buttons[INDEX_BROWSABLE ],SIGNAL(toggled(bool)),this,SLOT(update_BR_button(bool))) ;
_layout->setSpacing(0);
_layout->setContentsMargins(0, 0, 0, 0);
@ -84,16 +77,15 @@ FileStorageFlags GroupFlagsWidget::flags() const
{
FileStorageFlags flags ;
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
if(_buttons[i]->isChecked()) flags |= _flags[i] ;
flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ;
return flags ;
}
void GroupFlagsWidget::setFlags(FileStorageFlags flags)
{
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
_buttons[i]->setChecked(flags & _flags[i]) ;
update_button_state(_buttons[i]->isChecked(),i) ;
@ -104,41 +96,28 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id)
{
QString tip_on, tip_off;
switch (button_id) {
case 0:
tip_on = tr("Directory is browsable for friends from groups");
tip_off = tr("Directory is NOT browsable for friends from groups");
case INDEX_BROWSABLE:
tip_on = tr("Directory content is visible to friend nodes (see list at right)");
tip_off = tr("Directory content is NOT visible to friend nodes");
break;
case 1:
tip_on = tr("Directory is accessible by anonymous tunnels from friends from groups");
tip_off = tr("Directory is NOT accessible by anonymous tunnels from friends from groups");
case INDEX_ANON_SEARCH:
tip_on = tr("Directory can be searched anonymously");
tip_off = tr("Directory cannot be searched anonymously");
break;
case 2:
tip_on = tr("Directory is browsable for any friend");
tip_off = tr("Directory is NOT browsable for any friend");
break;
case 3:
tip_on = tr("Directory is accessible by anonymous tunnels from any friend");
tip_off = tr("Directory is NOT accessible by anonymous tunnels from any friend");
case INDEX_ANON_DL:
if(_buttons[INDEX_ANON_SEARCH]->isChecked())
tip_on = tr("Files can be accessed using anonymous tunnels");
else
tip_on = tr("Files can be accessed using anonymous & end-to-end encrypted tunnels");
tip_off = tr("Files cannot be downloaded anonymously");
break;
default:
tip_on = "";
tip_off = "";
}
if(b)
{
_buttons[button_id]->setIcon(*_icons[button_id]) ;
_buttons[button_id]->setToolTip(tip_on) ;
}
else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE)
{
_buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ;
_buttons[button_id]->setToolTip(tip_off) ;
}
else
{
_buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ;
_buttons[button_id]->setToolTip(tip_off) ;
}
_buttons[button_id]->setIcon(*_icons[2*button_id+(int)b]) ;
_buttons[button_id]->setToolTip(b?tip_on:tip_off) ;
}
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QString>& groupNames)
@ -155,42 +134,39 @@ QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QS
groups_string += *it ;
}
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
res += tr("All friend nodes can browse this directory") + "\n" ;
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
if(!groupNames.empty())
res += tr("Only friend nodes in groups %1 can browse this directory").arg(groups_string) + "\n" ;
if(flags & DIR_FLAGS_BROWSABLE)
{
if(groupNames.empty())
res += tr("All friend nodes can see this directory") + "\n" ;
else
res += tr("No one can browse this directory") + "\n" ;
res += tr("Only visible to friend nodes in groups: %1").arg(groups_string) + "\n" ;
}
else
res += tr("No one can browse this directory") + "\n" ;
res += tr("Not visible to friend nodes") + "\n" ;
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS)
res += tr("All friend nodes can relay anonymous tunnels to this directory") ;
else if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS)
res += tr("Only friend nodes in groups")+" " + groups_string +" "+ tr("can relay anonymous tunnels to this directory") ;
if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && !(flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be downloaded (but not searched) anonymously") ;
else if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be downloaded and searched anonymously") ;
else if(!(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be searched (but not downloaded) anonymously") ;
else
res += tr("No one can anonymously access this directory.") ;
//if(flags.toUInt32() == 0)
// res += tr("No friends can access nor see this directory.") ;
res += tr("No one can anonymously access/search these files.") ;
return res ;
}
void GroupFlagsWidget::update_GN_button(bool b) { update_button_state(b,INDEX_GROUP_NETWORK_W) ; updated() ; }
void GroupFlagsWidget::update_GB_button(bool b) { update_button_state(b,INDEX_GROUP_BROWSABLE) ; updated() ; }
void GroupFlagsWidget::update_ON_button(bool b) { update_button_state(b,INDEX_OTHER_NETWORK_W) ; updated() ; }
void GroupFlagsWidget::update_OB_button(bool b) { update_button_state(b,INDEX_OTHER_BROWSABLE) ; updated() ; }
void GroupFlagsWidget::update_DL_button(bool b) { update_button_state(b,INDEX_ANON_DL ) ; updated() ; }
void GroupFlagsWidget::update_SR_button(bool b) { update_button_state(b,INDEX_ANON_SEARCH) ; updated() ; }
void GroupFlagsWidget::update_BR_button(bool b) { update_button_state(b,INDEX_BROWSABLE ) ; updated() ; }
GroupFlagsWidget::~GroupFlagsWidget()
{
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
delete _buttons[i] ;
delete _icons[i] ;
delete _icons[2*i+0] ;
delete _icons[2*i+1] ;
}
delete _icons[INDEX_GROUP_UNCHECKED] ;
delete _icons[INDEX_OTHER_UNCHECKED] ;
}

View File

@ -22,10 +22,9 @@ class GroupFlagsWidget: public QWidget
void updated() ;
protected slots:
void update_GN_button(bool) ;
void update_GB_button(bool) ;
void update_ON_button(bool) ;
void update_OB_button(bool) ;
void update_DL_button(bool) ;
void update_SR_button(bool) ;
void update_BR_button(bool) ;
signals:
void flagsChanged(FileStorageFlags) const ;

View File

@ -1,3 +1,5 @@
#include <QLayout>
#include <QDialogButtonBox>
#include <retroshare/rspeers.h>
#include "GroupSelectionBox.h"
#include "GroupDefs.h"
@ -17,7 +19,6 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent)
// Fill with available groups
fillGroups();
}
void GroupSelectionBox::fillGroups()
{
std::list<RsNodeGroupId> selectedIds;
@ -78,3 +79,39 @@ void GroupSelectionBox::selectedGroupNames(QList<QString> &groupNames) const
}
}
}
std::list<RsNodeGroupId> GroupSelectionDialog::selectGroups(const std::list<RsNodeGroupId>& default_groups)
{
GroupSelectionDialog gsd(NULL) ;
gsd.mBox->setSelectedGroupIds(default_groups) ;
gsd.exec();
std::list<RsNodeGroupId> selected_groups ;
gsd.mBox->selectedGroupIds(selected_groups);
return selected_groups ;
}
GroupSelectionDialog::~GroupSelectionDialog()
{
delete mBox ;
}
GroupSelectionDialog::GroupSelectionDialog(QWidget *parent)
{
mBox = new GroupSelectionBox(this) ;
QLayout *l = new QVBoxLayout ;
setLayout(l) ;
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
l->addWidget(mBox) ;
l->addWidget(buttonBox) ;
l->update() ;
}

View File

@ -1,4 +1,5 @@
#include <QListWidget>
#include <QDialog>
#include <retroshare/rsids.h>
class GroupSelectionBox: public QListWidget
@ -8,6 +9,8 @@ class GroupSelectionBox: public QListWidget
public:
GroupSelectionBox(QWidget *parent);
static void selectGroups(const std::list<RsNodeGroupId>& default_groups) ;
void selectedGroupIds(std::list<RsNodeGroupId> &groupIds) const;
void selectedGroupNames(QList<QString> &groupNames) const;
@ -16,3 +19,17 @@ public:
private slots:
void fillGroups();
};
class GroupSelectionDialog: public QDialog
{
Q_OBJECT
public:
GroupSelectionDialog(QWidget *parent) ;
virtual ~GroupSelectionDialog() ;
static std::list<RsNodeGroupId> selectGroups(const std::list<RsNodeGroupId>& default_groups) ;
private:
GroupSelectionBox *mBox ;
};

View File

@ -78,6 +78,17 @@ void MimeTextEdit::insertFromMimeData(const QMimeData* source)
}
#endif
//insert retroshare links
QList<RetroShareLink> links;
RSLinkClipboard::parseText(source->text(), links);
if(links.size() > 0)
{
for(int i = 0; i < links.size(); ++i)
insertHtml(links[i].toHtml() + "<br>");
return;
}
return RSTextEdit::insertFromMimeData(source);
}

View File

@ -25,15 +25,16 @@
<file>icons/settings/sound.svg</file>
<file>icons/settings/webinterface.svg</file>
<file>icons/add_user_256.png</file>
<file>icons/anonymous_blue_128.png</file>
<file>icons/anonymous_green_128.png</file>
<file>icons/aol.png</file>
<file>icons/avatar_128.png</file>
<file>icons/avatar_grey_128.png</file>
<file>icons/blank_blue_128.png</file>
<file>icons/blank_red_128.png</file>
<file>icons/void_128.png</file>
<file>icons/blank_green_128.png</file>
<file>icons/browsable_blue_128.png</file>
<file>icons/blank_blue_128.png</file>
<file>icons/browsable_green_128.png</file>
<file>icons/search_red_128.png</file>
<file>icons/anonymous_blue_128.png</file>
<file>icons/bullet_blue_128.png</file>
<file>icons/bullet_green_128.png</file>
<file>icons/bullet_grey_128.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@ -3,7 +3,7 @@
echo '<RCC>'
echo '\t<qresource prefix="/">'
for i in `ls *.png`; do
for i in `ls *.png */*png */*svg`; do
echo '\t\t<file>icons/'$i'</file>'
done

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -44,10 +44,17 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags)
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: ui._defaultStrategy_CB->setCurrentIndex(2) ; break ;
}
switch(rsFiles->defaultEncryptionPolicy())
{
case RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE: ui._e2e_encryption_CB->setCurrentIndex(0) ; break ;
case RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT : ui._e2e_encryption_CB->setCurrentIndex(1) ; break ;
}
ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ;
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ;
QObject::connect(ui._e2e_encryption_CB,SIGNAL(activated(int)),this,SLOT(updateEncryptionPolicy(int))) ;
QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ;
QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) );
@ -57,6 +64,19 @@ void TransferPage::updateMaxTRUpRate(int b)
{
rsTurtle->setMaxTRForwardRate(b) ;
}
void TransferPage::updateEncryptionPolicy(int b)
{
switch(b)
{
case 1: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT) ;
break ;
default:
case 0: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE) ;
break ;
}
}
void TransferPage::updateDefaultStrategy(int i)
{
switch(i)

View File

@ -49,6 +49,7 @@ class TransferPage: public ConfigPage
void updateDefaultStrategy(int) ;
void updateDiskSizeLimit(int) ;
void updateMaxTRUpRate(int);
void updateEncryptionPolicy(int);
private:

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>700</width>
<height>356</height>
<width>741</width>
<height>372</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -49,6 +49,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>End-to-end encryption:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -135,6 +142,23 @@
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_e2e_encryption_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Anonymous tunnels can be end-o-end encrypted. In order to maintain backward compatibility, this can be made optional (choosing &amp;quot;Accepted&amp;quot;), but in the end, all Retroshare nodes will be switched to &amp;quot;Enforced&amp;quot;, meaning that all anonymous transfers will be end-to-end encrypted.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
<string>Accepted</string>
</property>
</item>
<item>
<property name="text">
<string>Enforced</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>

View File

@ -234,6 +234,9 @@ macx {
mac_icon.files = $$files($$PWD/rsMacIcon.icns)
mac_icon.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_icon
mac_webui.files = $$files($$PWD/../../libresapi/src/webui)
mac_webui.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_webui
CONFIG += version_detail_bash_script
LIBS += -lssl -lcrypto -lz

View File

@ -108,12 +108,12 @@ macx {
LIB_DIR += "/usr/local/lib"
LIB_DIR += "/opt/local/lib"
!QMAKE_MACOSX_DEPLOYMENT_TARGET {
message(***retroshare.pri: No Target, set it to MacOS 10.10 )
QMAKE_MACOSX_DEPLOYMENT_TARGET=10.10
message(***retroshare.pri: No Target. Set it to MacOS 10.11 )
QMAKE_MACOSX_DEPLOYMENT_TARGET=10.11
}
!QMAKE_MAC_SDK {
message(***retroshare.pri: No SDK, set it to MacOS 10.10 )
QMAKE_MAC_SDK = macosx10.10
message(***retroshare.pri: No SDK. Set it to MacOS 10.11 )
QMAKE_MAC_SDK = macosx10.11
}
CONFIG += c++11
}

View File

@ -192,23 +192,30 @@ mac {
CONFIG += upnp_miniupnpc
# zeroconf disabled at the end of libretroshare.pro (but need the code)
CONFIG += zeroconf
CONFIG += zcnatassist
#CONFIG += zeroconf
#CONFIG += zcnatassist
# Beautiful Hack to fix 64bit file access.
QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs
UPNPC_DIR = ../../../miniupnpc-1.0
#UPNPC_DIR = ../../../miniupnpc-1.0
#GPG_ERROR_DIR = ../../../../libgpg-error-1.7
#GPGME_DIR = ../../../../gpgme-1.1.8
#OPENPGPSDK_DIR = ../../openpgpsdk/src
#INCLUDEPATH += . $${UPNPC_DIR}
#INCLUDEPATH += $${OPENPGPSDK_DIR}
OPENPGPSDK_DIR = ../../openpgpsdk/src
#for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a}
for(lib, LIB_DIR):LIBS += -L"$$lib"
for(bin, BIN_DIR):LIBS += -L"$$bin"
INCLUDEPATH += . $${UPNPC_DIR}
INCLUDEPATH += $${OPENPGPSDK_DIR}
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
INCLUDEPATH += ../../../.
#../openpgpsdk
#INCLUDEPATH += . $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
LIBS += /usr/local/lib/libsqlcipher.a
#LIBS += -lsqlite3
}
################################# FreeBSD ##########################################

View File

@ -0,0 +1,12 @@
#include <gtest/gtest.h>
// from libretroshare
#include "crypto/chacha20.h"
TEST(libretroshare_crypto, ChaCha20)
{
std::cerr << "Testing Chacha20" << std::endl;
EXPECT_TRUE(librs::crypto::perform_tests()) ;
}

View File

@ -172,8 +172,8 @@ 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.4
CONFIG += version_detail_bash_script
LIBS += ../../libretroshare/src/lib/libretroshare.a
@ -181,24 +181,25 @@ macx {
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
LIBS += -lssl -lcrypto -lz
#LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan
LIBS += ../../../miniupnpc-1.0/libminiupnpc.a
for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a}
LIBS += -framework CoreFoundation
LIBS += -framework Security
gxs {
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
LIBS += ../../../lib/libsqlcipher.a
for(lib, LIB_DIR):LIBS += -L"$$lib"
for(bin, BIN_DIR):LIBS += -L"$$bin"
DEPENDPATH += . $$INC_DIR
INCLUDEPATH += . $$INC_DIR
#LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
LIBS += /usr/local/lib/libsqlcipher.a
#LIBS += -lsqlite3
}
INCLUDEPATH += .
#DEFINES* = MAC_IDLE # for idle feature
CONFIG -= uitools
}
##################################### FreeBSD ######################################
@ -271,6 +272,10 @@ INCLUDEPATH += ../librssimulator/
SOURCES += unittests.cc \
################################## Crypto ##################################
SOURCES += libretroshare/crypto/chacha20_test.cc
################################ Serialiser ################################
HEADERS += libretroshare/serialiser/support.h \
libretroshare/serialiser/rstlvutil.h \