Compare commits

..

No commits in common. "v0.6" and "python3android" have entirely different histories.

164 changed files with 4877 additions and 5757 deletions

1
.gitignore vendored
View File

@ -17,5 +17,4 @@ dist
*.egg-info *.egg-info
docs/_*/* docs/_*/*
docs/autodoc/ docs/autodoc/
build
pyan/ pyan/

View File

@ -1,9 +0,0 @@
version: 2
python:
version: 2.7
install:
- requirements: docs/requirements.txt
- method: setuptools
path: .
system_packages: true

View File

@ -6,7 +6,6 @@ addons:
packages: packages:
- build-essential - build-essential
- libcap-dev - libcap-dev
- tor
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt
- ln -s src pybitmessage # tests environment - ln -s src pybitmessage # tests environment

View File

@ -1,5 +1,5 @@
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2020 The Bitmessage Developers Copyright (c) 2012-2019 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

51
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2020 The Bitmessage Developers Copyright (c) 2012-2019 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@ -22,7 +22,7 @@ SOFTWARE.
===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net> ===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net>
qidenticon.py is Licensed under FreeBSD License. qidenticon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 2013 "Sendiulo". All rights reserved. Copyright 2013 "Sendiulo". All rights reserved.
@ -36,7 +36,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR I
===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp> ===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp>
identicon.py is Licensed under FreeBSD License. identicon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 1994-2009 Shin Adachi. All rights reserved. Copyright 1994-2009 Shin Adachi. All rights reserved.
@ -47,48 +47,3 @@ Redistribution and use in source and binary forms, with or without modification,
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===== based on asyncore_pollchoose.py asyncore_pollchoose python implementation. by Sam Rushing <rushing@nightmare.com>
Copyright 1996 by Sam Rushing. All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of Sam
Rushing not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
===== based on namecoin.py namecoin.py python implementation by Daniel Kraft <d@domob.eu>
Copyright (C) 2013 by Daniel Kraft <d@domob.eu>
This file is part of the Bitmessage project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -14,10 +14,12 @@ Development
---------- ----------
Bitmessage is a collaborative project. You are welcome to submit pull requests Bitmessage is a collaborative project. You are welcome to submit pull requests
although if you plan to put a non-trivial amount of work into coding new although if you plan to put a non-trivial amount of work into coding new
features, it is recommended that you first describe your ideas in the features, it is recommended that you first solicit feedback on the DevTalk
separate issue. pseudo-mailing list:
BM-2D9QKN4teYRvoq2fyzpiftPh9WP9qggtzh
Feel welcome to join chan "bitmessage", BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY Feel welcome to join chan "bitmessage", BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY
which is on preview here: https://beamstat.com/chan/bitmessage
References References
---------- ----------

View File

@ -1,6 +1,6 @@
PyBitmessage(Android) PyBitmessage(Android)
This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its addresses. This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its adresses.
Steps for trying out this sample: Steps for trying out this sample:
@ -13,7 +13,7 @@ This sample uses the kivy as Kivy is an open source, cross-platform Python frame
Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support. Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support.
Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prerequisite for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device. Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prequisites for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device.
Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build. Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build.

16
build/changelang.sh Executable file
View File

@ -0,0 +1,16 @@
export LANG=de_DE.UTF-8
export LANGUAGE=de_DE
export LC_CTYPE="de_DE.UTF-8"
export LC_NUMERIC=de_DE.UTF-8
export LC_TIME=de_DE.UTF-8
export LC_COLLATE="de_DE.UTF-8"
export LC_MONETARY=de_DE.UTF-8
export LC_MESSAGES="de_DE.UTF-8"
export LC_PAPER=de_DE.UTF-8
export LC_NAME=de_DE.UTF-8
export LC_ADDRESS=de_DE.UTF-8
export LC_TELEPHONE=de_DE.UTF-8
export LC_MEASUREMENT=de_DE.UTF-8
export LC_IDENTIFICATION=de_DE.UTF-8
export LC_ALL=
python2.7 src/bitmessagemain.py

23
build/compiletest.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python2.7
import ctypes
import fnmatch
import os
import sys
import traceback
matches = []
for root, dirnames, filenames in os.walk('src'):
for filename in fnmatch.filter(filenames, '*.py'):
matches.append(os.path.join(root, filename))
for filename in matches:
source = open(filename, 'r').read() + '\n'
try:
compile(source, filename, 'exec')
except Exception as e:
if 'win' in sys.platform:
ctypes.windll.user32.MessageBoxA(0, traceback.format_exc(), "Exception in " + filename, 1)
else:
print "Exception in %s: %s" % (filename, traceback.format_exc())
sys.exit(1)

11
build/mergepullrequest.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ -z "$1" ]; then
echo "You must specify pull request number"
exit
fi
git pull
git checkout v0.6
git fetch origin pull/"$1"/head:"$1"
git merge --ff-only "$1"

173
buildscripts/builder.sh Executable file
View File

@ -0,0 +1,173 @@
#!/bin/bash
# INIT
MACHINE_TYPE=`uname -m`
BASE_DIR=$(pwd)
PYTHON_VERSION=2.7.15
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
OPENSSL_VERSION=1_0_2t
DIRECTORY32BIT=SoftwareDownloads32bit
DIRECTORY64BIT=SoftwareDownloads64bit
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
if [ ! -d "$DIRECTORY64BIT" ]; then
mkdir SoftwareDownloads64bit
cd SoftwareDownloads64bit
else
echo "Directory already exists"
cd SoftwareDownloads64bit
fi
else
if [ ! -d "$DIRECTORY32BIT" ]; then
mkdir SoftwareDownloads32bit
cd SoftwareDownloads32bit
else
echo "Directory 32 bit alrready exists"
cd SoftwareDownloads32bit
fi
fi
#Functions
function install_wine {
wget -nc https://dl.winehq.org/wine-builds/Release.key --no-check-certificate
sudo apt-key add Release.key
sudo apt-add-repository 'https://dl.winehq.org/wine-builds/ubuntu/'
sudo apt-get -y update
sudo apt-get -y install wine1.8 winetricks
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
sudo apt-get -y install wine64-development
env WINEPREFIX=$HOME/.wine64 WINEARCH=win64 winecfg
WINE="env WINEPREFIX=$HOME/.wine64 wine"
export WINEPREFIX
else
sudo apt-get -y install wine32-development
env WINEPREFIX=$HOME/.wine32 WINEARCH=win32 winecfg
WINE="env WINEPREFIX=$HOME/.wine32 wine"
export WINEPREFIX
fi
}
function install_python(){
echo "Download Python2.7"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# For 64 bit machine
wget -nc wget http://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.amd64.msi --no-check-certificate
echo "Install Python2.7 for 64 bit"
$WINE msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
wget -nc https://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe --no-check-certificate
$WINE vcredist_x64.exe /q /norestart
echo "Installed vcredist for 64 bit"
$WINE pip install --upgrade pip
else
# For 32 bit machine
wget -nc https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.msi --no-check-certificate
echo "Install Python2.7 for 32 bit"
$WINE msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
echo "Installing vc_redist for 32 bit "
wget -nc https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe --no-check-certificate
$WINE vcredist_x86.exe /q /norestart
#insatlled msvcr120.dll for 32 bit system
wget -nc http://www.dll-found.com/zip/m/msvcr120.dll.zip --no-check-certificate
unzip msvcr120.dll.zip
sudo cp msvcr120.dll $HOME/.wine32/drive_c/windows/system32/
$WINE pip install --upgrade pip
fi
}
function install_pyqt(){
echo "Download PyQT"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# For 64 bit machine
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x64.exe?raw=true --no-check-certificate
$WINE PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x64.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
else
# For 32 bit machine
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe?raw=true --no-check-certificate
$WINE PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
fi
}
function install_openssl(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win64OpenSSL-${OPENSSL_VERSION}.exe?raw=true --no-check-certificate
$WINE Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
else
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true --no-check-certificate
$WINE Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
echo "Install PyInstaller 32 bit"
fi
}
function install_pyinstaller()
{
$WINE pip install pyinstaller
echo "Install PyInstaller"
echo "Install Pyopencl"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wget -nc https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64.whl --no-check-certificate
$WINE pip install pyopencl-2015.1-cp27-none-win_amd64.whl
$WINE pip install msgpack-python
else
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64one-win32.whl?raw=true --no-check-certificate
$WINE pip install msgpack-python
$WINE pip install pyopencl-2015.1-cp27-none-win32.whl
fi
echo "Install Message Pack"
}
function build_dll(){
cd $BASE_DIR
rm -rf master.zip
rm -rf PyBitmessage
git clone https://github.com/Bitmessage/PyBitmessage.git
cd PyBitmessage/src/bitmsghash
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# Do stuff for 64 bit machine
echo "Install MinGW"
sudo apt-get -y install mingw-w64
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -I/usr/x86_64-w64-mingw32/include -L$HOME/.wine64/drive_c/OpenSSL-Win64/lib -c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -L$HOME/.wine64/drive_c/OpenSSL-Win64 -L/usr/lib/x86_64-linux-gnu/wine -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
echo "DLL generated successfully "
cd ..
cp -R bitmsghash ../../../src/
cd ../../../
cd packages/pyinstaller/
env WINEPREFIX=$HOME/.wine64 wine pyinstaller bitmessagemain.spec
else
echo "Install MinGW for 32 bit"
sudo apt-get install mingw-w64
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -I/usr/i686-w64-mingw32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib -c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
cd ..
cp -R bitmsghash ../../../src/
cd ../../../
cd packages/pyinstaller/
env WINEPREFIX=$HOME/.wine32 wine pyinstaller bitmessagemain.spec
fi
}
install_wine
install_python
install_pyqt
install_openssl
install_pyinstaller
build_dll

View File

@ -1,169 +0,0 @@
#!/bin/bash
# INIT
MACHINE_TYPE=`uname -m`
BASE_DIR=$(pwd)
PYTHON_VERSION=2.7.17
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
OPENSSL_VERSION=1_0_2t
SRCPATH=~/Downloads
#Functions
function download_sources_32 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.msi \
https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x32.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win32.whl?raw=true
}
function download_sources_64 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
http://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.amd64.msi \
https://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x64.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win64OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64.whl?raw=true
}
function download_sources {
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
download_sources_64
else
download_sources_32
fi
}
function install_wine {
echo "Setting up wine"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
export WINEPREFIX=${HOME}/.wine64 WINEARCH=win64
else
export WINEPREFIX=${HOME}/.wine32 WINEARCH=win32
fi
rm -rf ${WINEPREFIX}
rm -rf packages/pyinstaller/{build,dist}
}
function install_python(){
cd ${SRCPATH}
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing Python ${PYTHON_VERSION} 64b"
wine msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
echo "Installing vcredist for 64 bit"
wine vcredist_x64.exe /q /norestart
else
echo "Installing Python ${PYTHON_VERSION} 32b"
wine msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
# MSVCR 2008 required for Windows XP
cd ${SRCPATH}
echo "Installing vc_redist (2008) for 32 bit "
wine vcredist_x86.exe /Q
fi
# add cert
if [ -f /usr/local/share/ca-certificates/bitmessage-proxy.crt ]; then
wine python -m pip config set global.cert 'z:\usr\local\share\ca-certificates\bitmessage-proxy.crt'
fi
echo "Upgrading pip"
wine python -m pip install --upgrade pip
}
function install_pyqt(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing PyQt-${PYQT_VERSION} 64b"
wine PyQt${PYQT_VERSION}-x64.exe /S /WX
else
echo "Installing PyQt-${PYQT_VERSION} 32b"
wine PyQt${PYQT_VERSION}-x32.exe /S /WX
fi
}
function install_openssl(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing OpenSSL ${OPENSSL_VERSION} 64b"
wine Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
else
echo "Installing OpenSSL ${OPENSSL_VERSION} 32b"
wine Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
fi
}
function install_pyinstaller()
{
cd ${BASE_DIR}
echo "Installing PyInstaller"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wine python -m pip install pyinstaller
else
# 3.2.1 is the last version to work on XP
# see https://github.com/pyinstaller/pyinstaller/issues/2931
wine python -m pip install -I pyinstaller==3.2.1
fi
}
function install_msgpack()
{
cd ${BASE_DIR}
echo "Installing msgpack"
wine python -m pip install msgpack-python
}
function install_pyopencl()
{
cd ${SRCPATH}
echo "Installing PyOpenCL"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wine python -m pip install pyopencl-2015.1-cp27-none-win_amd64.whl
else
wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl
fi
sed -Ei 's/_DEFAULT_INCLUDE_OPTIONS = .*/_DEFAULT_INCLUDE_OPTIONS = [] /' $WINEPREFIX/drive_c/Python27/Lib/site-packages/pyopencl/__init__.py
}
function build_dll(){
cd ${BASE_DIR}
cd src/bitmsghash
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -I/usr/x86_64-w64-mingw32/include -L$HOME/.wine64/drive_c/OpenSSL-Win64/lib -c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -L$HOME/.wine64/drive_c/OpenSSL-Win64 -L/usr/lib/x86_64-linux-gnu/wine -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
else
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -I/usr/i686-w64-mingw32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib -c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
fi
}
function build_exe(){
cd ${BASE_DIR}
cd packages/pyinstaller
wine pyinstaller bitmessagemain.spec
}
# prepare on ubuntu
# dpkg --add-architecture i386
# apt update
# apt -y install wget wine-stable wine-development winetricks mingw-w64 wine32 wine64 xvfb
download_sources
if [ "$1" == "--download-only" ]; then
exit
fi
install_wine
install_python
install_pyqt
install_openssl
install_pyopencl
install_msgpack
install_pyinstaller
build_dll
build_exe

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
""" """
Check dependencies and give recommendations about how to satisfy them Check dependendies and give recommendations about how to satisfy them
Limitations: Limitations:
@ -164,7 +164,7 @@ if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
if not compiler: if not compiler:
compilerToPackages() compilerToPackages()
prereqToPackages() prereqToPackages()
if prereqs and mandatory: if mandatory:
sys.exit(1) sys.exit(1)
else: else:
print("All the dependencies satisfied, you can install PyBitmessage") print("All the dependencies satisfied, you can install PyBitmessage")

22
debian/README.Debian vendored
View File

@ -1,22 +0,0 @@
bitmessage for Debian
--------------------
In order to build the .deb yourself, you'll first have to install the stuff that's neccessary to compile .debs:
apt-get install python-minimal python-setuptools python-all \
python openssl libssl-dev dh-apparmor debhelper dh-python \
python-msgpack python-qt4 git
Next make some build directory and clone the newest git repository:
And if I haven't forgotten anything, you can build the .deb package now:
dpkg-buildpackage -us -uc
I've tried this with Debian Buster, but I'd expect it to work on most if not all recent debian-based distributions. Maybe with some minor changes.
-- citizenaspirant <citizenadmin@helicoptarianconstitocracy.org> Wed, 29 Apr 2020 17:53:21 +0000

View File

@ -1,19 +0,0 @@
# Last Modified: Wed Apr 29 21:04:08 2020
#include <tunables/global>
/usr/bin/pybitmessage {
#include <abstractions/base>
#include <abstractions/fonts>
#include <abstractions/lightdm>
#include <abstractions/python>
#include <abstractions/user-tmp>
owner /home/*/.ICEauthority r,
owner /home/*/.Xauthority r,
owner /home/*/.config/PyBitmessage/ rw,
owner /home/*/.config/PyBitmessage/* rwk,
owner /home/*/.config/Trolltech.conf rwk,
owner /home/*/.config/Trolltech.conf.* rw,
owner /proc/*/mounts r,
}

View File

@ -1 +0,0 @@
README.Debian

5
debian/changelog vendored
View File

@ -1,5 +0,0 @@
bitmessage (0.7a-1) unstable; urgency=medium
* Initial release
-- citizenaspirant <citizenadmin@helicoptarianconstitocracy.org> Wed, 29 Apr 2020 17:53:21 +0000

1
debian/compat vendored
View File

@ -1 +0,0 @@
11

20
debian/control vendored
View File

@ -1,20 +0,0 @@
Source: bitmessage
Section: net
Priority: optional
Maintainer: citizenadmin <citizenadmin@helicoptarianconstitocracy.org>
Build-Depends: debhelper (>= 11), dh-python, dh-apparmor, python-all, python-setuptools
Standards-Version: 4.1.3
Homepage: https://github.com/Bitmessage/PyBitmessage
X-Python-Version: >= 2.6
#Vcs-Browser: https://salsa.debian.org/debian/bitmessage
Vcs-Git: https://github.com/Bitmessage/PyBitmessage
#Testsuite: autopkgtest-pkg-python
Package: python-bitmessage
Architecture: all
Depends: ${python:Depends}, ${misc:Depends}, python, openssl, libssl-dev, python-msgpack, python-setuptools
Suggests: apparmor, tor, python-pyopencl, python-qt4, python-stem
Description: BitMessage Anonymous Communication Client
.
Bitmessage is a P2P communication protocol used to send encrypted messages to another person or to many subscribers. It is decentralized and trustless, meaning that you need-not inherently trust any entities like root certificate authorities. It uses strong authentication, which means that the sender of a message cannot be spoofed. BM aims to hide metadata from passive eavesdroppers like those ongoing warrantless wiretapping programs. Hence the sender and receiver of Bitmessages stay anonymous.

38
debian/copyright vendored
View File

@ -1,38 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: bitmessage
Source: <url://example.com>
Files: *
Copyright: <years> <put author's name and email here>
<years> <likewise for another author>
License: <special license>
<Put the license of the package here indented by 1 space>
<This follows the format of Description: lines in control file>
.
<Including paragraphs>
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2020 unknown <builder@unknown>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package 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 General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.
# Please avoid picking licenses with terms that are more restrictive than the
# packaged work, as it may make Debian's contributions unacceptable upstream.

4
debian/menu vendored
View File

@ -1,4 +0,0 @@
?package(bitmessage): \
needs="X11|text|vc|wm" \
section="Applications/Office"\
title="bitmessage" command="/usr/bin/bitmessage"

View File

@ -1,2 +0,0 @@
debian/apparmor/pybitmessage etc/apparmor.d

19
debian/rules vendored
View File

@ -1,19 +0,0 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
export DH_VERBOSE = 1
export DH_OPTIONS=-v
export PYBUILD_NAME=bitmessage
%:
dh $@ --with python2 --buildsystem=pybuild
dh_apparmor --profile-name=pybitmessage -ppython-bitmessage
# If you need to rebuild the Sphinx documentation
# Add spinxdoc to the dh --with line
#override_dh_auto_build:
# dh_auto_build
# PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bhtml docs/ build/html # HTML generator
# PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bman docs/ build/man # Manpage generator

View File

@ -1 +0,0 @@
3.0 (quilt)

View File

@ -1 +0,0 @@
extend-diff-ignore = "^[^/]*[.]egg-info/"

View File

@ -1,4 +0,0 @@
/* Hide "On GitHub" section from versions menu */
li.wy-breadcrumbs-aside > a.fa {
display: none;
}

View File

@ -2,24 +2,35 @@
""" """
Configuration file for the Sphinx documentation builder. Configuration file for the Sphinx documentation builder.
For a full list of options see the documentation: This file does only contain a selection of the most common options. For a
full list see the documentation:
http://www.sphinx-doc.org/en/master/config http://www.sphinx-doc.org/en/master/config
-- Path setup --------------------------------------------------------------
If extensions (or modules to document with autodoc) are in another directory,
add these directories to sys.path here. If the directory is relative to the
documentation root, use os.path.abspath to make it absolute, like shown here.
""" """
import os import os
import sys import sys
from sphinx.apidoc import main
from mock import Mock as MagicMock
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('../src')) sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../src/pyelliptic'))
from importlib import import_module import version
import version # noqa:E402
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = u'PyBitmessage' project = u'PyBitmessage'
copyright = u'2019, The Bitmessage Team' # pylint: disable=redefined-builtin copyright = u'2018, The Bitmessage Team' # pylint: disable=redefined-builtin
author = u'The Bitmessage Team' author = u'The Bitmessage Team'
# The short X.Y version # The short X.Y version
@ -39,18 +50,15 @@ release = version
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.coverage', # FIXME: unused # 'sphinx.ext.doctest', # Currently disabled due to bad doctests
'sphinx.ext.imgmath', # legacy unused
'sphinx.ext.intersphinx', 'sphinx.ext.intersphinx',
'sphinx.ext.linkcode',
'sphinx.ext.napoleon',
'sphinx.ext.todo', 'sphinx.ext.todo',
'sphinxcontrib.apidoc', 'sphinx.ext.coverage',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'm2r', 'm2r',
] ]
default_role = 'obj'
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
@ -67,29 +75,23 @@ master_doc = 'index'
# #
# This is also used if you do content translation via gettext catalogs. # This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases. # Usually you set "language" from the command line for these cases.
# language = None language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path . # This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build'] exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'
# Don't prepend every class or function name with full module path
add_module_names = False
# A list of ignored prefixes for module index sorting.
modindex_common_prefix = ['pybitmessage.']
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
html_theme = 'sphinx_rtd_theme' html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the
@ -102,10 +104,6 @@ html_theme = 'sphinx_rtd_theme'
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ['_static']
html_css_files = [
'custom.css',
]
# Custom sidebar templates, must be a dictionary that maps document names # Custom sidebar templates, must be a dictionary that maps document names
# to template names. # to template names.
# #
@ -116,7 +114,10 @@ html_css_files = [
# #
# html_sidebars = {} # html_sidebars = {}
html_show_sourcelink = False # Deal with long lines in source view
html_theme_options = {
'page_width': '1366px',
}
# -- Options for HTMLHelp output --------------------------------------------- # -- Options for HTMLHelp output ---------------------------------------------
@ -198,74 +199,10 @@ epub_exclude_files = ['search.html']
# -- Extension configuration ------------------------------------------------- # -- Extension configuration -------------------------------------------------
autodoc_mock_imports = [
'debug',
'pybitmessage.bitmessagekivy',
'pybitmessage.bitmessageqt.addressvalidator',
'pybitmessage.helper_startup',
'pybitmessage.network.httpd',
'pybitmessage.network.https',
'ctypes',
'dialog',
'gi',
'kivy',
'logging',
'msgpack',
'numpy',
'pkg_resources',
'pycanberra',
'pyopencl',
'PyQt4',
'pyxdg',
'qrcode',
'stem',
]
autodoc_member_order = 'bysource'
# Apidoc settings
apidoc_module_dir = '../pybitmessage'
apidoc_output_dir = 'autodoc'
apidoc_excluded_paths = [
'bitmessagekivy', 'build_osx.py',
'bitmessageqt/addressvalidator.py', 'bitmessageqt/migrationwizard.py',
'bitmessageqt/newaddresswizard.py', 'helper_startup.py',
'kivymd', 'main.py', 'navigationdrawer', 'network/http*',
'pybitmessage', 'tests', 'version.py'
]
apidoc_module_first = True
apidoc_separate_modules = True
apidoc_toc_file = False
apidoc_extra_args = ['-a']
# Napoleon settings
napoleon_google_docstring = True
# linkcode function
def linkcode_resolve(domain, info):
"""This generates source URL's for sphinx.ext.linkcode"""
if domain != 'py' or not info['module']:
return
try:
home = os.path.abspath(import_module('pybitmessage').__path__[0])
mod = import_module(info['module']).__file__
except ImportError:
return
repo = 'https://github.com/Bitmessage/PyBitmessage/blob/v0.6/src%s'
path = mod.replace(home, '')
if path != mod:
# put the link only for top level definitions
if len(info['fullname'].split('.')) > 1:
return
if path.endswith('.pyc'):
path = path[:-1]
return repo % path
# -- Options for intersphinx extension --------------------------------------- # -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/2.7/': None} intersphinx_mapping = {'https://docs.python.org/': None}
# -- Options for todo extension ---------------------------------------------- # -- Options for todo extension ----------------------------------------------

View File

@ -1,2 +1,2 @@
.. mdinclude:: ../../../fabfile/README.md .. mdinclude:: fabfile/README.md

View File

@ -21,12 +21,12 @@ If we are to make bold claims about protecting your privacy we should demonstrat
- looking to audit - looking to audit
- warrant canary - warrant canary
Digital footprint Digital foootprint
------------------ ------------------
Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful. Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful.
* Use separate addresses for different purposes * Use separate addresses for different puprose
* Don't make the same mistakes all the time * Don't make the same mistakes all the time
* Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often. * Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often.

View File

@ -11,17 +11,17 @@ Bitmessage makes use of fabric_ to define tasks such as building documentation o
Code style and linters Code style and linters
---------------------- ----------------------
We aim to be PEP8 compliant but we recognize that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindness, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities. We aim to be PEP8 compliant but we recognise that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindess, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities.
Pull requests Pull requests
------------- -------------
There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based on the ideas in the template. There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based off the ideas in the template.
Bike-shedding Bike-shedding
------------- -------------
Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbitrary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here. Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbirary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here.
I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section. I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section.
@ -49,7 +49,7 @@ British vs American spelling
Dependency graph Dependency graph
---------------- ----------------
These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller graphs. These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller grapghs.
To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time. To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time.

View File

@ -1,8 +1,8 @@
Processes Processes
========= =========
In order to keep the Bitmessage project running, the team runs a number of systems and accounts that form the In other to keep the Bitmessage project running the team run a number of systems and accounts that form the
development pipeline and continuous delivery process. We are always striving to improve this process. Towards development pipeline and continuous delivery process. We are always striving to improve the process. Towards
that end it is documented here. that end it is documented here.
@ -20,7 +20,7 @@ Our official Github_ account is Bitmessage. Our issue tracker is here as well.
BitMessage BitMessage
---------- ----------
We eat our own dog food! You can send us bug reports via the [chan] bitmessage BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY We eat our own dog food! You can send us bug reports via the Bitmessage chan at xxx
.. _website: https://bitmessage.org .. _website: https://bitmessage.org

View File

@ -1,17 +1,9 @@
.. mdinclude:: ../README.md .. mdinclude:: ../README.md
Documentation
-------------
.. toctree::
:maxdepth: 3
autodoc/pybitmessage
Legacy pages
------------
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
overview
usage usage
contribute contribute

View File

@ -1,2 +0,0 @@
m2r
sphinxcontrib-apidoc

View File

@ -1,6 +1,6 @@
# Fabric # Fabric
[Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can think of it a bit like a [Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can thing of it a bit like a
makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check
return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts. return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts.
@ -46,7 +46,7 @@ Furthermore, you can use -- to run arbitrary shell commands rather than tasks:
There are a number of advantages that should benefit us: There are a number of advantages that should benefit us:
* Common tasks can be written in Python and executed consistently * Common tasks can be writen in Python and executed consistently
* Common tasks are now under source control * Common tasks are now under source control
* All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv) * All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv)
the user does not have to care the user does not have to care

View File

@ -15,7 +15,7 @@ OSX:
https://github.com/Bitmessage/PyBitmessage/releases https://github.com/Bitmessage/PyBitmessage/releases
Works on OSX 10.7.5 or higher Wors on OSX 10.7.5 or higher
Arch linux: Arch linux:

View File

@ -11,13 +11,13 @@ else:
sslName = 'OpenSSL-Win%s' % ("32" if arch == 32 else "64") sslName = 'OpenSSL-Win%s' % ("32" if arch == 32 else "64")
site_root = os.path.abspath(HOMEPATH) site_root = os.path.abspath(HOMEPATH)
spec_root = os.path.abspath(SPECPATH) spec_root = os.path.abspath(SPECPATH)
cdrivePath = site_root[0:3] cdrivePath= site_root[0:3]
srcPath = os.path.join(spec_root[:-20], "src") srcPath = spec_root[:-20]+"src\\"
qtBase = "PyQt4" qtPath = site_root+"\\PyQt4\\"
openSSLPath = os.path.join(cdrivePath, sslName) openSSLPath = cdrivePath+sslName+"\\"
msvcrDllPath = os.path.join(cdrivePath, "windows", "system32") msvcrDllPath = cdrivePath+"windows\\system32\\"
pythonDllPath = os.path.join(cdrivePath, "Python27") pythonDllPath = cdrivePath+"Python27\\"
outPath = os.path.join(spec_root, "bitmessagemain") outPath = spec_root+"\\bitmessagemain"
importPath = srcPath importPath = srcPath
sys.path.insert(0,importPath) sys.path.insert(0,importPath)
@ -31,9 +31,9 @@ os.rename(os.path.join(srcPath, '__init__.py'), os.path.join(srcPath, '__init__.
# -*- mode: python -*- # -*- mode: python -*-
a = Analysis( a = Analysis(
[os.path.join(srcPath, 'bitmessagemain.py')], [srcPath + 'bitmessagemain.py'],
pathex=[outPath], pathex=[outPath],
hiddenimports=['bitmessageqt.languagebox', 'pyopencl','numpy', 'win32com' , 'setuptools.msvc' ,'_cffi_backend'], hiddenimports=['pyopencl','numpy', 'win32com' , 'setuptools.msvc' ,'_cffi_backend'],
hookspath=None, hookspath=None,
runtime_hooks=None runtime_hooks=None
) )
@ -43,32 +43,23 @@ os.rename(os.path.join(srcPath, '__init__.py.backup'), os.path.join(srcPath, '__
def addTranslations(): def addTranslations():
import os import os
extraDatas = [] extraDatas = []
for file_ in os.listdir(os.path.join(srcPath, 'translations')): for file in os.listdir(srcPath + 'translations'):
if file_[-3:] != ".qm": if file[-3:] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file_), extraDatas.append((os.path.join('translations', file), os.path.join(srcPath, 'translations', file), 'DATA'))
os.path.join(srcPath, 'translations', file_), 'DATA')) for file in os.listdir(qtPath + 'translations'):
for libdir in sys.path: if file[0:3] != "qt_" or file[5:8] != ".qm":
qtdir = os.path.join(libdir, qtBase, 'translations')
if os.path.isdir(qtdir):
break
if not os.path.isdir(qtdir):
return extraDatas
for file_ in os.listdir(qtdir):
if file_[0:3] != "qt_" or file_[5:8] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file_), extraDatas.append((os.path.join('translations', file), os.path.join(qtPath, 'translations', file), 'DATA'))
os.path.join(qtdir, file_), 'DATA'))
return extraDatas return extraDatas
def addUIs(): def addUIs():
import os import os
extraDatas = [] extraDatas = []
for file_ in os.listdir(os.path.join(srcPath, 'bitmessageqt')): for file in os.listdir(srcPath + 'bitmessageqt'):
if file_[-3:] != ".ui": if file[-3:] != ".ui":
continue continue
extraDatas.append((os.path.join('ui', file_), os.path.join(srcPath, extraDatas.append((os.path.join('ui', file), os.path.join(srcPath, 'bitmessageqt', file), 'DATA'))
'bitmessageqt', file_), 'DATA'))
return extraDatas return extraDatas
# append the translations directory # append the translations directory
@ -76,8 +67,10 @@ a.datas += addTranslations()
a.datas += addUIs() a.datas += addUIs()
a.binaries += [('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'),
('python27.dll', os.path.join(pythonDllPath, 'python27.dll'), 'BINARY'), a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'),
('python27.dll', pythonDllPath + 'python27.dll', 'BINARY'),
('msvcr120.dll', msvcrDllPath + 'msvcr120.dll','BINARY'),
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'), (os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'), (os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'), (os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
@ -100,14 +93,14 @@ exe = EXE(pyz,
name=fname, name=fname,
debug=False, debug=False,
strip=None, strip=None,
upx=False, upx=True,
console=False, icon= os.path.join(srcPath, 'images', 'can-icon.ico')) console=True, icon= os.path.join(srcPath, 'images', 'can-icon.ico'))
coll = COLLECT(exe, coll = COLLECT(exe,
a.binaries, a.binaries,
a.zipfiles, a.zipfiles,
a.datas, a.datas,
strip=False, strip=False,
upx=False, upx=True,
name='main') name='main')

View File

@ -1 +0,0 @@
src

View File

@ -1,17 +1,14 @@
# Since there is overlap in the violations that the different tools check for, it makes sense to quiesce some warnings # Since there is overlap in the violations that the different tools check for, it makes sense to quiesce some warnings
# in some tools if those warnings in other tools are preferred. This avoids the need to add duplicate lint warnings. # in some tools if those warnings in other tools are preferred. This avoids the need to add duplicate lint warnings.
# max-line-length should be removed ASAP!
[pycodestyle] [pycodestyle]
max-line-length = 119 max-line-length = 119
[flake8] [flake8]
max-line-length = 119 max-line-length = 119
ignore = E722,F841,W503 ignore = E722,F841
# E722: pylint is preferred for bare-except # E722: pylint is preferred for bare-except
# F841: pylint is preferred for unused-variable # F841: pylint is preferred for unused-variable
# W503: deprecated: https://bugs.python.org/issue26763 - https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
# pylint honours the [MESSAGES CONTROL] section # pylint honours the [MESSAGES CONTROL] section
# as well as [MASTER] section # as well as [MASTER] section

View File

@ -17,7 +17,13 @@ EXTRAS_REQUIRE = {
'qrcode': ['qrcode'], 'qrcode': ['qrcode'],
'sound;platform_system=="Windows"': ['winsound'], 'sound;platform_system=="Windows"': ['winsound'],
'tor': ['stem'], 'tor': ['stem'],
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'] 'docs': [
'sphinx', # fab build_docs
'graphviz', # fab build_docs
'curses', # src/depends.py
'python2-pythondialog', # src/depends.py
'm2r', # fab build_docs
]
} }
@ -64,6 +70,7 @@ if __name__ == "__main__":
'pybitmessage.network', 'pybitmessage.network',
'pybitmessage.plugins', 'pybitmessage.plugins',
'pybitmessage.pyelliptic', 'pybitmessage.pyelliptic',
'pybitmessage.socks',
'pybitmessage.storage' 'pybitmessage.storage'
] ]
@ -149,9 +156,5 @@ if __name__ == "__main__":
# ] # ]
}, },
scripts=['src/pybitmessage'], scripts=['src/pybitmessage'],
cmdclass={'install': InstallCmd}, cmdclass={'install': InstallCmd}
command_options={
'build_sphinx': {
'source_dir': ('setup.py', 'docs')}
}
) )

View File

@ -1,22 +1,25 @@
""" """
Operations with addresses src/addresses.py
================
""" """
# pylint: disable=redefined-outer-name,inconsistent-return-statements # pylint: disable=redefined-outer-name,inconsistent-return-statements
import hashlib import hashlib
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from struct import pack, unpack from struct import pack, unpack
from debug import logger from debug import logger
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def encodeBase58(num, alphabet=ALPHABET): def encodeBase58(num, alphabet=ALPHABET):
"""Encode a number in Base X """Encode a number in Base X
Args: `num`: The number to encode
num: The number to encode `alphabet`: The alphabet to use for encoding
alphabet: The alphabet to use for encoding
""" """
if num == 0: if num == 0:
return alphabet[0] return alphabet[0]
@ -24,6 +27,7 @@ def encodeBase58(num, alphabet=ALPHABET):
base = len(alphabet) base = len(alphabet)
while num: while num:
rem = num % base rem = num % base
# print 'num is:', num
num = num // base num = num // base
arr.append(alphabet[rem]) arr.append(alphabet[rem])
arr.reverse() arr.reverse()
@ -33,9 +37,9 @@ def encodeBase58(num, alphabet=ALPHABET):
def decodeBase58(string, alphabet=ALPHABET): def decodeBase58(string, alphabet=ALPHABET):
"""Decode a Base X encoded string into the number """Decode a Base X encoded string into the number
Args: Arguments:
string: The encoded string - `string`: The encoded string
alphabet: The alphabet to use for encoding - `alphabet`: The alphabet to use for encoding
""" """
base = len(alphabet) base = len(alphabet)
num = 0 num = 0
@ -50,20 +54,11 @@ def decodeBase58(string, alphabet=ALPHABET):
return num return num
class varintEncodeError(Exception):
"""Exception class for encoding varint"""
pass
class varintDecodeError(Exception):
"""Exception class for decoding varint data"""
pass
def encodeVarint(integer): def encodeVarint(integer):
"""Convert integer into varint bytes""" """Convert integer into varint bytes"""
if integer < 0: if integer < 0:
raise varintEncodeError('varint cannot be < 0') logger.error('varint cannot be < 0')
raise SystemExit
if integer < 253: if integer < 253:
return pack('>B', integer) return pack('>B', integer)
if integer >= 253 and integer < 65536: if integer >= 253 and integer < 65536:
@ -73,7 +68,13 @@ def encodeVarint(integer):
if integer >= 4294967296 and integer < 18446744073709551616: if integer >= 4294967296 and integer < 18446744073709551616:
return pack('>B', 255) + pack('>Q', integer) return pack('>B', 255) + pack('>Q', integer)
if integer >= 18446744073709551616: if integer >= 18446744073709551616:
raise varintEncodeError('varint cannot be >= 18446744073709551616') logger.error('varint cannot be >= 18446744073709551616')
raise SystemExit
class varintDecodeError(Exception):
"""Exception class for decoding varint data"""
pass
def decodeVarint(data): def decodeVarint(data):
@ -178,8 +179,7 @@ def decodeAddress(address):
returns (status, address version number, stream number, returns (status, address version number, stream number,
data (almost certainly a ripe hash)) data (almost certainly a ripe hash))
""" """
# pylint: disable=too-many-return-statements,too-many-statements # pylint: disable=too-many-return-statements,too-many-statements,too-many-return-statements,too-many-branches
# pylint: disable=too-many-branches
address = str(address).strip() address = str(address).strip()

View File

@ -1,11 +1,19 @@
# pylint: disable=too-many-locals,too-many-lines,no-self-use,too-many-public-methods,too-many-branches
# pylint: disable=too-many-statements
""" """
src/api.py
==========
# Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2019 The Bitmessage developers
This is not what you run to run the Bitmessage API. Instead, enable the API This is not what you run to run the Bitmessage API. Instead, enable the API
( https://bitmessage.org/wiki/API ) and optionally enable daemon mode ( https://bitmessage.org/wiki/API ) and optionally enable daemon mode
( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py. ( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py.
""" """
# Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2020 The Bitmessage developers from __future__ import absolute_import
# pylint: disable=too-many-lines,no-self-use,unused-variable,unused-argument
import base64 import base64
import errno import errno
import hashlib import hashlib
@ -18,6 +26,8 @@ from binascii import hexlify, unhexlify
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
from struct import pack from struct import pack
from version import softwareVersion
import defaults import defaults
import helper_inbox import helper_inbox
import helper_sent import helper_sent
@ -27,20 +37,13 @@ import queues
import shared import shared
import shutdown import shutdown
import state import state
from addresses import ( from addresses import addBMIfNotPresent, calculateInventoryHash, decodeAddress, decodeVarint, varintDecodeError
addBMIfNotPresent,
calculateInventoryHash,
decodeAddress,
decodeVarint,
varintDecodeError
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger from debug import logger
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
from helper_threading import StoppableThread
from inventory import Inventory from inventory import Inventory
from network.threads import StoppableThread
from version import softwareVersion
str_chan = '[chan]' str_chan = '[chan]'
@ -96,8 +99,6 @@ class singleAPI(StoppableThread):
for attempt in range(50): for attempt in range(50):
try: try:
if attempt > 0: if attempt > 0:
logger.warning(
'Failed to start API listener on port %s', port)
port = random.randint(32767, 65535) port = random.randint(32767, 65535)
se = StoppableXMLRPCServer( se = StoppableXMLRPCServer(
(BMConfigParser().get( (BMConfigParser().get(
@ -109,9 +110,8 @@ class singleAPI(StoppableThread):
continue continue
else: else:
if attempt > 0: if attempt > 0:
logger.warning('Setting apiport to %s', port)
BMConfigParser().set( BMConfigParser().set(
'bitmessagesettings', 'apiport', str(port)) "bitmessagesettings", "apiport", str(port))
BMConfigParser().save() BMConfigParser().save()
break break
se.register_introspection_functions() se.register_introspection_functions()
@ -137,11 +137,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
""" """
This is one of several classes that constitute the API This is one of several classes that constitute the API
This class was written by Vaibhav Bhatia. This class was written by Vaibhav Bhatia. Modified by Jonathan Warren (Atheros).
Modified by Jonathan Warren (Atheros).
http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/ http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
""" """
# pylint: disable=too-many-public-methods
def do_POST(self): def do_POST(self):
""" """
@ -178,8 +176,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# SimpleXMLRPCDispatcher. To maintain backwards compatibility, # SimpleXMLRPCDispatcher. To maintain backwards compatibility,
# check to see if a subclass implements _dispatch and dispatch # check to see if a subclass implements _dispatch and dispatch
# using that method if present. # using that method if present.
# pylint: disable=protected-access response = self.server._marshaled_dispatch( # pylint: disable=protected-access
response = self.server._marshaled_dispatch(
data, getattr(self, '_dispatch', None) data, getattr(self, '_dispatch', None)
) )
except BaseException: # This should only happen if the module is buggy except BaseException: # This should only happen if the module is buggy
@ -217,10 +214,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
_, encstr = self.headers.get('Authorization').split() _, encstr = self.headers.get('Authorization').split()
emailid, password = encstr.decode('base64').split(':') emailid, password = encstr.decode('base64').split(':')
return ( return (
emailid == BMConfigParser().get( emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and
'bitmessagesettings', 'apiusername') and password == BMConfigParser().get('bitmessagesettings', 'apipassword')
password == BMConfigParser().get(
'bitmessagesettings', 'apipassword')
) )
else: else:
logger.warning( logger.warning(
@ -257,14 +252,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
if status == 'invalidcharacters': if status == 'invalidcharacters':
raise APIError(9, 'Invalid characters in address: ' + address) raise APIError(9, 'Invalid characters in address: ' + address)
if status == 'versiontoohigh': if status == 'versiontoohigh':
raise APIError( raise APIError(10, 'Address version number too high (or zero) in address: ' + address)
10,
'Address version number too high (or zero) in address: ' +
address)
if status == 'varintmalformed': if status == 'varintmalformed':
raise APIError(26, 'Malformed varint in address: ' + address) raise APIError(26, 'Malformed varint in address: ' + address)
raise APIError( raise APIError(7, 'Could not decode address: %s : %s' % (address, status))
7, 'Could not decode address: %s : %s' % (address, status))
if addressVersionNumber < 2 or addressVersionNumber > 4: if addressVersionNumber < 2 or addressVersionNumber > 4:
raise APIError( raise APIError(
11, 'The address version number currently must be 2, 3 or 4.' 11, 'The address version number currently must be 2, 3 or 4.'
@ -282,9 +273,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def HandleListAddresses(self, method): def HandleListAddresses(self, method):
"""Handle a request to list addresses""" """Handle a request to list addresses"""
data = '{"addresses":[' data = '{"addresses":['
for addressInKeysFile in BMConfigParser().addresses(): for addressInKeysFile in BMConfigParser().addresses():
status, addressVersionNumber, streamNumber, hash01 = decodeAddress( status, addressVersionNumber, streamNumber, hash01 = decodeAddress( # pylint: disable=unused-variable
addressInKeysFile) addressInKeysFile)
if len(data) > 20: if len(data) > 20:
data += ',' data += ','
@ -388,19 +380,16 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
elif len(params) == 3: elif len(params) == 3:
label, eighteenByteRipe, totalDifficulty = params label, eighteenByteRipe, totalDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get( payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 4: elif len(params) == 4:
label, eighteenByteRipe, totalDifficulty, \ label, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params smallMessageDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = int( payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
smallMessageDifficulty)
else: else:
raise APIError(0, 'Too many parameters!') raise APIError(0, 'Too many parameters!')
label = self._decode(label, "base64") label = self._decode(label, "base64")
@ -418,7 +407,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def HandleCreateDeterministicAddresses(self, params): def HandleCreateDeterministicAddresses(self, params):
"""Handle a request to create a deterministic address""" """Handle a request to create a deterministic address"""
# pylint: disable=too-many-branches, too-many-statements
if not params: if not params:
raise APIError(0, 'I need parameters!') raise APIError(0, 'I need parameters!')
@ -474,8 +462,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
passphrase, numberOfAddresses, addressVersionNumber, \ passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber, eighteenByteRipe, totalDifficulty = params streamNumber, eighteenByteRipe, totalDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get( payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes')
@ -484,11 +471,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
streamNumber, eighteenByteRipe, totalDifficulty, \ streamNumber, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params smallMessageDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = int( payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
smallMessageDifficulty)
else: else:
raise APIError(0, 'Too many parameters!') raise APIError(0, 'Too many parameters!')
if not passphrase: if not passphrase:
@ -622,8 +607,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
label = str_chan + ' ' + passphrase label = str_chan + ' ' + passphrase
except BaseException: except BaseException:
label = str_chan + ' ' + repr(passphrase) label = str_chan + ' ' + repr(passphrase)
status, addressVersionNumber, streamNumber, toRipe = (
self._verifyAddress(suppliedAddress)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress( # pylint: disable=unused-variable
suppliedAddress)
suppliedAddress = addBMIfNotPresent(suppliedAddress) suppliedAddress = addBMIfNotPresent(suppliedAddress)
queues.apiAddressGeneratorReturnQueue.queue.clear() queues.apiAddressGeneratorReturnQueue.queue.clear()
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
@ -646,8 +632,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
raise APIError(0, 'I need parameters.') raise APIError(0, 'I need parameters.')
elif len(params) == 1: elif len(params) == 1:
address, = params address, = params
status, addressVersionNumber, streamNumber, toRipe = ( # pylint: disable=unused-variable
self._verifyAddress(address)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address): if not BMConfigParser().has_section(address):
raise APIError( raise APIError(
@ -668,8 +654,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
raise APIError(0, 'I need parameters.') raise APIError(0, 'I need parameters.')
elif len(params) == 1: elif len(params) == 1:
address, = params address, = params
status, addressVersionNumber, streamNumber, toRipe = ( # pylint: disable=unused-variable
self._verifyAddress(address)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address): if not BMConfigParser().has_section(address):
raise APIError( raise APIError(
@ -681,7 +667,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
return 'success' return 'success'
def HandleGetAllInboxMessages(self, params): def HandleGetAllInboxMessages(self, params): # pylint: disable=unused-argument
"""Handle a request to get all inbox messages""" """Handle a request to get all inbox messages"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -709,7 +695,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllInboxMessageIds(self, params): def HandleGetAllInboxMessageIds(self, params): # pylint: disable=unused-argument
"""Handle a request to get all inbox message IDs""" """Handle a request to get all inbox message IDs"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -768,7 +754,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllSentMessages(self, params): def HandleGetAllSentMessages(self, params): # pylint: disable=unused-argument
"""Handle a request to get all sent messages""" """Handle a request to get all sent messages"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -797,7 +783,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllSentMessageIds(self, params): def HandleGetAllSentMessageIds(self, params): # pylint: disable=unused-argument
"""Handle a request to get all sent message IDs""" """Handle a request to get all sent message IDs"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -888,7 +874,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data = '{"sentMessages":[' data = '{"sentMessages":['
for row in queryreturn: for row in queryreturn:
msgid, toAddress, fromAddress, subject, lastactiontime, message, \ msgid, toAddress, fromAddress, subject, lastactiontime, message, \
encodingtype, status, ackdata = row encodingtype, status, ackdata = row # pylint: disable=unused-variable
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message) message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25: if len(data) > 25:
@ -967,7 +953,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleSendMessage(self, params): # pylint: disable=too-many-locals def HandleSendMessage(self, params):
"""Handle a request to send a message""" """Handle a request to send a message"""
if not params: if not params:
@ -998,6 +984,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
TTL = 28 * 24 * 60 * 60 TTL = 28 * 24 * 60 * 60
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
# pylint: disable=unused-variable
status, addressVersionNumber, streamNumber, toRipe = \ status, addressVersionNumber, streamNumber, toRipe = \
self._verifyAddress(toAddress) self._verifyAddress(toAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
@ -1171,9 +1158,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queues.UISignalQueue.put(('rerenderSubscriptions', '')) queues.UISignalQueue.put(('rerenderSubscriptions', ''))
return 'Deleted subscription if it existed.' return 'Deleted subscription if it existed.'
def ListSubscriptions(self, params): def ListSubscriptions(self, params): # pylint: disable=unused-argument
"""Handle a request to list susbcriptions""" """Handle a request to list susbcriptions"""
# pylint: disable=unused-variable
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT label, address, enabled FROM subscriptions") "SELECT label, address, enabled FROM subscriptions")
data = {'subscriptions': []} data = {'subscriptions': []}
@ -1208,15 +1196,12 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
) )
with shared.printLock: with shared.printLock:
print( print(
'(For msg message via API) Doing proof of work.' '(For msg message via API) Doing proof of work. Total required difficulty:',
'Total required difficulty:',
float( float(
requiredAverageProofOfWorkNonceTrialsPerByte requiredAverageProofOfWorkNonceTrialsPerByte
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte, ) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
'Required small message difficulty:', 'Required small message difficulty:',
float( float(requiredPayloadLengthExtraBytes) / defaults.networkDefaultPayloadLengthExtraBytes,
requiredPayloadLengthExtraBytes
) / defaults.networkDefaultPayloadLengthExtraBytes,
) )
powStartTime = time.time() powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest() initialHash = hashlib.sha512(encryptedPayload).digest()
@ -1225,9 +1210,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
try: try:
print( print(
'POW took', int(time.time() - powStartTime), 'POW took', int(time.time() - powStartTime), 'seconds.',
'seconds.', nonce / (time.time() - powStartTime), nonce / (time.time() - powStartTime), 'nonce trials per second.',
'nonce trials per second.',
) )
except BaseException: except BaseException:
pass pass
@ -1254,7 +1238,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata) sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleDissimatePubKey(self, params): def HandleDissimatePubKey(self, params): # pylint: disable=unused-argument
"""Handle a request to disseminate a public key""" """Handle a request to disseminate a public key"""
# The device issuing this command to PyBitmessage supplies a pubkey # The device issuing this command to PyBitmessage supplies a pubkey
@ -1283,6 +1267,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
pubkeyReadPosition += 8 pubkeyReadPosition += 8
else: else:
pubkeyReadPosition += 4 pubkeyReadPosition += 4
# pylint: disable=unused-variable
addressVersion, addressVersionLength = decodeVarint( addressVersion, addressVersionLength = decodeVarint(
payload[pubkeyReadPosition:pubkeyReadPosition + 10]) payload[pubkeyReadPosition:pubkeyReadPosition + 10])
pubkeyReadPosition += addressVersionLength pubkeyReadPosition += addressVersionLength
@ -1341,7 +1326,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleClientStatus(self, params): def HandleClientStatus(self, params): # pylint: disable=unused-argument
"""Handle a request to get the status of the client""" """Handle a request to get the status of the client"""
connections_num = len(network.stats.connectedHostsList()) connections_num = len(network.stats.connectedHostsList())

View File

@ -13,15 +13,15 @@ TODO: fix the following (currently ignored) violations:
""" """
import xmlrpclib
import datetime import datetime
import imghdr import imghdr
import json
import ntpath import ntpath
import os import json
import socket import socket
import sys
import time import time
import xmlrpclib import sys
import os
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser

View File

@ -1,6 +1,3 @@
"""
Bitmessage commandline interface
"""
# Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com> # Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com>
# This file adds a alternative commandline interface, feel free to critique and fork # This file adds a alternative commandline interface, feel free to critique and fork
# #
@ -10,30 +7,34 @@ Bitmessage commandline interface
# * python2-pythondialog # * python2-pythondialog
# * dialog # * dialog
import ConfigParser
import curses
import os import os
import sys import sys
import StringIO
from textwrap import *
import time import time
from textwrap import fill from time import strftime, localtime
from threading import Timer from threading import Timer
import curses
import dialog
from dialog import Dialog from dialog import Dialog
from helper_sql import *
from helper_ackPayload import genAckPayload
from addresses import *
import ConfigParser
from bmconfigparser import BMConfigParser
from inventory import Inventory
import l10n import l10n
import network.stats from pyelliptic.openssl import OpenSSL
import queues import queues
import shared import shared
import shutdown import shutdown
import network.stats
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
# pylint: disable=global-statement
quit_ = False quit = False
menutab = 1 menutab = 1
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"] menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
naptime = 100 naptime = 100
@ -59,194 +60,155 @@ bwtype = "black"
BROADCAST_STR = "[Broadcast subscribers]" BROADCAST_STR = "[Broadcast subscribers]"
class printLog:
class printLog(object):
"""Printing logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
"""Write logs"""
global log global log
log += output log += output
def flush(self): def flush(self):
"""Flush logs"""
pass pass
class errLog:
class errLog(object):
"""Error logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
"""Write error logs"""
global log global log
log += "!" + output log += "!"+output
def flush(self): def flush(self):
"""Flush error logs"""
pass pass
printlog = printLog() printlog = printLog()
errlog = errLog() errlog = errLog()
def cpair(a): def cpair(a):
"""Color pairs"""
r = curses.color_pair(a) r = curses.color_pair(a)
if r not in range(1, curses.COLOR_PAIRS - 1): if r not in range(1, curses.COLOR_PAIRS-1):
r = curses.color_pair(0) r = curses.color_pair(0)
return r return r
def ascii(s): def ascii(s):
"""ASCII values"""
r = "" r = ""
for c in s: for c in s:
if ord(c) in range(128): if ord(c) in range(128):
r += c r += c
return r return r
def drawmenu(stdscr): def drawmenu(stdscr):
"""Creating menu's"""
menustr = " " menustr = " "
for i, _ in enumerate(menu): for i in range(0, len(menu)):
if menutab == i + 1: if menutab == i+1:
menustr = menustr[:-1] menustr = menustr[:-1]
menustr += "[" menustr += "["
menustr += str(i + 1) + menu[i] menustr += str(i+1)+menu[i]
if menutab == i + 1: if menutab == i+1:
menustr += "] " menustr += "] "
elif i != len(menu) - 1: elif i != len(menu)-1:
menustr += " " menustr += " "
stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE) stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE)
def set_background_title(d, title): def set_background_title(d, title):
"""Setting background title"""
try: try:
d.set_background_title(title) d.set_background_title(title)
except: except:
d.add_persistent_args(("--backtitle", title)) d.add_persistent_args(("--backtitle", title))
def scrollbox(d, text, height=None, width=None): def scrollbox(d, text, height=None, width=None):
"""Setting scroll box"""
try: try:
d.scrollbox(text, height, width, exit_label="Continue") d.scrollbox(text, height, width, exit_label = "Continue")
except: except:
d.msgbox(text, height or 0, width or 0, ok_label="Continue") d.msgbox(text, height or 0, width or 0, ok_label = "Continue")
def resetlookups(): def resetlookups():
"""Reset the Inventory Lookups"""
global inventorydata global inventorydata
inventorydata = Inventory().numberOfInventoryLookupsPerformed inventorydata = Inventory().numberOfInventoryLookupsPerformed
Inventory().numberOfInventoryLookupsPerformed = 0 Inventory().numberOfInventoryLookupsPerformed = 0
Timer(1, resetlookups, ()).start() Timer(1, resetlookups, ()).start()
def drawtab(stdscr): def drawtab(stdscr):
"""Method for drawing different tabs""" if menutab in range(1, len(menu)+1):
# pylint: disable=too-many-branches, too-many-statements
if menutab in range(1, len(menu) + 1):
if menutab == 1: # Inbox if menutab == 1: # Inbox
stdscr.addstr(3, 5, "To", curses.A_BOLD) stdscr.addstr(3, 5, "To", curses.A_BOLD)
stdscr.addstr(3, 40, "From", curses.A_BOLD) stdscr.addstr(3, 40, "From", curses.A_BOLD)
stdscr.addstr(3, 80, "Subject", curses.A_BOLD) stdscr.addstr(3, 80, "Subject", curses.A_BOLD)
stdscr.addstr(3, 120, "Time Received", curses.A_BOLD) stdscr.addstr(3, 120, "Time Received", curses.A_BOLD)
stdscr.hline(4, 5, '-', 121) stdscr.hline(4, 5, '-', 121)
for i, item in enumerate(inbox[max(min(len(inbox) - curses.LINES + 6, inboxcur - 5), 0):]): for i, item in enumerate(inbox[max(min(len(inbox)-curses.LINES+6, inboxcur-5), 0):]):
if 6 + i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == inboxcur - max(min(len(inbox) - curses.LINES + 6, inboxcur - 5), 0): if i == inboxcur - max(min(len(inbox)-curses.LINES+6, inboxcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[7] is False: # If not read, highlight if item[7] == False: # If not read, highlight
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5 + i, 5, item[1][:34], a) stdscr.addstr(5+i, 5, item[1][:34], a)
stdscr.addstr(5 + i, 40, item[3][:39], a) stdscr.addstr(5+i, 40, item[3][:39], a)
stdscr.addstr(5 + i, 80, item[5][:39], a) stdscr.addstr(5+i, 80, item[5][:39], a)
stdscr.addstr(5 + i, 120, item[6][:39], a) stdscr.addstr(5+i, 120, item[6][:39], a)
elif menutab == 3: # Sent elif menutab == 3: # Sent
stdscr.addstr(3, 5, "To", curses.A_BOLD) stdscr.addstr(3, 5, "To", curses.A_BOLD)
stdscr.addstr(3, 40, "From", curses.A_BOLD) stdscr.addstr(3, 40, "From", curses.A_BOLD)
stdscr.addstr(3, 80, "Subject", curses.A_BOLD) stdscr.addstr(3, 80, "Subject", curses.A_BOLD)
stdscr.addstr(3, 120, "Status", curses.A_BOLD) stdscr.addstr(3, 120, "Status", curses.A_BOLD)
stdscr.hline(4, 5, '-', 121) stdscr.hline(4, 5, '-', 121)
for i, item in enumerate(sentbox[max(min(len(sentbox) - curses.LINES + 6, sentcur - 5), 0):]): for i, item in enumerate(sentbox[max(min(len(sentbox)-curses.LINES+6, sentcur-5), 0):]):
if 6 + i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == sentcur - max(min(len(sentbox) - curses.LINES + 6, sentcur - 5), 0): if i == sentcur - max(min(len(sentbox)-curses.LINES+6, sentcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
stdscr.addstr(5 + i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5 + i, 40, item[2][:39], a) stdscr.addstr(5+i, 40, item[2][:39], a)
stdscr.addstr(5 + i, 80, item[4][:39], a) stdscr.addstr(5+i, 80, item[4][:39], a)
stdscr.addstr(5 + i, 120, item[5][:39], a) stdscr.addstr(5+i, 120, item[5][:39], a)
elif menutab == 2 or menutab == 4: # Send or Identities elif menutab == 2 or menutab == 4: # Send or Identities
stdscr.addstr(3, 5, "Label", curses.A_BOLD) stdscr.addstr(3, 5, "Label", curses.A_BOLD)
stdscr.addstr(3, 40, "Address", curses.A_BOLD) stdscr.addstr(3, 40, "Address", curses.A_BOLD)
stdscr.addstr(3, 80, "Stream", curses.A_BOLD) stdscr.addstr(3, 80, "Stream", curses.A_BOLD)
stdscr.hline(4, 5, '-', 81) stdscr.hline(4, 5, '-', 81)
for i, item in enumerate(addresses[max(min(len(addresses) - curses.LINES + 6, addrcur - 5), 0):]): for i, item in enumerate(addresses[max(min(len(addresses)-curses.LINES+6, addrcur-5), 0):]):
if 6 + i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == addrcur - max(min(len(addresses) - curses.LINES + 6, addrcur - 5), 0): if i == addrcur - max(min(len(addresses)-curses.LINES+6, addrcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[1] and item[3] not in [8, 9]: # Embolden enabled, non-special addresses if item[1] == True and item[3] not in [8,9]: # Embolden enabled, non-special addresses
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5 + i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5 + i, 40, item[2][:39], cpair(item[3]) | a) stdscr.addstr(5+i, 40, item[2][:39], cpair(item[3]) | a)
stdscr.addstr(5 + i, 80, str(1)[:39], a) stdscr.addstr(5+i, 80, str(1)[:39], a)
elif menutab == 5: # Subscriptions elif menutab == 5: # Subscriptions
stdscr.addstr(3, 5, "Label", curses.A_BOLD) stdscr.addstr(3, 5, "Label", curses.A_BOLD)
stdscr.addstr(3, 80, "Address", curses.A_BOLD) stdscr.addstr(3, 80, "Address", curses.A_BOLD)
stdscr.addstr(3, 120, "Enabled", curses.A_BOLD) stdscr.addstr(3, 120, "Enabled", curses.A_BOLD)
stdscr.hline(4, 5, '-', 121) stdscr.hline(4, 5, '-', 121)
for i, item in enumerate(subscriptions[max(min(len(subscriptions) - curses.LINES + 6, subcur - 5), 0):]): for i, item in enumerate(subscriptions[max(min(len(subscriptions)-curses.LINES+6, subcur-5), 0):]):
if 6 + i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == subcur - max(min(len(subscriptions) - curses.LINES + 6, subcur - 5), 0): if i == subcur - max(min(len(subscriptions)-curses.LINES+6, subcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[2]: # Embolden enabled subscriptions if item[2] == True: # Embolden enabled subscriptions
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5 + i, 5, item[0][:74], a) stdscr.addstr(5+i, 5, item[0][:74], a)
stdscr.addstr(5 + i, 80, item[1][:39], a) stdscr.addstr(5+i, 80, item[1][:39], a)
stdscr.addstr(5 + i, 120, str(item[2]), a) stdscr.addstr(5+i, 120, str(item[2]), a)
elif menutab == 6: # Address book elif menutab == 6: # Address book
stdscr.addstr(3, 5, "Label", curses.A_BOLD) stdscr.addstr(3, 5, "Label", curses.A_BOLD)
stdscr.addstr(3, 40, "Address", curses.A_BOLD) stdscr.addstr(3, 40, "Address", curses.A_BOLD)
stdscr.hline(4, 5, '-', 41) stdscr.hline(4, 5, '-', 41)
for i, item in enumerate(addrbook[max(min(len(addrbook) - curses.LINES + 6, abookcur - 5), 0):]): for i, item in enumerate(addrbook[max(min(len(addrbook)-curses.LINES+6, abookcur-5), 0):]):
if 6 + i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == abookcur - max(min(len(addrbook) - curses.LINES + 6, abookcur - 5), 0): if i == abookcur - max(min(len(addrbook)-curses.LINES+6, abookcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
stdscr.addstr(5 + i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5 + i, 40, item[1][:39], a) stdscr.addstr(5+i, 40, item[1][:39], a)
elif menutab == 7: # Blacklist elif menutab == 7: # Blacklist
stdscr.addstr(3, 5, "Type: " + bwtype) stdscr.addstr(3, 5, "Type: "+bwtype)
stdscr.addstr(4, 5, "Label", curses.A_BOLD) stdscr.addstr(4, 5, "Label", curses.A_BOLD)
stdscr.addstr(4, 80, "Address", curses.A_BOLD) stdscr.addstr(4, 80, "Address", curses.A_BOLD)
stdscr.addstr(4, 120, "Enabled", curses.A_BOLD) stdscr.addstr(4, 120, "Enabled", curses.A_BOLD)
stdscr.hline(5, 5, '-', 121) stdscr.hline(5, 5, '-', 121)
for i, item in enumerate(blacklist[max(min(len(blacklist) - curses.LINES + 6, blackcur - 5), 0):]): for i, item in enumerate(blacklist[max(min(len(blacklist)-curses.LINES+6, blackcur-5), 0):]):
if 7 + i < curses.LINES: if 7+i < curses.LINES:
a = 0 a = 0
if i == blackcur - max(min(len(blacklist) - curses.LINES + 6, blackcur - 5), 0): if i == blackcur - max(min(len(blacklist)-curses.LINES+6, blackcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[2]: # Embolden enabled subscriptions if item[2] == True: # Embolden enabled subscriptions
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(6 + i, 5, item[0][:74], a) stdscr.addstr(6+i, 5, item[0][:74], a)
stdscr.addstr(6 + i, 80, item[1][:39], a) stdscr.addstr(6+i, 80, item[1][:39], a)
stdscr.addstr(6 + i, 120, str(item[2]), a) stdscr.addstr(6+i, 120, str(item[2]), a)
elif menutab == 8: # Network status elif menutab == 8: # Network status
# Connection data # Connection data
connected_hosts = network.stats.connectedHostsList() connected_hosts = network.stats.connectedHostsList()
@ -266,61 +228,48 @@ def drawtab(stdscr):
for i, item in enumerate(streamcount): for i, item in enumerate(streamcount):
if i < 4: if i < 4:
if i == 0: if i == 0:
stdscr.addstr(8 + i, 6, "?") stdscr.addstr(8+i, 6, "?")
else: else:
stdscr.addstr(8 + i, 6, str(i)) stdscr.addstr(8+i, 6, str(i))
stdscr.addstr(8 + i, 18, str(item).ljust(2)) stdscr.addstr(8+i, 18, str(item).ljust(2))
# Uptime and processing data # Uptime and processing data
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False)) stdscr.addstr(6, 35, "Since startup on "+l10n.formatTimestamp(startuptime, False))
stdscr.addstr(7, 40, "Processed " + str( stdscr.addstr(7, 40, "Processed "+str(shared.numberOfMessagesProcessed).ljust(4)+" person-to-person messages.")
shared.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.") stdscr.addstr(8, 40, "Processed "+str(shared.numberOfBroadcastsProcessed).ljust(4)+" broadcast messages.")
stdscr.addstr(8, 40, "Processed " + str( stdscr.addstr(9, 40, "Processed "+str(shared.numberOfPubkeysProcessed).ljust(4)+" public keys.")
shared.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
stdscr.addstr(9, 40, "Processed " + str(
shared.numberOfPubkeysProcessed).ljust(4) + " public keys.")
# Inventory data # Inventory data
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3)) stdscr.addstr(11, 35, "Inventory lookups per second: "+str(inventorydata).ljust(3))
# Log # Log
stdscr.addstr(13, 6, "Log", curses.A_BOLD) stdscr.addstr(13, 6, "Log", curses.A_BOLD)
n = log.count('\n') n = log.count('\n')
if n > 0: if n > 0:
lg = log.split('\n') l = log.split('\n')
if n > 512: if n > 512:
del lg[:(n - 256)] del l[:(n-256)]
logpad.erase() logpad.erase()
n = len(lg) n = len(l)
for i, item in enumerate(lg): for i, item in enumerate(l):
a = 0 a = 0
if item and item[0] == '!': if len(item) > 0 and item[0] == '!':
a = curses.color_pair(1) a = curses.color_pair(1)
item = item[1:] item = item[1:]
logpad.addstr(i, 0, item, a) logpad.addstr(i, 0, item, a)
logpad.refresh(n - curses.LINES + 2, 0, 14, 6, curses.LINES - 2, curses.COLS - 7) logpad.refresh(n-curses.LINES+2, 0, 14, 6, curses.LINES-2, curses.COLS-7)
stdscr.refresh() stdscr.refresh()
def redraw(stdscr): def redraw(stdscr):
"""Redraw menu"""
stdscr.erase() stdscr.erase()
stdscr.border() stdscr.border()
drawmenu(stdscr) drawmenu(stdscr)
stdscr.refresh() stdscr.refresh()
def dialogreset(stdscr): def dialogreset(stdscr):
"""Resetting dialogue"""
stdscr.clear() stdscr.clear()
stdscr.keypad(1) stdscr.keypad(1)
curses.curs_set(0) curses.curs_set(0)
# pylint: disable=too-many-branches, too-many-statements
def handlech(c, stdscr): def handlech(c, stdscr):
"""Handle character given on the command-line interface"""
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals
if c != curses.ERR: if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256): if c in range(256):
@ -328,17 +277,15 @@ def handlech(c, stdscr):
global menutab global menutab
menutab = int(chr(c)) menutab = int(chr(c))
elif chr(c) == 'q': elif chr(c) == 'q':
global quit_ global quit
quit_ = True quit = True
elif chr(c) == '\n': elif chr(c) == '\n':
curses.curs_set(1) curses.curs_set(1)
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
if menutab == 1: if menutab == 1:
set_background_title(d, "Inbox Message Dialog Box") set_background_title(d, "Inbox Message Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\"?",
"Do what with \"" + inbox[inboxcur][5] + "\" from \"" + inbox[inboxcur][3] + "\"?", choices=[("1", "View message"),
choices=[
("1", "View message"),
("2", "Mark message as unread"), ("2", "Mark message as unread"),
("3", "Reply"), ("3", "Reply"),
("4", "Add sender to Address Book"), ("4", "Add sender to Address Book"),
@ -346,16 +293,8 @@ def handlech(c, stdscr):
("6", "Move to trash")]) ("6", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
set_background_title( set_background_title(d, "\""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\" to \""+inbox[inboxcur][1]+"\"")
d, data = ""
"\"" +
inbox[inboxcur][5] +
"\" from \"" +
inbox[inboxcur][3] +
"\" to \"" +
inbox[inboxcur][1] +
"\"")
data = "" # pyint: disable=redefined-outer-name
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0]) ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
if ret != []: if ret != []:
for row in ret: for row in ret:
@ -363,7 +302,7 @@ def handlech(c, stdscr):
data = shared.fixPotentiallyInvalidUTF8Data(data) data = shared.fixPotentiallyInvalidUTF8Data(data)
msg = "" msg = ""
for i, item in enumerate(data.split("\n")): for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False) + "\n" msg += fill(item, replace_whitespace=False)+"\n"
scrollbox(d, unicode(ascii(msg)), 30, 80) scrollbox(d, unicode(ascii(msg)), 30, 80)
sqlExecute("UPDATE inbox SET read=1 WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET read=1 WHERE msgid=?", inbox[inboxcur][0])
inbox[inboxcur][7] = 1 inbox[inboxcur][7] = 1
@ -381,10 +320,8 @@ def handlech(c, stdscr):
if fromaddr == item[2] and item[3] != 0: if fromaddr == item[2] and item[3] != 0:
ischan = True ischan = True
break break
if not addresses[i][1]: # pylint: disable=undefined-loop-variable if not addresses[i][1]:
scrollbox(d, unicode( scrollbox(d, unicode("Sending address disabled, please either enable it or choose a different address."))
"Sending address disabled, please either enable it"
"or choose a different address."))
return return
toaddr = m[2] toaddr = m[2]
if ischan: if ischan:
@ -392,7 +329,7 @@ def handlech(c, stdscr):
subject = m[5] subject = m[5]
if not m[5][:4] == "Re: ": if not m[5][:4] == "Re: ":
subject = "Re: " + m[5] subject = "Re: "+m[5]
body = "" body = ""
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", m[0]) ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", m[0])
if ret != []: if ret != []:
@ -404,8 +341,8 @@ def handlech(c, stdscr):
dialogreset(stdscr) dialogreset(stdscr)
elif t == "4": # Add to Address Book elif t == "4": # Add to Address Book
addr = inbox[inboxcur][4] addr = inbox[inboxcur][4]
if addr not in [item[1] for i, item in enumerate(addrbook)]: if addr not in [item[1] for i,item in enumerate(addrbook)]:
r, t = d.inputbox("Label for address \"" + addr + "\"") r, t = d.inputbox("Label for address \""+addr+"\"")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
label = t label = t
sqlExecute("INSERT INTO addressbook VALUES (?,?)", label, addr) sqlExecute("INSERT INTO addressbook VALUES (?,?)", label, addr)
@ -416,8 +353,8 @@ def handlech(c, stdscr):
else: else:
scrollbox(d, unicode("The selected address is already in the Address Book.")) scrollbox(d, unicode("The selected address is already in the Address Book."))
elif t == "5": # Save message elif t == "5": # Save message
set_background_title(d, "Save \"" + inbox[inboxcur][5] + "\" as text file") set_background_title(d, "Save \""+inbox[inboxcur][5]+"\" as text file")
r, t = d.inputbox("Filename", init=inbox[inboxcur][5] + ".txt") r, t = d.inputbox("Filename", init=inbox[inboxcur][5]+".txt")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
msg = "" msg = ""
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0]) ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
@ -432,9 +369,7 @@ def handlech(c, stdscr):
elif t == "6": # Move to trash elif t == "6": # Move to trash
sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0])
del inbox[inboxcur] del inbox[inboxcur]
scrollbox(d, unicode( scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
"Message moved to trash. There is no interface to view your trash,"
" \nbut the message is still on disk if you are desperate to recover it."))
elif menutab == 2: elif menutab == 2:
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
@ -442,58 +377,36 @@ def handlech(c, stdscr):
sendMessage(addresses[addrcur][2], a) sendMessage(addresses[addrcur][2], a)
elif menutab == 3: elif menutab == 3:
set_background_title(d, "Sent Messages Dialog Box") set_background_title(d, "Sent Messages Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+sentbox[sentcur][4]+"\" to \""+sentbox[sentcur][0]+"\"?",
"Do what with \"" + sentbox[sentcur][4] + "\" to \"" + sentbox[sentcur][0] + "\"?", choices=[("1", "View message"),
choices=[
("1", "View message"),
("2", "Move to trash")]) ("2", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
set_background_title( set_background_title(d, "\""+sentbox[sentcur][4]+"\" from \""+sentbox[sentcur][3]+"\" to \""+sentbox[sentcur][1]+"\"")
d,
"\"" +
sentbox[sentcur][4] +
"\" from \"" +
sentbox[sentcur][3] +
"\" to \"" +
sentbox[sentcur][1] +
"\"")
data = "" data = ""
ret = sqlQuery( ret = sqlQuery("SELECT message FROM sent WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
"SELECT message FROM sent WHERE subject=? AND ackdata=?",
sentbox[sentcur][4],
sentbox[sentcur][6])
if ret != []: if ret != []:
for row in ret: for row in ret:
data, = row data, = row
data = shared.fixPotentiallyInvalidUTF8Data(data) data = shared.fixPotentiallyInvalidUTF8Data(data)
msg = "" msg = ""
for i, item in enumerate(data.split("\n")): for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False) + "\n" msg += fill(item, replace_whitespace=False)+"\n"
scrollbox(d, unicode(ascii(msg)), 30, 80) scrollbox(d, unicode(ascii(msg)), 30, 80)
else: else:
scrollbox(d, unicode("Could not fetch message.")) scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Move to trash elif t == "2": # Move to trash
sqlExecute( sqlExecute("UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
"UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?",
sentbox[sentcur][4],
sentbox[sentcur][6])
del sentbox[sentcur] del sentbox[sentcur]
scrollbox(d, unicode( scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
"Message moved to trash. There is no interface to view your trash"
" \nbut the message is still on disk if you are desperate to recover it."))
elif menutab == 4: elif menutab == 4:
set_background_title(d, "Your Identities Dialog Box") set_background_title(d, "Your Identities Dialog Box")
if len(addresses) <= addrcur: if len(addresses) <= addrcur:
r, t = d.menu( r, t = d.menu("Do what with addresses?",
"Do what with addresses?", choices=[("1", "Create new address")])
choices=[
("1", "Create new address")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with \""+addresses[addrcur][0]+"\" : \""+addresses[addrcur][2]+"\"?",
"Do what with \"" + addresses[addrcur][0] + "\" : \"" + addresses[addrcur][2] + "\"?", choices=[("1", "Create new address"),
choices=[
("1", "Create new address"),
("2", "Send a message from this address"), ("2", "Send a message from this address"),
("3", "Rename"), ("3", "Rename"),
("4", "Enable"), ("4", "Enable"),
@ -503,39 +416,29 @@ def handlech(c, stdscr):
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # Create new address if t == "1": # Create new address
set_background_title(d, "Create new address") set_background_title(d, "Create new address")
scrollbox( scrollbox(d, unicode("Here you may generate as many addresses as you like.\n"
d, unicode(
"Here you may generate as many addresses as you like.\n"
"Indeed, creating and abandoning addresses is encouraged.\n" "Indeed, creating and abandoning addresses is encouraged.\n"
"Deterministic addresses have several pros and cons:\n" "Deterministic addresses have several pros and cons:\n"
"\nPros:\n" "\nPros:\n"
" * You can recreate your addresses on any computer from memory\n" " * You can recreate your addresses on any computer from memory\n"
" * You need not worry about backing up your keys.dat file as long as you" " * You need not worry about backing up your keys.dat file as long as you \n can remember your passphrase\n"
" \n can remember your passphrase\n"
"Cons:\n" "Cons:\n"
" * You must remember (or write down) your passphrase in order to recreate" " * You must remember (or write down) your passphrase in order to recreate \n your keys if they are lost\n"
" \n your keys if they are lost\n"
" * You must also remember the address version and stream numbers\n" " * You must also remember the address version and stream numbers\n"
" * If you choose a weak passphrase someone may be able to brute-force it" " * If you choose a weak passphrase someone may be able to brute-force it \n and then send and receive messages as you"))
" \n and then send and receive messages as you")) r, t = d.menu("Choose an address generation technique",
r, t = d.menu( choices=[("1", "Use a random number generator"),
"Choose an address generation technique",
choices=[
("1", "Use a random number generator"),
("2", "Use a passphrase")]) ("2", "Use a passphrase")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
set_background_title(d, "Randomly generate address") set_background_title(d, "Randomly generate address")
r, t = d.inputbox("Label (not shown to anyone except you)") r, t = d.inputbox("Label (not shown to anyone except you)")
label = "" label = ""
if r == d.DIALOG_OK and t: if r == d.DIALOG_OK and len(t) > 0:
label = t label = t
r, t = d.menu( r, t = d.menu("Choose a stream",
"Choose a stream", choices=[("1", "Use the most available stream"),("", "(Best if this is the first of many addresses you will create)"),
choices=[("1", "Use the most available stream"), ("2", "Use the same stream as an existing address"),("", "(Saves you some bandwidth and processing power)")])
("", "(Best if this is the first of many addresses you will create)"),
("2", "Use the same stream as an existing address"),
("", "(Saves you some bandwidth and processing power)")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
stream = 1 stream = 1
@ -547,61 +450,34 @@ def handlech(c, stdscr):
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
stream = decodeAddress(addrs[int(t)][1])[2] stream = decodeAddress(addrs[int(t)][1])[2]
shorten = False shorten = False
r, t = d.checklist( r, t = d.checklist("Miscellaneous options",
"Miscellaneous options", choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
choices=[(
"1",
"Spend time shortening the address",
1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten))
"createRandomAddress",
4,
stream,
label,
1,
"",
shorten))
elif t == "2": elif t == "2":
set_background_title(d, "Make deterministic addresses") set_background_title(d, "Make deterministic addresses")
r, t = d.passwordform( r, t = d.passwordform("Enter passphrase",
"Enter passphrase", [("Passphrase", 1, 1, "", 2, 1, 64, 128),
[
("Passphrase", 1, 1, "", 2, 1, 64, 128),
("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)], ("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)],
form_height=4, insecure=True) form_height=4, insecure=True)
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t[0] == t[1]: if t[0] == t[1]:
passphrase = t[0] passphrase = t[0]
r, t = d.rangebox( r, t = d.rangebox("Number of addresses to generate",
"Number of addresses to generate", width=48, min=1, max=99, init=8)
width=48,
min=1,
max=99,
init=8)
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
number = t number = t
stream = 1 stream = 1
shorten = False shorten = False
r, t = d.checklist( r, t = d.checklist("Miscellaneous options",
"Miscellaneous options", choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
choices=[(
"1",
"Spend time shortening the address",
1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
scrollbox( scrollbox(d, unicode("In addition to your passphrase, be sure to remember the following numbers:\n"
d, unicode( "\n * Address version number: "+str(4)+"\n"
"In addition to your passphrase, be sure to remember the" " * Stream number: "+str(stream)))
" following numbers:\n" queues.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten))
"\n * Address version number: " + str(4) + "\n"
" * Stream number: " + str(stream)))
queues.addressGeneratorQueue.put(
('createDeterministicAddresses', 4, stream,
"unused deterministic address", number,
str(passphrase), shorten))
else: else:
scrollbox(d, unicode("Passphrases do not match")) scrollbox(d, unicode("Passphrases do not match"))
elif t == "2": # Send a message elif t == "2": # Send a message
@ -651,23 +527,20 @@ def handlech(c, stdscr):
a = addresses[addrcur][2] a = addresses[addrcur][2]
set_background_title(d, "Special address behavior") set_background_title(d, "Special address behavior")
if BMConfigParser().safeGetBoolean(a, "chan"): if BMConfigParser().safeGetBoolean(a, "chan"):
scrollbox(d, unicode( scrollbox(d, unicode("This is a chan address. You cannot use it as a pseudo-mailing list."))
"This is a chan address. You cannot use it as a pseudo-mailing list."))
else: else:
m = BMConfigParser().safeGetBoolean(a, "mailinglist") m = BMConfigParser().safeGetBoolean(a, "mailinglist")
r, t = d.radiolist( r, t = d.radiolist("Select address behavior",
"Select address behavior", choices=[("1", "Behave as a normal address", not m),
choices=[
("1", "Behave as a normal address", not m),
("2", "Behave as a pseudo-mailing-list address", m)]) ("2", "Behave as a pseudo-mailing-list address", m)])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1" and m: if t == "1" and m == True:
BMConfigParser().set(a, "mailinglist", "false") BMConfigParser().set(a, "mailinglist", "false")
if addresses[addrcur][1]: if addresses[addrcur][1]:
addresses[addrcur][3] = 0 # Set color to black addresses[addrcur][3] = 0 # Set color to black
else: else:
addresses[addrcur][3] = 8 # Set color to gray addresses[addrcur][3] = 8 # Set color to gray
elif t == "2" and m is False: elif t == "2" and m == False:
try: try:
mn = BMConfigParser().get(a, "mailinglistname") mn = BMConfigParser().get(a, "mailinglistname")
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
@ -683,15 +556,11 @@ def handlech(c, stdscr):
elif menutab == 5: elif menutab == 5:
set_background_title(d, "Subscriptions Dialog Box") set_background_title(d, "Subscriptions Dialog Box")
if len(subscriptions) <= subcur: if len(subscriptions) <= subcur:
r, t = d.menu( r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?", choices=[("1", "Add new subscription")])
choices=[
("1", "Add new subscription")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?", choices=[("1", "Add new subscription"),
choices=[
("1", "Add new subscription"),
("2", "Delete this subscription"), ("2", "Delete this subscription"),
("3", "Enable"), ("3", "Enable"),
("4", "Disable")]) ("4", "Disable")])
@ -712,39 +581,27 @@ def handlech(c, stdscr):
sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True) sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True)
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
elif t == "2": elif t == "2":
r, t = d.inputbox("Type in \"I want to delete this subscription\"") r, t = d.inpuxbox("Type in \"I want to delete this subscription\"")
if r == d.DIALOG_OK and t == "I want to delete this subscription": if r == d.DIALOG_OK and t == "I want to delete this subscription":
sqlExecute( sqlExecute("DELETE FROM subscriptions WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"DELETE FROM subscriptions WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
del subscriptions[subcur] del subscriptions[subcur]
elif t == "3": elif t == "3":
sqlExecute( sqlExecute("UPDATE subscriptions SET enabled=1 WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"UPDATE subscriptions SET enabled=1 WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
subscriptions[subcur][2] = True subscriptions[subcur][2] = True
elif t == "4": elif t == "4":
sqlExecute( sqlExecute("UPDATE subscriptions SET enabled=0 WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"UPDATE subscriptions SET enabled=0 WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
subscriptions[subcur][2] = False subscriptions[subcur][2] = False
elif menutab == 6: elif menutab == 6:
set_background_title(d, "Address Book Dialog Box") set_background_title(d, "Address Book Dialog Box")
if len(addrbook) <= abookcur: if len(addrbook) <= abookcur:
r, t = d.menu( r, t = d.menu("Do what with addressbook?",
"Do what with addressbook?",
choices=[("3", "Add new address to Address Book")]) choices=[("3", "Add new address to Address Book")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with \""+addrbook[abookcur][0]+"\" : \""+addrbook[abookcur][1]+"\"",
"Do what with \"" + addrbook[abookcur][0] + "\" : \"" + addrbook[abookcur][1] + "\"", choices=[("1", "Send a message to this address"),
choices=[
("1", "Send a message to this address"),
("2", "Subscribe to this address"), ("2", "Subscribe to this address"),
("3", "Add new address to Address Book"), ("3", "Add new address to Address Book"),
("4", "Delete this address")]) ("4", "Delete this address")])
@ -766,8 +623,8 @@ def handlech(c, stdscr):
r, t = d.inputbox("Input new address") r, t = d.inputbox("Input new address")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
addr = t addr = t
if addr not in [item[1] for i, item in enumerate(addrbook)]: if addr not in [item[1] for i,item in enumerate(addrbook)]:
r, t = d.inputbox("Label for address \"" + addr + "\"") r, t = d.inputbox("Label for address \""+addr+"\"")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
sqlExecute("INSERT INTO addressbook VALUES (?,?)", t, addr) sqlExecute("INSERT INTO addressbook VALUES (?,?)", t, addr)
# Prepend entry # Prepend entry
@ -779,39 +636,25 @@ def handlech(c, stdscr):
elif t == "4": elif t == "4":
r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"") r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"")
if r == d.DIALOG_OK and t == "I want to delete this Address Book entry": if r == d.DIALOG_OK and t == "I want to delete this Address Book entry":
sqlExecute( sqlExecute("DELETE FROM addressbook WHERE label=? AND address=?", addrbook[abookcur][0], addrbook[abookcur][1])
"DELETE FROM addressbook WHERE label=? AND address=?",
addrbook[abookcur][0],
addrbook[abookcur][1])
del addrbook[abookcur] del addrbook[abookcur]
elif menutab == 7: elif menutab == 7:
set_background_title(d, "Blacklist Dialog Box") set_background_title(d, "Blacklist Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+blacklist[blackcur][0]+"\" : \""+blacklist[blackcur][1]+"\"?",
"Do what with \"" + blacklist[blackcur][0] + "\" : \"" + blacklist[blackcur][1] + "\"?", choices=[("1", "Delete"),
choices=[
("1", "Delete"),
("2", "Enable"), ("2", "Enable"),
("3", "Disable")]) ("3", "Disable")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
r, t = d.inputbox("Type in \"I want to delete this Blacklist entry\"") r, t = d.inputbox("Type in \"I want to delete this Blacklist entry\"")
if r == d.DIALOG_OK and t == "I want to delete this Blacklist entry": if r == d.DIALOG_OK and t == "I want to delete this Blacklist entry":
sqlExecute( sqlExecute("DELETE FROM blacklist WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"DELETE FROM blacklist WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
del blacklist[blackcur] del blacklist[blackcur]
elif t == "2": elif t == "2":
sqlExecute( sqlExecute("UPDATE blacklist SET enabled=1 WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"UPDATE blacklist SET enabled=1 WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
blacklist[blackcur][2] = True blacklist[blackcur][2] = True
elif t == "3": elif t== "3":
sqlExecute( sqlExecute("UPDATE blacklist SET enabled=0 WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"UPDATE blacklist SET enabled=0 WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
blacklist[blackcur][2] = False blacklist[blackcur][2] = False
dialogreset(stdscr) dialogreset(stdscr)
else: else:
@ -829,17 +672,17 @@ def handlech(c, stdscr):
if menutab == 7 and blackcur > 0: if menutab == 7 and blackcur > 0:
blackcur -= 1 blackcur -= 1
elif c == curses.KEY_DOWN: elif c == curses.KEY_DOWN:
if menutab == 1 and inboxcur < len(inbox) - 1: if menutab == 1 and inboxcur < len(inbox)-1:
inboxcur += 1 inboxcur += 1
if (menutab == 2 or menutab == 4) and addrcur < len(addresses) - 1: if (menutab == 2 or menutab == 4) and addrcur < len(addresses)-1:
addrcur += 1 addrcur += 1
if menutab == 3 and sentcur < len(sentbox) - 1: if menutab == 3 and sentcur < len(sentbox)-1:
sentcur += 1 sentcur += 1
if menutab == 5 and subcur < len(subscriptions) - 1: if menutab == 5 and subcur < len(subscriptions)-1:
subcur += 1 subcur += 1
if menutab == 6 and abookcur < len(addrbook) - 1: if menutab == 6 and abookcur < len(addrbook)-1:
abookcur += 1 abookcur += 1
if menutab == 7 and blackcur < len(blacklist) - 1: if menutab == 7 and blackcur < len(blacklist)-1:
blackcur += 1 blackcur += 1
elif c == curses.KEY_HOME: elif c == curses.KEY_HOME:
if menutab == 1: if menutab == 1:
@ -856,42 +699,33 @@ def handlech(c, stdscr):
blackcur = 0 blackcur = 0
elif c == curses.KEY_END: elif c == curses.KEY_END:
if menutab == 1: if menutab == 1:
inboxcur = len(inbox) - 1 inboxcur = len(inbox)-1
if menutab == 2 or menutab == 4: if menutab == 2 or menutab == 4:
addrcur = len(addresses) - 1 addrcur = len(addresses)-1
if menutab == 3: if menutab == 3:
sentcur = len(sentbox) - 1 sentcur = len(sentbox)-1
if menutab == 5: if menutab == 5:
subcur = len(subscriptions) - 1 subcur = len(subscriptions)-1
if menutab == 6: if menutab == 6:
abookcur = len(addrbook) - 1 abookcur = len(addrbook)-1
if menutab == 7: if menutab == 7:
blackcur = len(blackcur) - 1 blackcur = len(blackcur)-1
redraw(stdscr) redraw(stdscr)
# pylint: disable=too-many-locals, too-many-arguments
def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=False): def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=False):
"""Method for message sending"""
if sender == "": if sender == "":
return return
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
set_background_title(d, "Send a message") set_background_title(d, "Send a message")
if recv == "": if recv == "":
r, t = d.inputbox( r, t = d.inputbox("Recipient address (Cancel to load from the Address Book or leave blank to broadcast)", 10, 60)
"Recipient address (Cancel to load from the Address Book or leave blank to broadcast)",
10,
60)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
global menutab global menutab
menutab = 6 menutab = 6
return return
recv = t recv = t
if broadcast is None and sender != recv: if broadcast == None and sender != recv:
r, t = d.radiolist( r, t = d.radiolist("How to send the message?",
"How to send the message?", choices=[("1", "Send to one or more specific people", 1),
choices=[
("1", "Send to one or more specific people", 1),
("2", "Broadcast to everyone who is subscribed to your address", 0)]) ("2", "Broadcast to everyone who is subscribed to your address", 0)])
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
@ -912,12 +746,11 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if not broadcast: if not broadcast:
recvlist = [] recvlist = []
for _, item in enumerate(recv.replace(",", ";").split(";")): for i, item in enumerate(recv.replace(",", ";").split(";")):
recvlist.append(item.strip()) recvlist.append(item.strip())
list(set(recvlist)) # Remove exact duplicates list(set(recvlist)) # Remove exact duplicates
for addr in recvlist: for addr in recvlist:
if addr != "": if addr != "":
# pylint: disable=redefined-outer-name
status, version, stream, ripe = decodeAddress(addr) status, version, stream, ripe = decodeAddress(addr)
if status != "success": if status != "success":
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
@ -929,17 +762,13 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
elif status == "invalidcharacters": elif status == "invalidcharacters":
err += "The address contains invalid characters." err += "The address contains invalid characters."
elif status == "versiontoohigh": elif status == "versiontoohigh":
err += ("The address version is too high. Either you need to upgrade your Bitmessage software" err += "The address version is too high. Either you need to upgrade your Bitmessage software or your acquaintance is doing something clever."
" or your acquaintance is doing something clever.")
elif status == "ripetooshort": elif status == "ripetooshort":
err += ("Some data encoded in the address is too short. There might be something wrong with" err += "Some data encoded in the address is too short. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
elif status == "ripetoolong": elif status == "ripetoolong":
err += ("Some data encoded in the address is too long. There might be something wrong with" err += "Some data encoded in the address is too long. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
elif status == "varintmalformed": elif status == "varintmalformed":
err += ("Some data encoded in the address is malformed. There might be something wrong with" err += "Some data encoded in the address is malformed. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
else: else:
err += "It is unknown what is wrong with the address." err += "It is unknown what is wrong with the address."
scrollbox(d, unicode(err)) scrollbox(d, unicode(err))
@ -947,24 +776,17 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
addr = addBMIfNotPresent(addr) addr = addBMIfNotPresent(addr)
if version > 4 or version <= 1: if version > 4 or version <= 1:
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
scrollbox(d, unicode( scrollbox(d, unicode("Could not understand version number " + version + "of address" + addr + "."))
"Could not understand version number " +
version +
"of address" +
addr +
"."))
continue continue
if stream > 1 or stream == 0: if stream > 1 or stream == 0:
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
scrollbox(d, unicode( scrollbox(d, unicode("Bitmessage currently only supports stream numbers of 1, unlike as requested for address " + addr + "."))
"Bitmessage currently only supports stream numbers of 1,"
"unlike as requested for address " + addr + "."))
continue continue
if not network.stats.connectedHostsList(): if not network.stats.connectedHostsList():
set_background_title(d, "Not connected warning") set_background_title(d, "Not connected warning")
scrollbox(d, unicode("Because you are not currently connected to the network, ")) scrollbox(d, unicode("Because you are not currently connected to the network, "))
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute( sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", "INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
"", "",
@ -989,7 +811,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
scrollbox(d, unicode("You must specify an address to send the message from.")) scrollbox(d, unicode("You must specify an address to send the message from."))
else: else:
# dummy ackdata, no need for stealth # dummy ackdata, no need for stealth
ackdata = genAckPayload(decodeAddress(addr)[2], 0) ackdata = genAckPayload(streamNumber, 0)
recv = BROADCAST_STR recv = BROADCAST_STR
ripe = "" ripe = ""
sqlExecute( sqlExecute(
@ -1011,12 +833,9 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
BMConfigParser().getint('bitmessagesettings', 'ttl')) BMConfigParser().getint('bitmessagesettings', 'ttl'))
queues.workerQueue.put(('sendbroadcast', '')) queues.workerQueue.put(('sendbroadcast', ''))
# pylint: disable=redefined-outer-name, too-many-locals
def loadInbox(): def loadInbox():
"""Load the list of messages"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading inbox messages..." print("Loading inbox messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1060,15 +879,12 @@ def loadInbox():
fromlabel = shared.fixPotentiallyInvalidUTF8Data(fromlabel) fromlabel = shared.fixPotentiallyInvalidUTF8Data(fromlabel)
# Load into array # Load into array
inbox.append([msgid, tolabel, toaddr, fromlabel, fromaddr, subject, l10n.formatTimestamp( inbox.append([msgid, tolabel, toaddr, fromlabel, fromaddr, subject,
received, False), read]) l10n.formatTimestamp(received, False), read])
inbox.reverse() inbox.reverse()
def loadSent(): def loadSent():
"""Load the messages that sent"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading sent messages..." print("Loading sent messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1114,20 +930,20 @@ def loadSent():
statstr = "Message queued" statstr = "Message queued"
elif status == "msgsent": elif status == "msgsent":
t = l10n.formatTimestamp(lastactiontime, False) t = l10n.formatTimestamp(lastactiontime, False)
statstr = "Message sent at " + t + ".Waiting for acknowledgement." statstr = "Message sent at "+t+".Waiting for acknowledgement."
elif status == "msgsentnoackexpected": elif status == "msgsentnoackexpected":
t = l10n.formatTimestamp(lastactiontime, False) t = l10n.formatTimestamp(lastactiontime, False)
statstr = "Message sent at " + t + "." statstr = "Message sent at "+t+"."
elif status == "doingmsgpow": elif status == "doingmsgpow":
statstr = "The proof of work required to send the message has been queued." statstr = "The proof of work required to send the message has been queued."
elif status == "ackreceived": elif status == "ackreceived":
t = l10n.formatTimestamp(lastactiontime, False) t = l10n.formatTimestamp(lastactiontime, False)
statstr = "Acknowledgment of the message received at " + t + "." statstr = "Acknowledgment of the message received at "+t+"."
elif status == "broadcastqueued": elif status == "broadcastqueued":
statstr = "Broadcast queued." statstr = "Broadcast queued."
elif status == "broadcastsent": elif status == "broadcastsent":
t = l10n.formatTimestamp(lastactiontime, False) t = l10n.formatTimestamp(lastactiontime, False)
statstr = "Broadcast sent at " + t + "." statstr = "Broadcast sent at "+t+"."
elif status == "forcepow": elif status == "forcepow":
statstr = "Forced difficulty override. Message will start sending soon." statstr = "Forced difficulty override. Message will start sending soon."
elif status == "badkey": elif status == "badkey":
@ -1136,25 +952,15 @@ def loadSent():
statstr = "Error: The work demanded by the recipient is more difficult than you are willing to do." statstr = "Error: The work demanded by the recipient is more difficult than you are willing to do."
else: else:
t = l10n.formatTimestamp(lastactiontime, False) t = l10n.formatTimestamp(lastactiontime, False)
statstr = "Unknown status " + status + " at " + t + "." statstr = "Unknown status "+status+" at "+t+"."
# Load into array # Load into array
sentbox.append([ sentbox.append([tolabel, toaddr, fromlabel, fromaddr, subject, statstr, ackdata,
tolabel,
toaddr,
fromlabel,
fromaddr,
subject,
statstr,
ackdata,
l10n.formatTimestamp(lastactiontime, False)]) l10n.formatTimestamp(lastactiontime, False)])
sentbox.reverse() sentbox.reverse()
def loadAddrBook(): def loadAddrBook():
"""Load address book"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading address book..." print("Loading address book...")
sys.stdout = printlog sys.stdout = printlog
ret = sqlQuery("SELECT label, address FROM addressbook") ret = sqlQuery("SELECT label, address FROM addressbook")
@ -1163,19 +969,13 @@ def loadAddrBook():
label = shared.fixPotentiallyInvalidUTF8Data(label) label = shared.fixPotentiallyInvalidUTF8Data(label)
addrbook.append([label, addr]) addrbook.append([label, addr])
addrbook.reverse() addrbook.reverse()
def loadSubscriptions(): def loadSubscriptions():
"""Load subscription functionality"""
ret = sqlQuery("SELECT label, address, enabled FROM subscriptions") ret = sqlQuery("SELECT label, address, enabled FROM subscriptions")
for row in ret: for row in ret:
label, address, enabled = row label, address, enabled = row
subscriptions.append([label, address, enabled]) subscriptions.append([label, address, enabled])
subscriptions.reverse() subscriptions.reverse()
def loadBlackWhiteList(): def loadBlackWhiteList():
"""load black/white list"""
global bwtype global bwtype
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist") bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
if bwtype == "black": if bwtype == "black":
@ -1187,12 +987,11 @@ def loadBlackWhiteList():
blacklist.append([label, address, enabled]) blacklist.append([label, address, enabled])
blacklist.reverse() blacklist.reverse()
def runwrapper(): def runwrapper():
"""Main method"""
sys.stdout = printlog sys.stdout = printlog
# sys.stderr = errlog #sys.stderr = errlog
# Load messages from database
loadInbox() loadInbox()
loadSent() loadSent()
loadAddrBook() loadAddrBook()
@ -1211,9 +1010,7 @@ def runwrapper():
curses.wrapper(run) curses.wrapper(run)
doShutdown() doShutdown()
def run(stdscr): def run(stdscr):
"""Main loop"""
# Schedule inventory lookup data # Schedule inventory lookup data
resetlookups() resetlookups()
@ -1242,28 +1039,27 @@ def run(stdscr):
addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile]) addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile])
# Set address color # Set address color
if not isEnabled: if not isEnabled:
addresses[len(addresses) - 1].append(8) # gray addresses[len(addresses)-1].append(8) # gray
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'): elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'):
addresses[len(addresses) - 1].append(9) # orange addresses[len(addresses)-1].append(9) # orange
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'): elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'):
addresses[len(addresses) - 1].append(5) # magenta addresses[len(addresses)-1].append(5) # magenta
else: else:
addresses[len(addresses) - 1].append(0) # black addresses[len(addresses)-1].append(0) # black
addresses.reverse() addresses.reverse()
stdscr.clear() stdscr.clear()
redraw(stdscr) redraw(stdscr)
while quit_ is False: while quit == False:
drawtab(stdscr) drawtab(stdscr)
handlech(stdscr.getch(), stdscr) handlech(stdscr.getch(), stdscr)
def doShutdown(): def doShutdown():
"""Shutting the app down"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Shutting down..." print("Shutting down...")
sys.stdout = printlog sys.stdout = printlog
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
os._exit(0) # pylint: disable=protected-access
os._exit(0)

View File

@ -1,14 +1,14 @@
#!/usr/bin/python2.7 #!/usr/bin/python2.7
"""
The PyBitmessage startup script
"""
# Copyright (c) 2012-2016 Jonathan Warren # Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2020 The Bitmessage developers # Copyright (c) 2012-2019 The Bitmessage developers
# Distributed under the MIT/X11 software license. See the accompanying # Distributed under the MIT/X11 software license. See the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
# Right now, PyBitmessage only support connecting to stream 1. It doesn't # Right now, PyBitmessage only support connecting to stream 1. It doesn't
# yet contain logic to expand into further streams. # yet contain logic to expand into further streams.
# The software version variable is now held in shared.py
import os import os
import sys import sys
@ -31,33 +31,43 @@ import time
import traceback import traceback
from struct import pack from struct import pack
import defaults
import shared
import shutdown
import state
from bmconfigparser import BMConfigParser
from debug import logger # this should go before any threads
from helper_startup import ( from helper_startup import (
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections, isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
start_proxyconfig
)
from inventory import Inventory
from knownnodes import readKnownNodes
# Network objects and threads
from network import (
BMConnectionPool, Dandelion, AddrThread, AnnounceThread, BMNetworkThread,
InvThread, ReceiveQueueThread, DownloadThread, UploadThread
) )
from singleinstance import singleinstance from singleinstance import singleinstance
# Synchronous threads
from threads import ( import defaults
set_thread_name, addressGenerator, objectProcessor, singleCleaner, import shared
singleWorker, sqlThread import knownnodes
) import state
import shutdown
from debug import logger
# Classes
from class_sqlThread import sqlThread
from class_singleCleaner import singleCleaner
from class_objectProcessor import objectProcessor
from class_singleWorker import singleWorker
from class_addressGenerator import addressGenerator
from bmconfigparser import BMConfigParser
from inventory import Inventory
from network.connectionpool import BMConnectionPool
from network.dandelion import Dandelion
from network.networkthread import BMNetworkThread
from network.receivequeuethread import ReceiveQueueThread
from network.announcethread import AnnounceThread
from network.invthread import InvThread
from network.addrthread import AddrThread
from network.downloadthread import DownloadThread
from network.uploadthread import UploadThread
# Helper Functions
import helper_threading
def connectToStream(streamNumber): def connectToStream(streamNumber):
"""Connect to a stream"""
state.streamsInWhichIAmParticipating.append(streamNumber) state.streamsInWhichIAmParticipating.append(streamNumber)
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
@ -74,6 +84,14 @@ def connectToStream(streamNumber):
except: except:
pass pass
with knownnodes.knownNodesLock:
if streamNumber not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber] = {}
if streamNumber * 2 not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber * 2] = {}
if streamNumber * 2 + 1 not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber * 2 + 1] = {}
BMConnectionPool().connectToStream(streamNumber) BMConnectionPool().connectToStream(streamNumber)
@ -90,8 +108,6 @@ def _fixSocket():
addressToString = ctypes.windll.ws2_32.WSAAddressToStringA addressToString = ctypes.windll.ws2_32.WSAAddressToStringA
def inet_ntop(family, host): def inet_ntop(family, host):
"""Converting an IP address in packed
binary format to string format"""
if family == socket.AF_INET: if family == socket.AF_INET:
if len(host) != 4: if len(host) != 4:
raise ValueError("invalid IPv4 host") raise ValueError("invalid IPv4 host")
@ -113,8 +129,6 @@ def _fixSocket():
stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA
def inet_pton(family, host): def inet_pton(family, host):
"""Converting an IP address in string format
to a packed binary format"""
buf = "\0" * 28 buf = "\0" * 28
lengthBuf = pack("I", len(buf)) lengthBuf = pack("I", len(buf))
if stringToAddress(str(host), if stringToAddress(str(host),
@ -155,8 +169,8 @@ def signal_handler(signum, frame):
if thread.name not in ("PyBitmessage", "MainThread"): if thread.name not in ("PyBitmessage", "MainThread"):
return return
logger.error("Got signal %i", signum) logger.error("Got signal %i", signum)
# there are possible non-UI variants to run bitmessage # there are possible non-UI variants to run bitmessage which should shutdown
# which should shutdown especially test-mode # especially test-mode
if shared.thisapp.daemon or not state.enableGUI: if shared.thisapp.daemon or not state.enableGUI:
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
else: else:
@ -169,18 +183,36 @@ def signal_handler(signum, frame):
' because the UI captures the signal.') ' because the UI captures the signal.')
class Main(object): class Main:
"""Main PyBitmessage class""" @staticmethod
def start_proxyconfig(config):
"""Check socksproxytype and start any proxy configuration plugin"""
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
if proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
# pylint: disable=relative-import
from plugins.plugin import get_plugin
try:
proxyconfig_start = time.time()
get_plugin('proxyconfig', name=proxy_type)(config)
except TypeError:
logger.error(
'Failed to run proxy config plugin %s',
proxy_type, exc_info=True)
shutdown.doCleanShutdown()
sys.exit(2)
else:
logger.info(
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)
def start(self): def start(self):
"""Start main application"""
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
_fixSocket() _fixSocket()
config = BMConfigParser() config = BMConfigParser()
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') daemon = config.safeGetBoolean('bitmessagesettings', 'daemon')
try: try:
opts, _ = getopt.getopt( opts, args = getopt.getopt(
sys.argv[1:], "hcdt", sys.argv[1:], "hcdt",
["help", "curses", "daemon", "test"]) ["help", "curses", "daemon", "test"])
@ -188,7 +220,7 @@ class Main(object):
self.usage() self.usage()
sys.exit(2) sys.exit(2)
for opt, _ in opts: for opt, arg in opts:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
self.usage() self.usage()
sys.exit() sys.exit()
@ -242,7 +274,7 @@ class Main(object):
self.setSignalHandler() self.setSignalHandler()
set_thread_name("PyBitmessage") helper_threading.set_thread_name("PyBitmessage")
state.dandelion = config.safeGetInt('network', 'dandelion') state.dandelion = config.safeGetInt('network', 'dandelion')
# dandelion requires outbound connections, without them, # dandelion requires outbound connections, without them,
@ -258,7 +290,7 @@ class Main(object):
defaults.networkDefaultPayloadLengthExtraBytes = int( defaults.networkDefaultPayloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes / 100) defaults.networkDefaultPayloadLengthExtraBytes / 100)
readKnownNodes() knownnodes.readKnownNodes()
# Not needed if objproc is disabled # Not needed if objproc is disabled
if state.enableObjProc: if state.enableObjProc:
@ -332,7 +364,7 @@ class Main(object):
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
start_proxyconfig() self.start_proxyconfig(config)
BMConnectionPool() BMConnectionPool()
asyncoreThread = BMNetworkThread() asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True asyncoreThread.daemon = True
@ -388,13 +420,10 @@ class Main(object):
while state.shutdown == 0: while state.shutdown == 0:
time.sleep(1) time.sleep(1)
if ( if (
state.testmode and time.time() - state.testmode and time.time() - state.last_api_response >= 30):
state.last_api_response >= 30
):
self.stop() self.stop()
elif not state.enableGUI: elif not state.enableGUI:
# pylint: disable=relative-import from tests import core as test_core # pylint: disable=relative-import
from tests import core as test_core
test_core_result = test_core.run() test_core_result = test_core.run()
state.enableGUI = True state.enableGUI = True
self.stop() self.stop()
@ -405,9 +434,7 @@ class Main(object):
else 0 else 0
) )
@staticmethod def daemonize(self):
def daemonize():
"""Running as a daemon. Send signal in end."""
grandfatherPid = os.getpid() grandfatherPid = os.getpid()
parentPid = None parentPid = None
try: try:
@ -417,7 +444,7 @@ class Main(object):
# wait until grandchild ready # wait until grandchild ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0) # pylint: disable=protected-access os._exit(0)
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
@ -438,7 +465,7 @@ class Main(object):
# wait until child ready # wait until child ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0) # pylint: disable=protected-access os._exit(0)
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
@ -459,18 +486,14 @@ class Main(object):
os.kill(parentPid, signal.SIGTERM) os.kill(parentPid, signal.SIGTERM)
os.kill(grandfatherPid, signal.SIGTERM) os.kill(grandfatherPid, signal.SIGTERM)
@staticmethod def setSignalHandler(self):
def setSignalHandler():
"""Setting the Signal Handler"""
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGTERM, signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL) # signal.signal(signal.SIGINT, signal.SIG_DFL)
@staticmethod def usage(self):
def usage(): print 'Usage: ' + sys.argv[0] + ' [OPTIONS]'
"""Displaying the usages""" print '''
print('Usage: ' + sys.argv[0] + ' [OPTIONS]')
print('''
Options: Options:
-h, --help show this help message and exit -h, --help show this help message and exit
-c, --curses use curses (text mode) interface -c, --curses use curses (text mode) interface
@ -478,19 +501,15 @@ Options:
-t, --test dryrun, make testing -t, --test dryrun, make testing
All parameters are optional. All parameters are optional.
''') '''
@staticmethod def stop(self):
def stop():
"""Stop main application"""
with shared.printLock: with shared.printLock:
print('Stopping Bitmessage Deamon.') print('Stopping Bitmessage Deamon.')
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
# .. todo:: nice function but no one is using this # TODO: nice function but no one is using this
@staticmethod def getApiAddress(self):
def getApiAddress():
"""This function returns API address and port"""
if not BMConfigParser().safeGetBoolean( if not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'apienabled'): 'bitmessagesettings', 'apienabled'):
return None return None
@ -500,7 +519,6 @@ All parameters are optional.
def main(): def main():
"""Triggers main module"""
mainprogram = Main() mainprogram = Main()
mainprogram.start() mainprogram.start()

View File

@ -23,6 +23,7 @@ from addresses import decodeAddress, addBMIfNotPresent
import shared import shared
from bitmessageui import Ui_MainWindow from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import defaults
import namecoin import namecoin
from messageview import MessageView from messageview import MessageView
from migrationwizard import Ui_MigrationWizard from migrationwizard import Ui_MigrationWizard
@ -30,12 +31,15 @@ from foldertree import (
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget, AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
MessageList_AddressWidget, MessageList_SubjectWidget, MessageList_AddressWidget, MessageList_SubjectWidget,
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress) Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress)
from settings import Ui_settingsDialog
import settingsmixin import settingsmixin
import support import support
import debug
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
import helper_search import helper_search
import l10n import l10n
import openclpow
from utils import str_broadcast_subscribers, avatarize from utils import str_broadcast_subscribers, avatarize
from account import ( from account import (
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount, getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
@ -43,15 +47,16 @@ from account import (
import dialogs import dialogs
from network.stats import pendingDownload, pendingUpload from network.stats import pendingDownload, pendingUpload
from uisignaler import UISignaler from uisignaler import UISignaler
import knownnodes
import paths import paths
from proofofwork import getPowType from proofofwork import getPowType
import queues import queues
import shutdown import shutdown
import state import state
from statusbar import BMStatusBar from statusbar import BMStatusBar
from network.asyncore_pollchoose import set_rates
import sound import sound
# This is needed for tray icon
import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
try: try:
from plugins.plugin import get_plugin, get_plugins from plugins.plugin import get_plugin, get_plugins
@ -59,6 +64,49 @@ except ImportError:
get_plugins = False get_plugins = False
def change_translation(newlocale):
global qmytranslator, qsystranslator
try:
if not qmytranslator.isEmpty():
QtGui.QApplication.removeTranslator(qmytranslator)
except:
pass
try:
if not qsystranslator.isEmpty():
QtGui.QApplication.removeTranslator(qsystranslator)
except:
pass
qmytranslator = QtCore.QTranslator()
translationpath = os.path.join (paths.codePath(), 'translations', 'bitmessage_' + newlocale)
qmytranslator.load(translationpath)
QtGui.QApplication.installTranslator(qmytranslator)
qsystranslator = QtCore.QTranslator()
if paths.frozen:
translationpath = os.path.join (paths.codePath(), 'translations', 'qt_' + newlocale)
else:
translationpath = os.path.join (str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
qsystranslator.load(translationpath)
QtGui.QApplication.installTranslator(qsystranslator)
lang = locale.normalize(l10n.getTranslationLanguage())
langs = [lang.split(".")[0] + "." + l10n.encoding, lang.split(".")[0] + "." + 'UTF-8', lang]
if 'win32' in sys.platform or 'win64' in sys.platform:
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
l10n.setlocale(locale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = locale.nl_langinfo(locale.CODESET)
else:
l10n.encoding = locale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)
# TODO: rewrite # TODO: rewrite
def powQueueSize(): def powQueueSize():
"""Returns the size of queues.workerQueue including current unfinished work""" """Returns the size of queues.workerQueue including current unfinished work"""
@ -74,6 +122,9 @@ def powQueueSize():
class MyForm(settingsmixin.SMainWindow): class MyForm(settingsmixin.SMainWindow):
# the last time that a message arrival sound was played
lastSoundTime = datetime.now() - timedelta(days=1)
# the maximum frequency of message sounds in seconds # the maximum frequency of message sounds in seconds
maxSoundFrequencySec = 60 maxSoundFrequencySec = 60
@ -81,58 +132,6 @@ class MyForm(settingsmixin.SMainWindow):
REPLY_TYPE_CHAN = 1 REPLY_TYPE_CHAN = 1
REPLY_TYPE_UPD = 2 REPLY_TYPE_UPD = 2
def change_translation(self, newlocale=None):
"""Change translation language for the application"""
if newlocale is None:
newlocale = l10n.getTranslationLanguage()
try:
if not self.qmytranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qmytranslator)
except:
pass
try:
if not self.qsystranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qsystranslator)
except:
pass
self.qmytranslator = QtCore.QTranslator()
translationpath = os.path.join(
paths.codePath(), 'translations', 'bitmessage_' + newlocale)
self.qmytranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qmytranslator)
self.qsystranslator = QtCore.QTranslator()
if paths.frozen:
translationpath = os.path.join(
paths.codePath(), 'translations', 'qt_' + newlocale)
else:
translationpath = os.path.join(
str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
self.qsystranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qsystranslator)
lang = locale.normalize(l10n.getTranslationLanguage())
langs = [
lang.split(".")[0] + "." + l10n.encoding,
lang.split(".")[0] + "." + 'UTF-8',
lang
]
if 'win32' in sys.platform or 'win64' in sys.platform:
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
l10n.setlocale(locale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = locale.nl_langinfo(locale.CODESET)
else:
l10n.encoding = locale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)
def init_file_menu(self): def init_file_menu(self):
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL( QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL(
"triggered()"), self.quit) "triggered()"), self.quit)
@ -606,13 +605,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
self.qmytranslator = self.qsystranslator = None
self.indicatorUpdate = None
self.actionStatus = None
# the last time that a message arrival sound was played
self.lastSoundTime = datetime.now() - timedelta(days=1)
# Ask the user if we may delete their old version 1 addresses if they # Ask the user if we may delete their old version 1 addresses if they
# have any. # have any.
for addressInKeysFile in getSortedAccounts(): for addressInKeysFile in getSortedAccounts():
@ -628,9 +620,22 @@ class MyForm(settingsmixin.SMainWindow):
BMConfigParser().remove_section(addressInKeysFile) BMConfigParser().remove_section(addressInKeysFile)
BMConfigParser().save() BMConfigParser().save()
self.updateStartOnLogon() # Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
self.change_translation() if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(RUN_PATH, QtCore.QSettings.NativeFormat)
self.settings.remove(
"PyBitmessage") # In case the user moves the program and the registry entry is no longer valid, this will delete the old registry entry.
if BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
# e.g. for editing labels # e.g. for editing labels
self.recurDepth = 0 self.recurDepth = 0
@ -781,9 +786,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.treeWidgetSubscriptions.keyPressEvent = self.treeWidgetKeyPressEvent self.ui.treeWidgetSubscriptions.keyPressEvent = self.treeWidgetKeyPressEvent
self.ui.treeWidgetChans.keyPressEvent = self.treeWidgetKeyPressEvent self.ui.treeWidgetChans.keyPressEvent = self.treeWidgetKeyPressEvent
# Key press in addressbook
self.ui.tableWidgetAddressBook.keyPressEvent = self.addressbookKeyPressEvent
# Key press in messagelist # Key press in messagelist
self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetKeyPressEvent self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetKeyPressEvent
self.ui.tableWidgetInboxSubscriptions.keyPressEvent = self.tableWidgetKeyPressEvent self.ui.tableWidgetInboxSubscriptions.keyPressEvent = self.tableWidgetKeyPressEvent
@ -826,28 +828,6 @@ class MyForm(settingsmixin.SMainWindow):
finally: finally:
self._contact_selected = None self._contact_selected = None
def updateStartOnLogon(self):
# Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(
RUN_PATH, QtCore.QSettings.NativeFormat)
# In case the user moves the program and the registry entry is
# no longer valid, this will delete the old registry entry.
self.settings.remove("PyBitmessage")
if BMConfigParser().getboolean(
'bitmessagesettings', 'startonlogon'
):
self.settings.setValue("PyBitmessage", sys.argv[0])
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
def updateTTL(self, sliderPosition): def updateTTL(self, sliderPosition):
TTL = int(sliderPosition ** 3.199 + 3600) TTL = int(sliderPosition ** 3.199 + 3600)
self.updateHumanFriendlyTTLDescription(TTL) self.updateHumanFriendlyTTLDescription(TTL)
@ -1453,15 +1433,6 @@ class MyForm(settingsmixin.SMainWindow):
def treeWidgetKeyPressEvent(self, event): def treeWidgetKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentTreeWidget()) return self.handleKeyPress(event, self.getCurrentTreeWidget())
# addressbook
def addressbookKeyPressEvent(self, event):
"""Handle keypress event in addressbook widget"""
if event.key() == QtCore.Qt.Key_Delete:
self.on_action_AddressBookDelete()
else:
return QtGui.QTableWidget.keyPressEvent(
self.ui.tableWidgetAddressBook, event)
# inbox / sent # inbox / sent
def tableWidgetKeyPressEvent(self, event): def tableWidgetKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentMessagelist()) return self.handleKeyPress(event, self.getCurrentMessagelist())
@ -1470,12 +1441,11 @@ class MyForm(settingsmixin.SMainWindow):
def textEditKeyPressEvent(self, event): def textEditKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentMessageTextedit()) return self.handleKeyPress(event, self.getCurrentMessageTextedit())
def handleKeyPress(self, event, focus=None): def handleKeyPress(self, event, focus = None):
"""This method handles keypress events for all widgets on MyForm"""
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
if isinstance(focus, MessageView) or isinstance(focus, QtGui.QTableWidget): if isinstance (focus, MessageView) or isinstance(focus, QtGui.QTableWidget):
if folder == "sent": if folder == "sent":
self.on_action_SentTrash() self.on_action_SentTrash()
else: else:
@ -1511,17 +1481,17 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.lineEditTo.setFocus() self.ui.lineEditTo.setFocus()
event.ignore() event.ignore()
elif event.key() == QtCore.Qt.Key_F: elif event.key() == QtCore.Qt.Key_F:
searchline = self.getCurrentSearchLine(retObj=True) searchline = self.getCurrentSearchLine(retObj = True)
if searchline: if searchline:
searchline.setFocus() searchline.setFocus()
event.ignore() event.ignore()
if not event.isAccepted(): if not event.isAccepted():
return return
if isinstance(focus, MessageView): if isinstance (focus, MessageView):
return MessageView.keyPressEvent(focus, event) return MessageView.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTableWidget): elif isinstance (focus, QtGui.QTableWidget):
return QtGui.QTableWidget.keyPressEvent(focus, event) return QtGui.QTableWidget.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTreeWidget): elif isinstance (focus, QtGui.QTreeWidget):
return QtGui.QTreeWidget.keyPressEvent(focus, event) return QtGui.QTreeWidget.keyPressEvent(focus, event)
# menu button 'manage keys' # menu button 'manage keys'
@ -1652,6 +1622,7 @@ class MyForm(settingsmixin.SMainWindow):
# The window state has just been changed to # The window state has just been changed to
# Normal/Maximised/FullScreen # Normal/Maximised/FullScreen
pass pass
# QtGui.QWidget.changeEvent(self, event)
def __icon_activated(self, reason): def __icon_activated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger: if reason == QtGui.QSystemTrayIcon.Trigger:
@ -2463,7 +2434,225 @@ class MyForm(settingsmixin.SMainWindow):
dialogs.AboutDialog(self).exec_() dialogs.AboutDialog(self).exec_()
def click_actionSettings(self): def click_actionSettings(self):
dialogs.SettingsDialog(self, firstrun=self._firstrun).exec_() self.settingsDialogInstance = settingsDialog(self)
if self._firstrun:
self.settingsDialogInstance.ui.tabWidgetSettings.setCurrentIndex(1)
if self.settingsDialogInstance.exec_():
if self._firstrun:
BMConfigParser().remove_option(
'bitmessagesettings', 'dontconnect')
BMConfigParser().set('bitmessagesettings', 'startonlogon', str(
self.settingsDialogInstance.ui.checkBoxStartOnLogon.isChecked()))
BMConfigParser().set('bitmessagesettings', 'minimizetotray', str(
self.settingsDialogInstance.ui.checkBoxMinimizeToTray.isChecked()))
BMConfigParser().set('bitmessagesettings', 'trayonclose', str(
self.settingsDialogInstance.ui.checkBoxTrayOnClose.isChecked()))
BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', str(
self.settingsDialogInstance.ui.checkBoxHideTrayConnectionNotifications.isChecked()))
BMConfigParser().set('bitmessagesettings', 'showtraynotifications', str(
self.settingsDialogInstance.ui.checkBoxShowTrayNotifications.isChecked()))
BMConfigParser().set('bitmessagesettings', 'startintray', str(
self.settingsDialogInstance.ui.checkBoxStartInTray.isChecked()))
BMConfigParser().set('bitmessagesettings', 'willinglysendtomobile', str(
self.settingsDialogInstance.ui.checkBoxWillinglySendToMobile.isChecked()))
BMConfigParser().set('bitmessagesettings', 'useidenticons', str(
self.settingsDialogInstance.ui.checkBoxUseIdenticons.isChecked()))
BMConfigParser().set('bitmessagesettings', 'replybelow', str(
self.settingsDialogInstance.ui.checkBoxReplyBelow.isChecked()))
lang = str(self.settingsDialogInstance.ui.languageComboBox.itemData(self.settingsDialogInstance.ui.languageComboBox.currentIndex()).toString())
BMConfigParser().set('bitmessagesettings', 'userlocale', lang)
change_translation(l10n.getTranslationLanguage())
if int(BMConfigParser().get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'):
QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "You must restart Bitmessage for the port number change to take effect."))
BMConfigParser().set('bitmessagesettings', 'port', str(
self.settingsDialogInstance.ui.lineEditTCPPort.text()))
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked() != BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp'):
BMConfigParser().set('bitmessagesettings', 'upnp', str(self.settingsDialogInstance.ui.checkBoxUPnP.isChecked()))
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked():
import upnp
upnpThread = upnp.uPnPThread()
upnpThread.start()
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText()', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5]
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
if shared.statusIconColor != 'red':
QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any)."))
if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
self.statusbar.clearMessage()
state.resetNetworkProtocolAvailability() # just in case we changed something in the network connectivity
if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(
self.settingsDialogInstance.ui.comboBoxProxyType.currentText()))
else:
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'none')
BMConfigParser().set('bitmessagesettings', 'socksauthentication', str(
self.settingsDialogInstance.ui.checkBoxAuthentication.isChecked()))
BMConfigParser().set('bitmessagesettings', 'sockshostname', str(
self.settingsDialogInstance.ui.lineEditSocksHostname.text()))
BMConfigParser().set('bitmessagesettings', 'socksport', str(
self.settingsDialogInstance.ui.lineEditSocksPort.text()))
BMConfigParser().set('bitmessagesettings', 'socksusername', str(
self.settingsDialogInstance.ui.lineEditSocksUsername.text()))
BMConfigParser().set('bitmessagesettings', 'sockspassword', str(
self.settingsDialogInstance.ui.lineEditSocksPassword.text()))
BMConfigParser().set('bitmessagesettings', 'sockslisten', str(
self.settingsDialogInstance.ui.checkBoxSocksListen.isChecked()))
try:
# Rounding to integers just for aesthetics
BMConfigParser().set('bitmessagesettings', 'maxdownloadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxDownloadRate.text()))))
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text()))))
except ValueError:
QtGui.QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate(
"MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed."))
else:
set_rates(BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate"))
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text()))))
BMConfigParser().set('bitmessagesettings', 'namecoinrpctype',
self.settingsDialogInstance.getNamecoinType())
BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str(
self.settingsDialogInstance.ui.lineEditNamecoinHost.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcport', str(
self.settingsDialogInstance.ui.lineEditNamecoinPort.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcuser', str(
self.settingsDialogInstance.ui.lineEditNamecoinUser.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcpassword', str(
self.settingsDialogInstance.ui.lineEditNamecoinPassword.text()))
self.resetNamecoinConnection()
# Demanded difficulty tab
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
BMConfigParser().set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(int(float(
self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1:
BMConfigParser().set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(int(float(
self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)))
if self.settingsDialogInstance.ui.comboBoxOpenCL.currentText().toUtf8() != BMConfigParser().safeGet("bitmessagesettings", "opencl"):
BMConfigParser().set('bitmessagesettings', 'opencl', str(self.settingsDialogInstance.ui.comboBoxOpenCL.currentText()))
queues.workerQueue.put(('resetPoW', ''))
acceptableDifficultyChanged = False
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) == 0:
if BMConfigParser().get('bitmessagesettings','maxacceptablenoncetrialsperbyte') != str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
# the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True
BMConfigParser().set('bitmessagesettings', 'maxacceptablenoncetrialsperbyte', str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0:
if BMConfigParser().get('bitmessagesettings','maxacceptablepayloadlengthextrabytes') != str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)):
# the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True
BMConfigParser().set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)))
if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously marked as toodifficult.
# Let us change them to 'msgqueued'. The singleWorker will try to send them and will again
# mark them as toodifficult if the receiver's required difficulty is still higher than
# we are willing to do.
sqlExecute('''UPDATE sent SET status='msgqueued' WHERE status='toodifficult' ''')
queues.workerQueue.put(('sendmessage', ''))
#start:UI setting to stop trying to send messages after X days/months
# I'm open to changing this UI to something else if someone has a better idea.
if ((self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')):#We need to handle this special case. Bitmessage has its default behavior. The input is blank/blank
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '')
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
try:
float(self.settingsDialogInstance.ui.lineEditDays.text())
lineEditDaysIsValidFloat = True
except:
lineEditDaysIsValidFloat = False
try:
float(self.settingsDialogInstance.ui.lineEditMonths.text())
lineEditMonthsIsValidFloat = True
except:
lineEditMonthsIsValidFloat = False
if lineEditDaysIsValidFloat and not lineEditMonthsIsValidFloat:
self.settingsDialogInstance.ui.lineEditMonths.setText("0")
if lineEditMonthsIsValidFloat and not lineEditDaysIsValidFloat:
self.settingsDialogInstance.ui.lineEditDays.setText("0")
if lineEditDaysIsValidFloat or lineEditMonthsIsValidFloat:
if (float(self.settingsDialogInstance.ui.lineEditDays.text()) >=0 and float(self.settingsDialogInstance.ui.lineEditMonths.text()) >=0):
shared.maximumLengthOfTimeToBotherResendingMessages = (float(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60) + (float(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: # If the time period is less than 5 hours, we give zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about(self, _translate("MainWindow", "Will not resend ever"), _translate(
"MainWindow", "Note that the time limit you entered is less than the amount of time Bitmessage waits for the first resend attempt therefore your messages will never be resent."))
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '0')
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '0')
shared.maximumLengthOfTimeToBotherResendingMessages = 0
else:
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', str(float(
self.settingsDialogInstance.ui.lineEditDays.text())))
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', str(float(
self.settingsDialogInstance.ui.lineEditMonths.text())))
BMConfigParser().save()
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(RUN_PATH, QtCore.QSettings.NativeFormat)
if BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
else:
self.settings.remove("PyBitmessage")
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
if state.appdata != paths.lookupExeFolder() and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location
sqlStoredProcedure('movemessagstoprog')
with open(paths.lookupExeFolder() + 'keys.dat', 'wb') as configfile:
BMConfigParser().write(configfile)
# Write the knownnodes.dat file to disk in the new location
knownnodes.saveKnownNodes(paths.lookupExeFolder())
os.remove(state.appdata + 'keys.dat')
os.remove(state.appdata + 'knownnodes.dat')
previousAppdataLocation = state.appdata
state.appdata = paths.lookupExeFolder()
debug.resetLogging()
try:
os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1')
except:
pass
if state.appdata == paths.lookupExeFolder() and not self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we ARE using portable mode now but the user selected that we shouldn't...
state.appdata = paths.lookupAppdataFolder()
if not os.path.exists(state.appdata):
os.makedirs(state.appdata)
sqlStoredProcedure('movemessagstoappdata')
# Write the keys.dat file to disk in the new location
BMConfigParser().save()
# Write the knownnodes.dat file to disk in the new location
knownnodes.saveKnownNodes(state.appdata)
os.remove(paths.lookupExeFolder() + 'keys.dat')
os.remove(paths.lookupExeFolder() + 'knownnodes.dat')
debug.resetLogging()
try:
os.remove(paths.lookupExeFolder() + 'debug.log')
os.remove(paths.lookupExeFolder() + 'debug.log.1')
except:
pass
def on_action_Send(self): def on_action_Send(self):
"""Send message to current selected address""" """Send message to current selected address"""
@ -3204,7 +3393,8 @@ class MyForm(settingsmixin.SMainWindow):
0].row() 0].row()
item = self.ui.tableWidgetAddressBook.item(currentRow, 0) item = self.ui.tableWidgetAddressBook.item(currentRow, 0)
sqlExecute( sqlExecute(
'DELETE FROM addressbook WHERE address=?', item.address) 'DELETE FROM addressbook WHERE label=? AND address=?',
item.label, item.address)
self.ui.tableWidgetAddressBook.removeRow(currentRow) self.ui.tableWidgetAddressBook.removeRow(currentRow)
self.rerenderMessagelistFromLabels() self.rerenderMessagelistFromLabels()
self.rerenderMessagelistToLabels() self.rerenderMessagelistToLabels()
@ -4063,6 +4253,237 @@ class MyForm(settingsmixin.SMainWindow):
obj.loadSettings() obj.loadSettings()
class settingsDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_settingsDialog()
self.ui.setupUi(self)
self.parent = parent
self.ui.checkBoxStartOnLogon.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'))
self.ui.checkBoxMinimizeToTray.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray'))
self.ui.checkBoxTrayOnClose.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'trayonclose'))
self.ui.checkBoxHideTrayConnectionNotifications.setChecked(
BMConfigParser().getboolean("bitmessagesettings", "hidetrayconnectionnotifications"))
self.ui.checkBoxShowTrayNotifications.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'showtraynotifications'))
self.ui.checkBoxStartInTray.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'startintray'))
self.ui.checkBoxWillinglySendToMobile.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'willinglysendtomobile'))
self.ui.checkBoxUseIdenticons.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.ui.checkBoxReplyBelow.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'))
if state.appdata == paths.lookupExeFolder():
self.ui.checkBoxPortableMode.setChecked(True)
else:
try:
import tempfile
tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete
except:
self.ui.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform:
self.ui.checkBoxStartOnLogon.setDisabled(True)
self.ui.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
self.ui.checkBoxMinimizeToTray.setDisabled(True)
self.ui.checkBoxMinimizeToTray.setText(_translate(
"MainWindow", "Minimize-to-tray not yet supported on your OS."))
self.ui.checkBoxShowTrayNotifications.setDisabled(True)
self.ui.checkBoxShowTrayNotifications.setText(_translate(
"MainWindow", "Tray notifications not yet supported on your OS."))
elif 'linux' in sys.platform:
self.ui.checkBoxStartOnLogon.setDisabled(True)
self.ui.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
# On the Network settings tab:
self.ui.lineEditTCPPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'port')))
self.ui.checkBoxUPnP.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp'))
self.ui.checkBoxAuthentication.setChecked(BMConfigParser().getboolean(
'bitmessagesettings', 'socksauthentication'))
self.ui.checkBoxSocksListen.setChecked(BMConfigParser().getboolean(
'bitmessagesettings', 'sockslisten'))
if str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'none':
self.ui.comboBoxProxyType.setCurrentIndex(0)
self.ui.lineEditSocksHostname.setEnabled(False)
self.ui.lineEditSocksPort.setEnabled(False)
self.ui.lineEditSocksUsername.setEnabled(False)
self.ui.lineEditSocksPassword.setEnabled(False)
self.ui.checkBoxAuthentication.setEnabled(False)
self.ui.checkBoxSocksListen.setEnabled(False)
elif str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'SOCKS4a':
self.ui.comboBoxProxyType.setCurrentIndex(1)
elif str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'SOCKS5':
self.ui.comboBoxProxyType.setCurrentIndex(2)
self.ui.lineEditSocksHostname.setText(str(
BMConfigParser().get('bitmessagesettings', 'sockshostname')))
self.ui.lineEditSocksPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'socksport')))
self.ui.lineEditSocksUsername.setText(str(
BMConfigParser().get('bitmessagesettings', 'socksusername')))
self.ui.lineEditSocksPassword.setText(str(
BMConfigParser().get('bitmessagesettings', 'sockspassword')))
QtCore.QObject.connect(self.ui.comboBoxProxyType, QtCore.SIGNAL(
"currentIndexChanged(int)"), self.comboBoxProxyTypeChanged)
self.ui.lineEditMaxDownloadRate.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxdownloadrate')))
self.ui.lineEditMaxUploadRate.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxuploadrate')))
self.ui.lineEditMaxOutboundConnections.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxoutboundconnections')))
# Demanded difficulty tab
self.ui.lineEditTotalDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'defaultnoncetrialsperbyte')) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.ui.lineEditSmallMessageDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')) / defaults.networkDefaultPayloadLengthExtraBytes)))
# Max acceptable difficulty tab
self.ui.lineEditMaxAcceptableTotalDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.ui.lineEditMaxAcceptableSmallMessageDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes')) / defaults.networkDefaultPayloadLengthExtraBytes)))
# OpenCL
if openclpow.openclAvailable():
self.ui.comboBoxOpenCL.setEnabled(True)
else:
self.ui.comboBoxOpenCL.setEnabled(False)
self.ui.comboBoxOpenCL.clear()
self.ui.comboBoxOpenCL.addItem("None")
self.ui.comboBoxOpenCL.addItems(openclpow.vendors)
self.ui.comboBoxOpenCL.setCurrentIndex(0)
for i in range(self.ui.comboBoxOpenCL.count()):
if self.ui.comboBoxOpenCL.itemText(i) == BMConfigParser().safeGet('bitmessagesettings', 'opencl'):
self.ui.comboBoxOpenCL.setCurrentIndex(i)
break
# Namecoin integration tab
nmctype = BMConfigParser().get('bitmessagesettings', 'namecoinrpctype')
self.ui.lineEditNamecoinHost.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpchost')))
self.ui.lineEditNamecoinPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcport')))
self.ui.lineEditNamecoinUser.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcuser')))
self.ui.lineEditNamecoinPassword.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcpassword')))
if nmctype == "namecoind":
self.ui.radioButtonNamecoinNamecoind.setChecked(True)
elif nmctype == "nmcontrol":
self.ui.radioButtonNamecoinNmcontrol.setChecked(True)
self.ui.lineEditNamecoinUser.setEnabled(False)
self.ui.labelNamecoinUser.setEnabled(False)
self.ui.lineEditNamecoinPassword.setEnabled(False)
self.ui.labelNamecoinPassword.setEnabled(False)
else:
assert False
QtCore.QObject.connect(self.ui.radioButtonNamecoinNamecoind, QtCore.SIGNAL(
"toggled(bool)"), self.namecoinTypeChanged)
QtCore.QObject.connect(self.ui.radioButtonNamecoinNmcontrol, QtCore.SIGNAL(
"toggled(bool)"), self.namecoinTypeChanged)
QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonNamecoinTest)
#Message Resend tab
self.ui.lineEditDays.setText(str(
BMConfigParser().get('bitmessagesettings', 'stopresendingafterxdays')))
self.ui.lineEditMonths.setText(str(
BMConfigParser().get('bitmessagesettings', 'stopresendingafterxmonths')))
#'System' tab removed for now.
"""try:
maxCores = BMConfigParser().getint('bitmessagesettings', 'maxcores')
except:
maxCores = 99999
if maxCores <= 1:
self.ui.comboBoxMaxCores.setCurrentIndex(0)
elif maxCores == 2:
self.ui.comboBoxMaxCores.setCurrentIndex(1)
elif maxCores <= 4:
self.ui.comboBoxMaxCores.setCurrentIndex(2)
elif maxCores <= 8:
self.ui.comboBoxMaxCores.setCurrentIndex(3)
elif maxCores <= 16:
self.ui.comboBoxMaxCores.setCurrentIndex(4)
else:
self.ui.comboBoxMaxCores.setCurrentIndex(5)"""
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def comboBoxProxyTypeChanged(self, comboBoxIndex):
if comboBoxIndex == 0:
self.ui.lineEditSocksHostname.setEnabled(False)
self.ui.lineEditSocksPort.setEnabled(False)
self.ui.lineEditSocksUsername.setEnabled(False)
self.ui.lineEditSocksPassword.setEnabled(False)
self.ui.checkBoxAuthentication.setEnabled(False)
self.ui.checkBoxSocksListen.setEnabled(False)
elif comboBoxIndex == 1 or comboBoxIndex == 2:
self.ui.lineEditSocksHostname.setEnabled(True)
self.ui.lineEditSocksPort.setEnabled(True)
self.ui.checkBoxAuthentication.setEnabled(True)
self.ui.checkBoxSocksListen.setEnabled(True)
if self.ui.checkBoxAuthentication.isChecked():
self.ui.lineEditSocksUsername.setEnabled(True)
self.ui.lineEditSocksPassword.setEnabled(True)
# Check status of namecoin integration radio buttons and translate
# it to a string as in the options.
def getNamecoinType(self):
if self.ui.radioButtonNamecoinNamecoind.isChecked():
return "namecoind"
if self.ui.radioButtonNamecoinNmcontrol.isChecked():
return "nmcontrol"
assert False
# Namecoin connection type was changed.
def namecoinTypeChanged(self, checked):
nmctype = self.getNamecoinType()
assert nmctype == "namecoind" or nmctype == "nmcontrol"
isNamecoind = (nmctype == "namecoind")
self.ui.lineEditNamecoinUser.setEnabled(isNamecoind)
self.ui.labelNamecoinUser.setEnabled(isNamecoind)
self.ui.lineEditNamecoinPassword.setEnabled(isNamecoind)
self.ui.labelNamecoinPassword.setEnabled(isNamecoind)
if isNamecoind:
self.ui.lineEditNamecoinPort.setText(defaults.namecoinDefaultRpcPort)
else:
self.ui.lineEditNamecoinPort.setText("9000")
def click_pushButtonNamecoinTest(self):
"""Test the namecoin settings specified in the settings dialog."""
self.ui.labelNamecoinTestResult.setText(_translate(
"MainWindow", "Testing..."))
options = {}
options["type"] = self.getNamecoinType()
options["host"] = str(self.ui.lineEditNamecoinHost.text().toUtf8())
options["port"] = str(self.ui.lineEditNamecoinPort.text().toUtf8())
options["user"] = str(self.ui.lineEditNamecoinUser.text().toUtf8())
options["password"] = str(self.ui.lineEditNamecoinPassword.text().toUtf8())
nc = namecoin.namecoinConnection(options)
status, text = nc.test()
self.ui.labelNamecoinTestResult.setText(text)
if status == 'success':
self.parent.namecoin = nc
# In order for the time columns on the Inbox and Sent tabs to be sorted # In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the < # correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem. # operator and use this class instead of QTableWidgetItem.
@ -4137,6 +4558,7 @@ def init():
def run(): def run():
global myapp global myapp
app = init() app = init()
change_translation(l10n.getTranslationLanguage())
app.setStyleSheet("QStatusBar::item { border: 0px solid black }") app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm() myapp = MyForm()

View File

@ -46,7 +46,7 @@
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2020 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2019 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeft</set> <set>Qt::AlignLeft</set>

View File

@ -5,25 +5,22 @@ src/bitmessageqt/dialogs.py
from PyQt4 import QtGui from PyQt4 import QtGui
from version import softwareVersion
import paths import paths
import widgets import widgets
from address_dialogs import ( from address_dialogs import (
AddAddressDialog, EmailGatewayDialog, NewAddressDialog, AddAddressDialog, EmailGatewayDialog, NewAddressDialog, NewSubscriptionDialog, RegenerateAddressesDialog,
NewSubscriptionDialog, RegenerateAddressesDialog,
SpecialAddressBehaviorDialog SpecialAddressBehaviorDialog
) )
from newchandialog import NewChanDialog from newchandialog import NewChanDialog
from retranslateui import RetranslateMixin from retranslateui import RetranslateMixin
from settings import SettingsDialog
from tr import _translate from tr import _translate
from version import softwareVersion
__all__ = [ __all__ = [
"NewChanDialog", "AddAddressDialog", "NewAddressDialog", "NewChanDialog", "AddAddressDialog", "NewAddressDialog",
"NewSubscriptionDialog", "RegenerateAddressesDialog", "NewSubscriptionDialog", "RegenerateAddressesDialog",
"SpecialAddressBehaviorDialog", "EmailGatewayDialog", "SpecialAddressBehaviorDialog", "EmailGatewayDialog"
"SettingsDialog"
] ]
@ -47,7 +44,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
try: try:
self.label_2.setText( self.label_2.setText(
self.label_2.text().replace( self.label_2.text().replace(
'2020', str(last_commit.get('time').year) '2019', str(last_commit.get('time').year)
)) ))
except AttributeError: except AttributeError:
pass pass

View File

@ -14,7 +14,7 @@ import network.stats
import shared import shared
import widgets import widgets
from inventory import Inventory from inventory import Inventory
from network import BMConnectionPool from network.connectionpool import BMConnectionPool
from retranslateui import RetranslateMixin from retranslateui import RetranslateMixin
from tr import _translate from tr import _translate
from uisignaler import UISignaler from uisignaler import UISignaler

View File

@ -1,584 +1,630 @@
import ConfigParser # -*- coding: utf-8 -*-
import os # pylint: disable=too-many-instance-attributes,too-many-locals,too-many-statements,attribute-defined-outside-init
import sys """
src/bitmessageqt/settings.py
============================
Form implementation generated from reading ui file 'settings.ui'
Created: Thu Dec 25 23:21:20 2014
by: PyQt4 UI code generator 4.10.3
WARNING! All changes made in this file will be lost!
"""
from sys import platform
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import debug from . import bitmessage_icons_rc # pylint: disable=unused-import
import defaults from .languagebox import LanguageBox
import knownnodes
import namecoin try:
import openclpow _fromUtf8 = QtCore.QString.fromUtf8
import paths except AttributeError:
import queues def _fromUtf8(s):
import shared return s
import state
import tempfile try:
import widgets _encoding = QtGui.QApplication.UnicodeUTF8
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlStoredProcedure def _translate(context, text, disambig):
from helper_startup import start_proxyconfig return QtGui.QApplication.translate(context, text, disambig, _encoding)
from network.asyncore_pollchoose import set_rates except AttributeError:
from tr import _translate def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
def getSOCKSProxyType(config): class Ui_settingsDialog(object):
"""Get user socksproxytype setting from *config*""" """Encapsulate a UI settings dialog object"""
try:
result = ConfigParser.SafeConfigParser.get(
config, 'bitmessagesettings', 'socksproxytype')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return
else:
if result.lower() in ('', 'none', 'false'):
result = None
return result
def setupUi(self, settingsDialog):
"""Set up the UI"""
class SettingsDialog(QtGui.QDialog): settingsDialog.setObjectName(_fromUtf8("settingsDialog"))
"""The "Settings" dialog""" settingsDialog.resize(521, 413)
def __init__(self, parent=None, firstrun=False): self.gridLayout = QtGui.QGridLayout(settingsDialog)
super(SettingsDialog, self).__init__(parent) self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
widgets.load('settings.ui', self) self.buttonBox = QtGui.QDialogButtonBox(settingsDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.parent = parent self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
self.firstrun = firstrun self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.config = BMConfigParser() self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.net_restart_needed = False self.tabWidgetSettings = QtGui.QTabWidget(settingsDialog)
self.timer = QtCore.QTimer() self.tabWidgetSettings.setObjectName(_fromUtf8("tabWidgetSettings"))
self.tabUserInterface = QtGui.QWidget()
try: self.tabUserInterface.setEnabled(True)
import pkg_resources self.tabUserInterface.setObjectName(_fromUtf8("tabUserInterface"))
except ImportError: self.formLayout = QtGui.QFormLayout(self.tabUserInterface)
pass self.formLayout.setObjectName(_fromUtf8("formLayout"))
else: self.checkBoxStartOnLogon = QtGui.QCheckBox(self.tabUserInterface)
# Append proxy types defined in plugins self.checkBoxStartOnLogon.setObjectName(_fromUtf8("checkBoxStartOnLogon"))
for ep in pkg_resources.iter_entry_points( self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.checkBoxStartOnLogon)
'bitmessage.proxyconfig'): self.groupBoxTray = QtGui.QGroupBox(self.tabUserInterface)
self.comboBoxProxyType.addItem(ep.name) self.groupBoxTray.setObjectName(_fromUtf8("groupBoxTray"))
self.formLayoutTray = QtGui.QFormLayout(self.groupBoxTray)
self.formLayoutTray.setObjectName(_fromUtf8("formLayoutTray"))
self.checkBoxStartInTray = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxStartInTray.setObjectName(_fromUtf8("checkBoxStartInTray"))
self.formLayoutTray.setWidget(0, QtGui.QFormLayout.SpanningRole, self.checkBoxStartInTray)
self.checkBoxMinimizeToTray = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxMinimizeToTray.setChecked(True)
self.checkBoxMinimizeToTray.setObjectName(_fromUtf8("checkBoxMinimizeToTray"))
self.formLayoutTray.setWidget(1, QtGui.QFormLayout.LabelRole, self.checkBoxMinimizeToTray)
self.checkBoxTrayOnClose = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxTrayOnClose.setChecked(True)
self.checkBoxTrayOnClose.setObjectName(_fromUtf8("checkBoxTrayOnClose"))
self.formLayoutTray.setWidget(2, QtGui.QFormLayout.LabelRole, self.checkBoxTrayOnClose)
self.formLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.groupBoxTray)
self.checkBoxHideTrayConnectionNotifications = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxHideTrayConnectionNotifications.setChecked(False)
self.checkBoxHideTrayConnectionNotifications.setObjectName(
_fromUtf8("checkBoxHideTrayConnectionNotifications"))
self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.checkBoxHideTrayConnectionNotifications)
self.checkBoxShowTrayNotifications = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxShowTrayNotifications.setObjectName(_fromUtf8("checkBoxShowTrayNotifications"))
self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.checkBoxShowTrayNotifications)
self.checkBoxPortableMode = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxPortableMode.setObjectName(_fromUtf8("checkBoxPortableMode"))
self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.checkBoxPortableMode)
self.PortableModeDescription = QtGui.QLabel(self.tabUserInterface)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PortableModeDescription.sizePolicy().hasHeightForWidth())
self.PortableModeDescription.setSizePolicy(sizePolicy)
self.PortableModeDescription.setWordWrap(True)
self.PortableModeDescription.setObjectName(_fromUtf8("PortableModeDescription"))
self.formLayout.setWidget(5, QtGui.QFormLayout.SpanningRole, self.PortableModeDescription)
self.checkBoxWillinglySendToMobile = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxWillinglySendToMobile.setObjectName(_fromUtf8("checkBoxWillinglySendToMobile"))
self.formLayout.setWidget(6, QtGui.QFormLayout.SpanningRole, self.checkBoxWillinglySendToMobile)
self.checkBoxUseIdenticons = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxUseIdenticons.setObjectName(_fromUtf8("checkBoxUseIdenticons"))
self.formLayout.setWidget(7, QtGui.QFormLayout.LabelRole, self.checkBoxUseIdenticons)
self.checkBoxReplyBelow = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxReplyBelow.setObjectName(_fromUtf8("checkBoxReplyBelow"))
self.formLayout.setWidget(8, QtGui.QFormLayout.LabelRole, self.checkBoxReplyBelow)
self.groupBox = QtGui.QGroupBox(self.tabUserInterface)
self.groupBox.setObjectName(_fromUtf8("groupBox"))
self.formLayout_2 = QtGui.QFormLayout(self.groupBox)
self.formLayout_2.setObjectName(_fromUtf8("formLayout_2"))
self.languageComboBox = LanguageBox(self.groupBox)
self.languageComboBox.setMinimumSize(QtCore.QSize(100, 0))
self.languageComboBox.setObjectName(_fromUtf8("languageComboBox")) # pylint: disable=not-callable
self.formLayout_2.setWidget(0, QtGui.QFormLayout.LabelRole, self.languageComboBox)
self.formLayout.setWidget(9, QtGui.QFormLayout.FieldRole, self.groupBox)
self.tabWidgetSettings.addTab(self.tabUserInterface, _fromUtf8(""))
self.tabNetworkSettings = QtGui.QWidget()
self.tabNetworkSettings.setObjectName(_fromUtf8("tabNetworkSettings"))
self.gridLayout_4 = QtGui.QGridLayout(self.tabNetworkSettings)
self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
self.groupBox1 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox1.setObjectName(_fromUtf8("groupBox1"))
self.gridLayout_3 = QtGui.QGridLayout(self.groupBox1)
self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
self.label = QtGui.QLabel(self.groupBox1)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout_3.addWidget(self.label, 0, 0, 1, 1, QtCore.Qt.AlignRight)
self.lineEditTCPPort = QtGui.QLineEdit(self.groupBox1)
self.lineEditTCPPort.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditTCPPort.setObjectName(_fromUtf8("lineEditTCPPort"))
self.gridLayout_3.addWidget(self.lineEditTCPPort, 0, 1, 1, 1, QtCore.Qt.AlignLeft)
self.labelUPnP = QtGui.QLabel(self.groupBox1)
self.labelUPnP.setObjectName(_fromUtf8("labelUPnP"))
self.gridLayout_3.addWidget(self.labelUPnP, 0, 2, 1, 1, QtCore.Qt.AlignRight)
self.checkBoxUPnP = QtGui.QCheckBox(self.groupBox1)
self.checkBoxUPnP.setObjectName(_fromUtf8("checkBoxUPnP"))
self.gridLayout_3.addWidget(self.checkBoxUPnP, 0, 3, 1, 1, QtCore.Qt.AlignLeft)
self.gridLayout_4.addWidget(self.groupBox1, 0, 0, 1, 1)
self.groupBox_3 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
self.gridLayout_9 = QtGui.QGridLayout(self.groupBox_3)
self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9"))
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_9.addItem(spacerItem1, 0, 0, 2, 1)
self.label_24 = QtGui.QLabel(self.groupBox_3)
self.label_24.setObjectName(_fromUtf8("label_24"))
self.gridLayout_9.addWidget(self.label_24, 0, 1, 1, 1)
self.lineEditMaxDownloadRate = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxDownloadRate.sizePolicy().hasHeightForWidth())
self.lineEditMaxDownloadRate.setSizePolicy(sizePolicy)
self.lineEditMaxDownloadRate.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxDownloadRate.setObjectName(_fromUtf8("lineEditMaxDownloadRate"))
self.gridLayout_9.addWidget(self.lineEditMaxDownloadRate, 0, 2, 1, 1)
self.label_25 = QtGui.QLabel(self.groupBox_3)
self.label_25.setObjectName(_fromUtf8("label_25"))
self.gridLayout_9.addWidget(self.label_25, 1, 1, 1, 1)
self.lineEditMaxUploadRate = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxUploadRate.sizePolicy().hasHeightForWidth())
self.lineEditMaxUploadRate.setSizePolicy(sizePolicy)
self.lineEditMaxUploadRate.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxUploadRate.setObjectName(_fromUtf8("lineEditMaxUploadRate"))
self.gridLayout_9.addWidget(self.lineEditMaxUploadRate, 1, 2, 1, 1)
self.label_26 = QtGui.QLabel(self.groupBox_3)
self.label_26.setObjectName(_fromUtf8("label_26"))
self.gridLayout_9.addWidget(self.label_26, 2, 1, 1, 1)
self.lineEditMaxOutboundConnections = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxOutboundConnections.sizePolicy().hasHeightForWidth())
self.lineEditMaxOutboundConnections.setSizePolicy(sizePolicy)
self.lineEditMaxOutboundConnections.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxOutboundConnections.setObjectName(_fromUtf8("lineEditMaxOutboundConnections"))
self.lineEditMaxOutboundConnections.setValidator( self.lineEditMaxOutboundConnections.setValidator(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections)) QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
self.gridLayout_9.addWidget(self.lineEditMaxOutboundConnections, 2, 2, 1, 1)
self.adjust_from_config(self.config) self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1)
if firstrun: self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings)
# switch to "Network Settings" tab if user selected self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
# "Let me configure special network settings first" on first run self.gridLayout_2 = QtGui.QGridLayout(self.groupBox_2)
self.tabWidgetSettings.setCurrentIndex( self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.tabWidgetSettings.indexOf(self.tabNetworkSettings) self.label_2 = QtGui.QLabel(self.groupBox_2)
) self.label_2.setObjectName(_fromUtf8("label_2"))
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1)
self.label_3 = QtGui.QLabel(self.groupBox_2)
def adjust_from_config(self, config): self.label_3.setObjectName(_fromUtf8("label_3"))
"""Adjust all widgets state according to config settings""" self.gridLayout_2.addWidget(self.label_3, 1, 1, 1, 1)
# pylint: disable=too-many-branches,too-many-statements self.lineEditSocksHostname = QtGui.QLineEdit(self.groupBox_2)
if not self.parent.tray.isSystemTrayAvailable(): self.lineEditSocksHostname.setObjectName(_fromUtf8("lineEditSocksHostname"))
self.groupBoxTray.setEnabled(False) self.lineEditSocksHostname.setPlaceholderText(_fromUtf8("127.0.0.1"))
self.groupBoxTray.setTitle(_translate( self.gridLayout_2.addWidget(self.lineEditSocksHostname, 1, 2, 1, 2)
"MainWindow", "Tray (not available in your system)")) self.label_4 = QtGui.QLabel(self.groupBox_2)
for setting in ( self.label_4.setObjectName(_fromUtf8("label_4"))
'minimizetotray', 'trayonclose', 'startintray'): self.gridLayout_2.addWidget(self.label_4, 1, 4, 1, 1)
config.set('bitmessagesettings', setting, 'false') self.lineEditSocksPort = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksPort.setObjectName(_fromUtf8("lineEditSocksPort"))
if platform in ['darwin', 'win32', 'win64']:
self.lineEditSocksPort.setPlaceholderText(_fromUtf8("9150"))
else: else:
self.checkBoxMinimizeToTray.setChecked( self.lineEditSocksPort.setPlaceholderText(_fromUtf8("9050"))
config.getboolean('bitmessagesettings', 'minimizetotray')) self.gridLayout_2.addWidget(self.lineEditSocksPort, 1, 5, 1, 1)
self.checkBoxTrayOnClose.setChecked( self.checkBoxAuthentication = QtGui.QCheckBox(self.groupBox_2)
config.safeGetBoolean('bitmessagesettings', 'trayonclose')) self.checkBoxAuthentication.setObjectName(_fromUtf8("checkBoxAuthentication"))
self.checkBoxStartInTray.setChecked( self.gridLayout_2.addWidget(self.checkBoxAuthentication, 2, 1, 1, 1)
config.getboolean('bitmessagesettings', 'startintray')) self.label_5 = QtGui.QLabel(self.groupBox_2)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.checkBoxHideTrayConnectionNotifications.setChecked( self.gridLayout_2.addWidget(self.label_5, 2, 2, 1, 1)
config.getboolean( self.lineEditSocksUsername = QtGui.QLineEdit(self.groupBox_2)
'bitmessagesettings', 'hidetrayconnectionnotifications'))
self.checkBoxShowTrayNotifications.setChecked(
config.getboolean('bitmessagesettings', 'showtraynotifications'))
self.checkBoxStartOnLogon.setChecked(
config.getboolean('bitmessagesettings', 'startonlogon'))
self.checkBoxWillinglySendToMobile.setChecked(
config.safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile'))
self.checkBoxUseIdenticons.setChecked(
config.safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.checkBoxReplyBelow.setChecked(
config.safeGetBoolean('bitmessagesettings', 'replybelow'))
if state.appdata == paths.lookupExeFolder():
self.checkBoxPortableMode.setChecked(True)
else:
try:
tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete
except:
self.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform:
self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
self.checkBoxMinimizeToTray.setDisabled(True)
self.checkBoxMinimizeToTray.setText(_translate(
"MainWindow",
"Minimize-to-tray not yet supported on your OS."))
self.checkBoxShowTrayNotifications.setDisabled(True)
self.checkBoxShowTrayNotifications.setText(_translate(
"MainWindow",
"Tray notifications not yet supported on your OS."))
elif 'linux' in sys.platform:
self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
# On the Network settings tab:
self.lineEditTCPPort.setText(str(
config.get('bitmessagesettings', 'port')))
self.checkBoxUPnP.setChecked(
config.safeGetBoolean('bitmessagesettings', 'upnp'))
self.checkBoxAuthentication.setChecked(
config.getboolean('bitmessagesettings', 'socksauthentication'))
self.checkBoxSocksListen.setChecked(
config.getboolean('bitmessagesettings', 'sockslisten'))
self.checkBoxOnionOnly.setChecked(
config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
self._proxy_type = getSOCKSProxyType(config)
self.comboBoxProxyType.setCurrentIndex(
0 if not self._proxy_type
else self.comboBoxProxyType.findText(self._proxy_type))
self.comboBoxProxyTypeChanged(self.comboBoxProxyType.currentIndex())
self.lineEditSocksHostname.setText(
config.get('bitmessagesettings', 'sockshostname'))
self.lineEditSocksPort.setText(str(
config.get('bitmessagesettings', 'socksport')))
self.lineEditSocksUsername.setText(
config.get('bitmessagesettings', 'socksusername'))
self.lineEditSocksPassword.setText(
config.get('bitmessagesettings', 'sockspassword'))
self.lineEditMaxDownloadRate.setText(str(
config.get('bitmessagesettings', 'maxdownloadrate')))
self.lineEditMaxUploadRate.setText(str(
config.get('bitmessagesettings', 'maxuploadrate')))
self.lineEditMaxOutboundConnections.setText(str(
config.get('bitmessagesettings', 'maxoutboundconnections')))
# Demanded difficulty tab
self.lineEditTotalDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditSmallMessageDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
# Max acceptable difficulty tab
self.lineEditMaxAcceptableTotalDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditMaxAcceptableSmallMessageDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
# OpenCL
self.comboBoxOpenCL.setEnabled(openclpow.openclAvailable())
self.comboBoxOpenCL.clear()
self.comboBoxOpenCL.addItem("None")
self.comboBoxOpenCL.addItems(openclpow.vendors)
self.comboBoxOpenCL.setCurrentIndex(0)
for i in range(self.comboBoxOpenCL.count()):
if self.comboBoxOpenCL.itemText(i) == config.safeGet(
'bitmessagesettings', 'opencl'):
self.comboBoxOpenCL.setCurrentIndex(i)
break
# Namecoin integration tab
nmctype = config.get('bitmessagesettings', 'namecoinrpctype')
self.lineEditNamecoinHost.setText(
config.get('bitmessagesettings', 'namecoinrpchost'))
self.lineEditNamecoinPort.setText(str(
config.get('bitmessagesettings', 'namecoinrpcport')))
self.lineEditNamecoinUser.setText(
config.get('bitmessagesettings', 'namecoinrpcuser'))
self.lineEditNamecoinPassword.setText(
config.get('bitmessagesettings', 'namecoinrpcpassword'))
if nmctype == "namecoind":
self.radioButtonNamecoinNamecoind.setChecked(True)
elif nmctype == "nmcontrol":
self.radioButtonNamecoinNmcontrol.setChecked(True)
self.lineEditNamecoinUser.setEnabled(False)
self.labelNamecoinUser.setEnabled(False)
self.lineEditNamecoinPassword.setEnabled(False)
self.labelNamecoinPassword.setEnabled(False)
else:
assert False
# Message Resend tab
self.lineEditDays.setText(str(
config.get('bitmessagesettings', 'stopresendingafterxdays')))
self.lineEditMonths.setText(str(
config.get('bitmessagesettings', 'stopresendingafterxmonths')))
def comboBoxProxyTypeChanged(self, comboBoxIndex):
"""A callback for currentIndexChanged event of comboBoxProxyType"""
if comboBoxIndex == 0:
self.lineEditSocksHostname.setEnabled(False)
self.lineEditSocksPort.setEnabled(False)
self.lineEditSocksUsername.setEnabled(False) self.lineEditSocksUsername.setEnabled(False)
self.lineEditSocksUsername.setObjectName(_fromUtf8("lineEditSocksUsername"))
self.gridLayout_2.addWidget(self.lineEditSocksUsername, 2, 3, 1, 1)
self.label_6 = QtGui.QLabel(self.groupBox_2)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.gridLayout_2.addWidget(self.label_6, 2, 4, 1, 1)
self.lineEditSocksPassword = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksPassword.setEnabled(False) self.lineEditSocksPassword.setEnabled(False)
self.checkBoxAuthentication.setEnabled(False) self.lineEditSocksPassword.setInputMethodHints(
self.checkBoxSocksListen.setEnabled(False) QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText)
self.checkBoxOnionOnly.setEnabled(False) self.lineEditSocksPassword.setEchoMode(QtGui.QLineEdit.Password)
else: self.lineEditSocksPassword.setObjectName(_fromUtf8("lineEditSocksPassword"))
self.lineEditSocksHostname.setEnabled(True) self.gridLayout_2.addWidget(self.lineEditSocksPassword, 2, 5, 1, 1)
self.lineEditSocksPort.setEnabled(True) self.checkBoxSocksListen = QtGui.QCheckBox(self.groupBox_2)
self.checkBoxAuthentication.setEnabled(True) self.checkBoxSocksListen.setObjectName(_fromUtf8("checkBoxSocksListen"))
self.checkBoxSocksListen.setEnabled(True) self.gridLayout_2.addWidget(self.checkBoxSocksListen, 3, 1, 1, 4)
self.checkBoxOnionOnly.setEnabled(True) self.comboBoxProxyType = QtGui.QComboBox(self.groupBox_2)
if self.checkBoxAuthentication.isChecked(): self.comboBoxProxyType.setObjectName(_fromUtf8("comboBoxProxyType")) # pylint: disable=not-callable
self.lineEditSocksUsername.setEnabled(True) self.comboBoxProxyType.addItem(_fromUtf8(""))
self.lineEditSocksPassword.setEnabled(True) self.comboBoxProxyType.addItem(_fromUtf8(""))
self.comboBoxProxyType.addItem(_fromUtf8(""))
self.gridLayout_2.addWidget(self.comboBoxProxyType, 0, 1, 1, 1)
self.gridLayout_4.addWidget(self.groupBox_2, 1, 0, 1, 1)
spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_4.addItem(spacerItem2, 3, 0, 1, 1)
self.tabWidgetSettings.addTab(self.tabNetworkSettings, _fromUtf8(""))
self.tabDemandedDifficulty = QtGui.QWidget()
self.tabDemandedDifficulty.setObjectName(_fromUtf8("tabDemandedDifficulty"))
self.gridLayout_6 = QtGui.QGridLayout(self.tabDemandedDifficulty)
self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6"))
self.label_9 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_9.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_9.setObjectName(_fromUtf8("label_9"))
self.gridLayout_6.addWidget(self.label_9, 1, 1, 1, 1)
self.label_10 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_10.setWordWrap(True)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.gridLayout_6.addWidget(self.label_10, 2, 0, 1, 3)
self.label_11 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_11.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_11.setObjectName(_fromUtf8("label_11"))
self.gridLayout_6.addWidget(self.label_11, 3, 1, 1, 1)
self.label_8 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_8.setWordWrap(True)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.gridLayout_6.addWidget(self.label_8, 0, 0, 1, 3)
spacerItem3 = QtGui.QSpacerItem(203, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_6.addItem(spacerItem3, 1, 0, 1, 1)
self.label_12 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_12.setWordWrap(True)
self.label_12.setObjectName(_fromUtf8("label_12"))
self.gridLayout_6.addWidget(self.label_12, 4, 0, 1, 3)
self.lineEditSmallMessageDifficulty = QtGui.QLineEdit(self.tabDemandedDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditSmallMessageDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditSmallMessageDifficulty.setSizePolicy(sizePolicy)
self.lineEditSmallMessageDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditSmallMessageDifficulty.setObjectName(_fromUtf8("lineEditSmallMessageDifficulty"))
self.gridLayout_6.addWidget(self.lineEditSmallMessageDifficulty, 3, 2, 1, 1)
self.lineEditTotalDifficulty = QtGui.QLineEdit(self.tabDemandedDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditTotalDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditTotalDifficulty.setSizePolicy(sizePolicy)
self.lineEditTotalDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditTotalDifficulty.setObjectName(_fromUtf8("lineEditTotalDifficulty"))
self.gridLayout_6.addWidget(self.lineEditTotalDifficulty, 1, 2, 1, 1)
spacerItem4 = QtGui.QSpacerItem(203, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_6.addItem(spacerItem4, 3, 0, 1, 1)
spacerItem5 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_6.addItem(spacerItem5, 5, 0, 1, 1)
self.tabWidgetSettings.addTab(self.tabDemandedDifficulty, _fromUtf8(""))
self.tabMaxAcceptableDifficulty = QtGui.QWidget()
self.tabMaxAcceptableDifficulty.setObjectName(_fromUtf8("tabMaxAcceptableDifficulty"))
self.gridLayout_7 = QtGui.QGridLayout(self.tabMaxAcceptableDifficulty)
self.gridLayout_7.setObjectName(_fromUtf8("gridLayout_7"))
self.label_15 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_15.setWordWrap(True)
self.label_15.setObjectName(_fromUtf8("label_15"))
self.gridLayout_7.addWidget(self.label_15, 0, 0, 1, 3)
spacerItem6 = QtGui.QSpacerItem(102, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_7.addItem(spacerItem6, 1, 0, 1, 1)
self.label_13 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_13.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label_13.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_13.setObjectName(_fromUtf8("label_13"))
self.gridLayout_7.addWidget(self.label_13, 1, 1, 1, 1)
self.lineEditMaxAcceptableTotalDifficulty = QtGui.QLineEdit(self.tabMaxAcceptableDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxAcceptableTotalDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditMaxAcceptableTotalDifficulty.setSizePolicy(sizePolicy)
self.lineEditMaxAcceptableTotalDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditMaxAcceptableTotalDifficulty.setObjectName(_fromUtf8("lineEditMaxAcceptableTotalDifficulty"))
self.gridLayout_7.addWidget(self.lineEditMaxAcceptableTotalDifficulty, 1, 2, 1, 1)
spacerItem7 = QtGui.QSpacerItem(102, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_7.addItem(spacerItem7, 2, 0, 1, 1)
self.label_14 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_14.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_14.setObjectName(_fromUtf8("label_14"))
self.gridLayout_7.addWidget(self.label_14, 2, 1, 1, 1)
self.lineEditMaxAcceptableSmallMessageDifficulty = QtGui.QLineEdit(self.tabMaxAcceptableDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxAcceptableSmallMessageDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditMaxAcceptableSmallMessageDifficulty.setSizePolicy(sizePolicy)
self.lineEditMaxAcceptableSmallMessageDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditMaxAcceptableSmallMessageDifficulty.setObjectName(
_fromUtf8("lineEditMaxAcceptableSmallMessageDifficulty"))
self.gridLayout_7.addWidget(self.lineEditMaxAcceptableSmallMessageDifficulty, 2, 2, 1, 1)
spacerItem8 = QtGui.QSpacerItem(20, 147, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_7.addItem(spacerItem8, 3, 1, 1, 1)
self.labelOpenCL = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.labelOpenCL.setObjectName(_fromUtf8("labelOpenCL"))
self.gridLayout_7.addWidget(self.labelOpenCL, 4, 0, 1, 1)
self.comboBoxOpenCL = QtGui.QComboBox(self.tabMaxAcceptableDifficulty)
self.comboBoxOpenCL.setObjectName = (_fromUtf8("comboBoxOpenCL"))
self.gridLayout_7.addWidget(self.comboBoxOpenCL, 4, 1, 1, 1)
self.tabWidgetSettings.addTab(self.tabMaxAcceptableDifficulty, _fromUtf8(""))
self.tabNamecoin = QtGui.QWidget()
self.tabNamecoin.setObjectName(_fromUtf8("tabNamecoin"))
self.gridLayout_8 = QtGui.QGridLayout(self.tabNamecoin)
self.gridLayout_8.setObjectName(_fromUtf8("gridLayout_8"))
spacerItem9 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem9, 2, 0, 1, 1)
self.label_16 = QtGui.QLabel(self.tabNamecoin)
self.label_16.setWordWrap(True)
self.label_16.setObjectName(_fromUtf8("label_16"))
self.gridLayout_8.addWidget(self.label_16, 0, 0, 1, 3)
self.label_17 = QtGui.QLabel(self.tabNamecoin)
self.label_17.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_17.setObjectName(_fromUtf8("label_17"))
self.gridLayout_8.addWidget(self.label_17, 2, 1, 1, 1)
self.lineEditNamecoinHost = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinHost.setObjectName(_fromUtf8("lineEditNamecoinHost"))
self.gridLayout_8.addWidget(self.lineEditNamecoinHost, 2, 2, 1, 1)
spacerItem10 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem10, 3, 0, 1, 1)
spacerItem11 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem11, 4, 0, 1, 1)
self.label_18 = QtGui.QLabel(self.tabNamecoin)
self.label_18.setEnabled(True)
self.label_18.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_18.setObjectName(_fromUtf8("label_18"))
self.gridLayout_8.addWidget(self.label_18, 3, 1, 1, 1)
self.lineEditNamecoinPort = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinPort.setObjectName(_fromUtf8("lineEditNamecoinPort"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPort, 3, 2, 1, 1)
spacerItem12 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_8.addItem(spacerItem12, 8, 1, 1, 1)
self.labelNamecoinUser = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinUser.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.labelNamecoinUser.setObjectName(_fromUtf8("labelNamecoinUser"))
self.gridLayout_8.addWidget(self.labelNamecoinUser, 4, 1, 1, 1)
self.lineEditNamecoinUser = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinUser.setObjectName(_fromUtf8("lineEditNamecoinUser"))
self.gridLayout_8.addWidget(self.lineEditNamecoinUser, 4, 2, 1, 1)
spacerItem13 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem13, 5, 0, 1, 1)
self.labelNamecoinPassword = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinPassword.setAlignment(
QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.labelNamecoinPassword.setObjectName(_fromUtf8("labelNamecoinPassword"))
self.gridLayout_8.addWidget(self.labelNamecoinPassword, 5, 1, 1, 1)
self.lineEditNamecoinPassword = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinPassword.setInputMethodHints(
QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText)
self.lineEditNamecoinPassword.setEchoMode(QtGui.QLineEdit.Password)
self.lineEditNamecoinPassword.setObjectName(_fromUtf8("lineEditNamecoinPassword"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPassword, 5, 2, 1, 1)
self.labelNamecoinTestResult = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinTestResult.setText(_fromUtf8(""))
self.labelNamecoinTestResult.setObjectName(_fromUtf8("labelNamecoinTestResult"))
self.gridLayout_8.addWidget(self.labelNamecoinTestResult, 7, 0, 1, 2)
self.pushButtonNamecoinTest = QtGui.QPushButton(self.tabNamecoin)
self.pushButtonNamecoinTest.setObjectName(_fromUtf8("pushButtonNamecoinTest"))
self.gridLayout_8.addWidget(self.pushButtonNamecoinTest, 7, 2, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label_21 = QtGui.QLabel(self.tabNamecoin)
self.label_21.setObjectName(_fromUtf8("label_21"))
self.horizontalLayout.addWidget(self.label_21)
self.radioButtonNamecoinNamecoind = QtGui.QRadioButton(self.tabNamecoin)
self.radioButtonNamecoinNamecoind.setObjectName(_fromUtf8("radioButtonNamecoinNamecoind"))
self.horizontalLayout.addWidget(self.radioButtonNamecoinNamecoind)
self.radioButtonNamecoinNmcontrol = QtGui.QRadioButton(self.tabNamecoin)
self.radioButtonNamecoinNmcontrol.setObjectName(_fromUtf8("radioButtonNamecoinNmcontrol"))
self.horizontalLayout.addWidget(self.radioButtonNamecoinNmcontrol)
self.gridLayout_8.addLayout(self.horizontalLayout, 1, 0, 1, 3)
self.tabWidgetSettings.addTab(self.tabNamecoin, _fromUtf8(""))
self.tabResendsExpire = QtGui.QWidget()
self.tabResendsExpire.setObjectName(_fromUtf8("tabResendsExpire"))
self.gridLayout_5 = QtGui.QGridLayout(self.tabResendsExpire)
self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
self.label_7 = QtGui.QLabel(self.tabResendsExpire)
self.label_7.setWordWrap(True)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.gridLayout_5.addWidget(self.label_7, 0, 0, 1, 3)
spacerItem14 = QtGui.QSpacerItem(212, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_5.addItem(spacerItem14, 1, 0, 1, 1)
self.widget = QtGui.QWidget(self.tabResendsExpire)
self.widget.setMinimumSize(QtCore.QSize(231, 75))
self.widget.setObjectName(_fromUtf8("widget"))
self.label_19 = QtGui.QLabel(self.widget)
self.label_19.setGeometry(QtCore.QRect(10, 20, 101, 20))
self.label_19.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_19.setObjectName(_fromUtf8("label_19"))
self.label_20 = QtGui.QLabel(self.widget)
self.label_20.setGeometry(QtCore.QRect(30, 40, 80, 16))
self.label_20.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_20.setObjectName(_fromUtf8("label_20"))
self.lineEditDays = QtGui.QLineEdit(self.widget)
self.lineEditDays.setGeometry(QtCore.QRect(113, 20, 51, 20))
self.lineEditDays.setObjectName(_fromUtf8("lineEditDays"))
self.lineEditMonths = QtGui.QLineEdit(self.widget)
self.lineEditMonths.setGeometry(QtCore.QRect(113, 40, 51, 20))
self.lineEditMonths.setObjectName(_fromUtf8("lineEditMonths"))
self.label_22 = QtGui.QLabel(self.widget)
self.label_22.setGeometry(QtCore.QRect(169, 23, 61, 16))
self.label_22.setObjectName(_fromUtf8("label_22"))
self.label_23 = QtGui.QLabel(self.widget)
self.label_23.setGeometry(QtCore.QRect(170, 41, 71, 16))
self.label_23.setObjectName(_fromUtf8("label_23"))
self.gridLayout_5.addWidget(self.widget, 1, 2, 1, 1)
spacerItem15 = QtGui.QSpacerItem(20, 129, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_5.addItem(spacerItem15, 2, 1, 1, 1)
self.tabWidgetSettings.addTab(self.tabResendsExpire, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1)
def getNamecoinType(self): self.retranslateUi(settingsDialog)
""" self.tabWidgetSettings.setCurrentIndex(0)
Check status of namecoin integration radio buttons QtCore.QObject.connect( # pylint: disable=no-member
and translate it to a string as in the options. self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept)
""" QtCore.QObject.connect( # pylint: disable=no-member
if self.radioButtonNamecoinNamecoind.isChecked(): self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), settingsDialog.reject)
return "namecoind" QtCore.QObject.connect( # pylint: disable=no-member
if self.radioButtonNamecoinNmcontrol.isChecked(): self.checkBoxAuthentication,
return "nmcontrol" QtCore.SIGNAL(
assert False _fromUtf8("toggled(bool)")),
self.lineEditSocksUsername.setEnabled)
QtCore.QObject.connect( # pylint: disable=no-member
self.checkBoxAuthentication,
QtCore.SIGNAL(
_fromUtf8("toggled(bool)")),
self.lineEditSocksPassword.setEnabled)
QtCore.QMetaObject.connectSlotsByName(settingsDialog)
settingsDialog.setTabOrder(self.tabWidgetSettings, self.checkBoxStartOnLogon)
settingsDialog.setTabOrder(self.checkBoxStartOnLogon, self.checkBoxStartInTray)
settingsDialog.setTabOrder(self.checkBoxStartInTray, self.checkBoxMinimizeToTray)
settingsDialog.setTabOrder(self.checkBoxMinimizeToTray, self.lineEditTCPPort)
settingsDialog.setTabOrder(self.lineEditTCPPort, self.comboBoxProxyType)
settingsDialog.setTabOrder(self.comboBoxProxyType, self.lineEditSocksHostname)
settingsDialog.setTabOrder(self.lineEditSocksHostname, self.lineEditSocksPort)
settingsDialog.setTabOrder(self.lineEditSocksPort, self.checkBoxAuthentication)
settingsDialog.setTabOrder(self.checkBoxAuthentication, self.lineEditSocksUsername)
settingsDialog.setTabOrder(self.lineEditSocksUsername, self.lineEditSocksPassword)
settingsDialog.setTabOrder(self.lineEditSocksPassword, self.checkBoxSocksListen)
settingsDialog.setTabOrder(self.checkBoxSocksListen, self.buttonBox)
# Namecoin connection type was changed. def retranslateUi(self, settingsDialog):
def namecoinTypeChanged(self, checked): # pylint: disable=unused-argument """Re-translate the UI into the supported languages"""
"""A callback for toggled event of radioButtonNamecoinNamecoind"""
nmctype = self.getNamecoinType()
assert nmctype == "namecoind" or nmctype == "nmcontrol"
isNamecoind = (nmctype == "namecoind") settingsDialog.setWindowTitle(_translate("settingsDialog", "Settings", None))
self.lineEditNamecoinUser.setEnabled(isNamecoind) self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None))
self.labelNamecoinUser.setEnabled(isNamecoind) self.groupBoxTray.setTitle(_translate("settingsDialog", "Tray", None))
self.lineEditNamecoinPassword.setEnabled(isNamecoind) self.checkBoxStartInTray.setText(
self.labelNamecoinPassword.setEnabled(isNamecoind)
if isNamecoind:
self.lineEditNamecoinPort.setText(defaults.namecoinDefaultRpcPort)
else:
self.lineEditNamecoinPort.setText("9000")
def click_pushButtonNamecoinTest(self):
"""Test the namecoin settings specified in the settings dialog."""
self.labelNamecoinTestResult.setText(
_translate("MainWindow", "Testing..."))
nc = namecoin.namecoinConnection({
'type': self.getNamecoinType(),
'host': str(self.lineEditNamecoinHost.text().toUtf8()),
'port': str(self.lineEditNamecoinPort.text().toUtf8()),
'user': str(self.lineEditNamecoinUser.text().toUtf8()),
'password': str(self.lineEditNamecoinPassword.text().toUtf8())
})
status, text = nc.test()
self.labelNamecoinTestResult.setText(text)
if status == 'success':
self.parent.namecoin = nc
def accept(self):
"""A callback for accepted event of buttonBox (OK button pressed)"""
# pylint: disable=too-many-branches,too-many-statements
super(SettingsDialog, self).accept()
if self.firstrun:
self.config.remove_option('bitmessagesettings', 'dontconnect')
self.config.set('bitmessagesettings', 'startonlogon', str(
self.checkBoxStartOnLogon.isChecked()))
self.config.set('bitmessagesettings', 'minimizetotray', str(
self.checkBoxMinimizeToTray.isChecked()))
self.config.set('bitmessagesettings', 'trayonclose', str(
self.checkBoxTrayOnClose.isChecked()))
self.config.set(
'bitmessagesettings', 'hidetrayconnectionnotifications',
str(self.checkBoxHideTrayConnectionNotifications.isChecked()))
self.config.set('bitmessagesettings', 'showtraynotifications', str(
self.checkBoxShowTrayNotifications.isChecked()))
self.config.set('bitmessagesettings', 'startintray', str(
self.checkBoxStartInTray.isChecked()))
self.config.set('bitmessagesettings', 'willinglysendtomobile', str(
self.checkBoxWillinglySendToMobile.isChecked()))
self.config.set('bitmessagesettings', 'useidenticons', str(
self.checkBoxUseIdenticons.isChecked()))
self.config.set('bitmessagesettings', 'replybelow', str(
self.checkBoxReplyBelow.isChecked()))
lang = str(self.languageComboBox.itemData(
self.languageComboBox.currentIndex()).toString())
self.config.set('bitmessagesettings', 'userlocale', lang)
self.parent.change_translation()
if int(self.config.get('bitmessagesettings', 'port')) != int(
self.lineEditTCPPort.text()):
self.config.set(
'bitmessagesettings', 'port', str(self.lineEditTCPPort.text()))
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
self.net_restart_needed = True
if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean(
'bitmessagesettings', 'upnp'):
self.config.set(
'bitmessagesettings', 'upnp',
str(self.checkBoxUPnP.isChecked()))
if self.checkBoxUPnP.isChecked():
import upnp
upnpThread = upnp.uPnPThread()
upnpThread.start()
proxytype_index = self.comboBoxProxyType.currentIndex()
if proxytype_index == 0:
if self._proxy_type and shared.statusIconColor != 'red':
self.net_restart_needed = True
elif self.comboBoxProxyType.currentText() != self._proxy_type:
self.net_restart_needed = True
self.parent.statusbar.clearMessage()
self.config.set(
'bitmessagesettings', 'socksproxytype',
'none' if self.comboBoxProxyType.currentIndex() == 0
else str(self.comboBoxProxyType.currentText())
)
if proxytype_index > 2: # last literal proxytype in ui
start_proxyconfig()
self.config.set('bitmessagesettings', 'socksauthentication', str(
self.checkBoxAuthentication.isChecked()))
self.config.set('bitmessagesettings', 'sockshostname', str(
self.lineEditSocksHostname.text()))
self.config.set('bitmessagesettings', 'socksport', str(
self.lineEditSocksPort.text()))
self.config.set('bitmessagesettings', 'socksusername', str(
self.lineEditSocksUsername.text()))
self.config.set('bitmessagesettings', 'sockspassword', str(
self.lineEditSocksPassword.text()))
self.config.set('bitmessagesettings', 'sockslisten', str(
self.checkBoxSocksListen.isChecked()))
if self.checkBoxOnionOnly.isChecked() \
and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'):
self.net_restart_needed = True
self.config.set('bitmessagesettings', 'onionservicesonly', str(
self.checkBoxOnionOnly.isChecked()))
try:
# Rounding to integers just for aesthetics
self.config.set('bitmessagesettings', 'maxdownloadrate', str(
int(float(self.lineEditMaxDownloadRate.text()))))
self.config.set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.lineEditMaxUploadRate.text()))))
except ValueError:
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Number needed"),
_translate( _translate(
"MainWindow", "settingsDialog",
"Your maximum download and upload rate must be numbers." "Start Bitmessage in the tray (don\'t show main window)",
" Ignoring what you typed.") None))
) self.checkBoxMinimizeToTray.setText(_translate("settingsDialog", "Minimize to tray", None))
else: self.checkBoxTrayOnClose.setText(_translate("settingsDialog", "Close to tray", None))
set_rates( self.checkBoxHideTrayConnectionNotifications.setText(
self.config.safeGetInt('bitmessagesettings', 'maxdownloadrate'), _translate("settingsDialog", "Hide connection notifications", None))
self.config.safeGetInt('bitmessagesettings', 'maxuploadrate')) self.checkBoxShowTrayNotifications.setText(
self.config.set('bitmessagesettings', 'maxoutboundconnections', str(
int(float(self.lineEditMaxOutboundConnections.text()))))
self.config.set(
'bitmessagesettings', 'namecoinrpctype', self.getNamecoinType())
self.config.set('bitmessagesettings', 'namecoinrpchost', str(
self.lineEditNamecoinHost.text()))
self.config.set('bitmessagesettings', 'namecoinrpcport', str(
self.lineEditNamecoinPort.text()))
self.config.set('bitmessagesettings', 'namecoinrpcuser', str(
self.lineEditNamecoinUser.text()))
self.config.set('bitmessagesettings', 'namecoinrpcpassword', str(
self.lineEditNamecoinPassword.text()))
self.parent.resetNamecoinConnection()
# Demanded difficulty tab
if float(self.lineEditTotalDifficulty.text()) >= 1:
self.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(int(
float(self.lineEditTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.lineEditSmallMessageDifficulty.text()) >= 1:
self.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(int(
float(self.lineEditSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes)))
if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet(
'bitmessagesettings', 'opencl'):
self.config.set(
'bitmessagesettings', 'opencl',
str(self.comboBoxOpenCL.currentText()))
queues.workerQueue.put(('resetPoW', ''))
acceptableDifficultyChanged = False
if (
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or
float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
):
if self.config.get(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
) != str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
):
# the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True
self.config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
)
if (
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
):
if self.config.get(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) != str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes)
):
# the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True
self.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes))
)
if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously
# marked as toodifficult. Let us change them to 'msgqueued'.
# The singleWorker will try to send them and will again mark
# them as toodifficult if the receiver's required difficulty
# is still higher than we are willing to do.
sqlExecute(
"UPDATE sent SET status='msgqueued'"
" WHERE status='toodifficult'")
queues.workerQueue.put(('sendmessage', ''))
stopResendingDefaults = False
# UI setting to stop trying to send messages after X days/months
# I'm open to changing this UI to something else if someone has a better idea.
if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '':
# We need to handle this special case. Bitmessage has its
# default behavior. The input is blank/blank
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
stopResendingDefaults = True
try:
days = float(self.lineEditDays.text())
except ValueError:
self.lineEditDays.setText("0")
days = 0.0
try:
months = float(self.lineEditMonths.text())
except ValueError:
self.lineEditMonths.setText("0")
months = 0.0
if days >= 0 and months >= 0 and not stopResendingDefaults:
shared.maximumLengthOfTimeToBotherResendingMessages = \
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000:
# If the time period is less than 5 hours, we give
# zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about(
self,
_translate("MainWindow", "Will not resend ever"),
_translate( _translate(
"MainWindow", "settingsDialog",
"Note that the time limit you entered is less" "Show notification when message received",
" than the amount of time Bitmessage waits for" None))
" the first resend attempt therefore your" self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", None))
" messages will never be resent.") self.PortableModeDescription.setText(
) _translate(
self.config.set( "settingsDialog",
'bitmessagesettings', 'stopresendingafterxdays', '0') "In Portable Mode, messages and config files are stored in the same directory as the"
self.config.set( " program rather than the normal application-data folder. This makes it convenient to"
'bitmessagesettings', 'stopresendingafterxmonths', '0') " run Bitmessage from a USB thumb drive.",
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0 None))
else: self.checkBoxWillinglySendToMobile.setText(
self.config.set( _translate(
'bitmessagesettings', 'stopresendingafterxdays', str(days)) "settingsDialog",
self.config.set( "Willingly include unencrypted destination address when sending to a mobile device",
'bitmessagesettings', 'stopresendingafterxmonths', None))
str(months)) self.checkBoxUseIdenticons.setText(_translate("settingsDialog", "Use Identicons", None))
self.checkBoxReplyBelow.setText(_translate("settingsDialog", "Reply below Quote", None))
self.config.save() self.groupBox.setTitle(_translate("settingsDialog", "Interface Language", None))
self.languageComboBox.setItemText(0, _translate("settingsDialog", "System Settings", "system"))
if self.net_restart_needed: self.tabWidgetSettings.setTabText(
self.net_restart_needed = False self.tabWidgetSettings.indexOf(
self.config.setTemp('bitmessagesettings', 'dontconnect', 'true') self.tabUserInterface),
self.timer.singleShot( _translate(
5000, lambda: "settingsDialog", "User Interface", None))
self.config.setTemp( self.groupBox1.setTitle(_translate("settingsDialog", "Listening port", None))
'bitmessagesettings', 'dontconnect', 'false') self.label.setText(_translate("settingsDialog", "Listen for connections on port:", None))
) self.labelUPnP.setText(_translate("settingsDialog", "UPnP:", None))
self.groupBox_3.setTitle(_translate("settingsDialog", "Bandwidth limit", None))
self.parent.updateStartOnLogon() self.label_24.setText(_translate("settingsDialog", "Maximum download rate (kB/s): [0: unlimited]", None))
self.label_25.setText(_translate("settingsDialog", "Maximum upload rate (kB/s): [0: unlimited]", None))
if ( self.label_26.setText(_translate("settingsDialog", "Maximum outbound connections: [0: none]", None))
state.appdata != paths.lookupExeFolder() and self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None))
self.checkBoxPortableMode.isChecked() self.label_2.setText(_translate("settingsDialog", "Type:", None))
): self.label_3.setText(_translate("settingsDialog", "Server hostname:", None))
# If we are NOT using portable mode now but the user selected self.label_4.setText(_translate("settingsDialog", "Port:", None))
# that we should... self.checkBoxAuthentication.setText(_translate("settingsDialog", "Authentication", None))
# Write the keys.dat file to disk in the new location self.label_5.setText(_translate("settingsDialog", "Username:", None))
sqlStoredProcedure('movemessagstoprog') self.label_6.setText(_translate("settingsDialog", "Pass:", None))
with open(paths.lookupExeFolder() + 'keys.dat', 'wb') as configfile: self.checkBoxSocksListen.setText(
self.config.write(configfile) _translate(
# Write the knownnodes.dat file to disk in the new location "settingsDialog",
knownnodes.saveKnownNodes(paths.lookupExeFolder()) "Listen for incoming connections when using proxy",
os.remove(state.appdata + 'keys.dat') None))
os.remove(state.appdata + 'knownnodes.dat') self.comboBoxProxyType.setItemText(0, _translate("settingsDialog", "none", None))
previousAppdataLocation = state.appdata self.comboBoxProxyType.setItemText(1, _translate("settingsDialog", "SOCKS4a", None))
state.appdata = paths.lookupExeFolder() self.comboBoxProxyType.setItemText(2, _translate("settingsDialog", "SOCKS5", None))
debug.resetLogging() self.tabWidgetSettings.setTabText(
try: self.tabWidgetSettings.indexOf(
os.remove(previousAppdataLocation + 'debug.log') self.tabNetworkSettings),
os.remove(previousAppdataLocation + 'debug.log.1') _translate(
except: "settingsDialog", "Network Settings", None))
pass self.label_9.setText(_translate("settingsDialog", "Total difficulty:", None))
self.label_10.setText(
if ( _translate(
state.appdata == paths.lookupExeFolder() and "settingsDialog",
not self.checkBoxPortableMode.isChecked() "The \'Total difficulty\' affects the absolute amount of work the sender must complete."
): " Doubling this value doubles the amount of work.",
# If we ARE using portable mode now but the user selected None))
# that we shouldn't... self.label_11.setText(_translate("settingsDialog", "Small message difficulty:", None))
state.appdata = paths.lookupAppdataFolder() self.label_8.setText(_translate(
if not os.path.exists(state.appdata): "settingsDialog",
os.makedirs(state.appdata) "When someone sends you a message, their computer must first complete some work. The difficulty of this"
sqlStoredProcedure('movemessagstoappdata') " work, by default, is 1. You may raise this default for new addresses you create by changing the values"
# Write the keys.dat file to disk in the new location " here. Any new addresses you create will require senders to meet the higher difficulty. There is one"
self.config.save() " exception: if you add a friend or acquaintance to your address book, Bitmessage will automatically"
# Write the knownnodes.dat file to disk in the new location " notify them when you next send a message that they need only complete the minimum amount of"
knownnodes.saveKnownNodes(state.appdata) " work: difficulty 1. ",
os.remove(paths.lookupExeFolder() + 'keys.dat') None))
os.remove(paths.lookupExeFolder() + 'knownnodes.dat') self.label_12.setText(
debug.resetLogging() _translate(
try: "settingsDialog",
os.remove(paths.lookupExeFolder() + 'debug.log') "The \'Small message difficulty\' mostly only affects the difficulty of sending small messages."
os.remove(paths.lookupExeFolder() + 'debug.log.1') " Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really"
except: " affect large messages.",
pass None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabDemandedDifficulty),
_translate(
"settingsDialog", "Demanded difficulty", None))
self.label_15.setText(
_translate(
"settingsDialog",
"Here you may set the maximum amount of work you are willing to do to send a message to another"
" person. Setting these values to 0 means that any value is acceptable.",
None))
self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None))
self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabMaxAcceptableDifficulty),
_translate(
"settingsDialog", "Max acceptable difficulty", None))
self.labelOpenCL.setText(_translate("settingsDialog", "Hardware GPU acceleration (OpenCL):", None))
self.label_16.setText(_translate(
"settingsDialog",
"<html><head/><body><p>Bitmessage can utilize a different Bitcoin-based program called Namecoin to make"
" addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage"
" address, you can simply tell him to send a message to <span style=\" font-style:italic;\">test."
" </span></p><p>(Getting your own Bitmessage address into Namecoin is still rather difficult).</p>"
"<p>Bitmessage can use either namecoind directly or a running nmcontrol instance.</p></body></html>",
None))
self.label_17.setText(_translate("settingsDialog", "Host:", None))
self.label_18.setText(_translate("settingsDialog", "Port:", None))
self.labelNamecoinUser.setText(_translate("settingsDialog", "Username:", None))
self.labelNamecoinPassword.setText(_translate("settingsDialog", "Password:", None))
self.pushButtonNamecoinTest.setText(_translate("settingsDialog", "Test", None))
self.label_21.setText(_translate("settingsDialog", "Connect to:", None))
self.radioButtonNamecoinNamecoind.setText(_translate("settingsDialog", "Namecoind", None))
self.radioButtonNamecoinNmcontrol.setText(_translate("settingsDialog", "NMControl", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabNamecoin),
_translate(
"settingsDialog", "Namecoin integration", None))
self.label_7.setText(_translate(
"settingsDialog",
"<html><head/><body><p>By default, if you send a message to someone and he is offline for more than two"
" days, Bitmessage will send the message again after an additional two days. This will be continued with"
" exponential backoff forever; messages will be resent after 5, 10, 20 days ect. until the receiver"
" acknowledges them. Here you may change that behavior by having Bitmessage give up after a certain"
" number of days or months.</p><p>Leave these input fields blank for the default behavior."
" </p></body></html>",
None))
self.label_19.setText(_translate("settingsDialog", "Give up after", None))
self.label_20.setText(_translate("settingsDialog", "and", None))
self.label_22.setText(_translate("settingsDialog", "days", None))
self.label_23.setText(_translate("settingsDialog", "months.", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabResendsExpire),
_translate(
"settingsDialog", "Resends Expire", None))

View File

@ -37,18 +37,6 @@
<string>User Interface</string> <string>User Interface</string>
</attribute> </attribute>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="checkBoxStartOnLogon"> <widget class="QCheckBox" name="checkBoxStartOnLogon">
<property name="text"> <property name="text">
@ -56,43 +44,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBoxTray">
<property name="title">
<string>Tray</string>
</property>
<layout class="QVBoxLayout" name="formLayoutTray">
<item>
<widget class="QCheckBox" name="checkBoxStartInTray"> <widget class="QCheckBox" name="checkBoxStartInTray">
<property name="text"> <property name="text">
<string>Start Bitmessage in the tray (don't show main window)</string> <string>Start Bitmessage in the tray (don't show main window)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QCheckBox" name="checkBoxMinimizeToTray"> <widget class="QCheckBox" name="checkBoxMinimizeToTray">
<property name="text"> <property name="text">
<string>Minimize to tray</string> <string>Minimize to tray</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxTrayOnClose">
<property name="text">
<string>Close to tray</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxHideTrayConnectionNotifications">
<property name="text">
<string>Hide connection notifications</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -152,15 +117,90 @@
<property name="title"> <property name="title">
<string>Interface Language</string> <string>Interface Language</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QFormLayout" name="formLayout_2">
<item> <item row="0" column="0">
<widget class="LanguageBox" name="languageComboBox"> <widget class="QComboBox" name="languageComboBox">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>100</width> <width>100</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<item>
<property name="text">
<string comment="system">System Settings</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="en">English</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="eo">Esperanto</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="fr">Français</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="de">Deutsch</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="es">Español</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ru">русский</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="no">Norsk</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ar">العربية</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="zh_cn">简体中文</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ja">日本語</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="nl">Nederlands</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="cs">Česky</string>
</property>
</item>
<item>
<property name="text">
<string comment="en_pirate">Pirate English</string>
</property>
</item>
<item>
<property name="text">
<string comment="other">Other (set in keys.dat)</string>
</property>
</item>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -173,18 +213,6 @@
<string>Network Settings</string> <string>Network Settings</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
@ -192,13 +220,26 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>125</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Listen for connections on port:</string> <string>Listen for connections on port:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="2">
<widget class="QLineEdit" name="lineEditTCPPort"> <widget class="QLineEdit" name="lineEditTCPPort">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -208,26 +249,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4">
<widget class="QCheckBox" name="checkBoxUPnP">
<property name="text">
<string>UPnP</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -403,13 +424,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="4">
<widget class="QCheckBox" name="checkBoxOnionOnly">
<property name="text">
<string>Only connect to onion services (*.onion)</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="comboBoxProxyType"> <widget class="QComboBox" name="comboBoxProxyType">
<item> <item>
@ -419,12 +433,12 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">SOCKS4a</string> <string>SOCKS4a</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">SOCKS5</string> <string>SOCKS5</string>
</property> </property>
</item> </item>
</widget> </widget>
@ -452,18 +466,6 @@
<string>Demanded difficulty</string> <string>Demanded difficulty</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="text"> <property name="text">
@ -592,18 +594,6 @@
<string>Max acceptable difficulty</string> <string>Max acceptable difficulty</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0" colspan="3"> <item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
@ -708,33 +698,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="labelOpenCL">
<property name="text">
<string>Hardware GPU acceleration (OpenCL):</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxOpenCL"/>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabNamecoin"> <widget class="QWidget" name="tabNamecoin">
@ -742,18 +705,6 @@
<string>Namecoin integration</string> <string>Namecoin integration</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="2" column="0"> <item row="2" column="0">
<spacer name="horizontalSpacer_6"> <spacer name="horizontalSpacer_6">
<property name="orientation"> <property name="orientation">
@ -937,18 +888,6 @@
<string>Resends Expire</string> <string>Resends Expire</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0" colspan="3"> <item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
@ -973,16 +912,22 @@
</spacer> </spacer>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QGroupBox"> <widget class="QWidget" name="widget" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>231</width> <width>231</width>
<height>75</height> <height>75</height>
</size> </size>
</property> </property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="label_19">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>Give up after</string> <string>Give up after</string>
</property> </property>
@ -990,9 +935,15 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_20"> <widget class="QLabel" name="label_20">
<property name="geometry">
<rect>
<x>30</x>
<y>40</y>
<width>80</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>and</string> <string>and</string>
</property> </property>
@ -1000,42 +951,52 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditDays"> <widget class="QLineEdit" name="lineEditDays">
<property name="maximumSize"> <property name="geometry">
<size> <rect>
<width>55</width> <x>113</x>
<height>100</height> <y>20</y>
</size> <width>51</width>
<height>20</height>
</rect>
</property> </property>
</widget> </widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditMonths"> <widget class="QLineEdit" name="lineEditMonths">
<property name="maximumSize"> <property name="geometry">
<size> <rect>
<width>55</width> <x>113</x>
<height>100</height> <y>40</y>
</size> <width>51</width>
<height>20</height>
</rect>
</property> </property>
</widget> </widget>
</item> <widget class="QLabel" name="label_22">
<item row="0" column="2"> <property name="geometry">
<widget class="QLabel"> <rect>
<x>169</x>
<y>23</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>days</string> <string>days</string>
</property> </property>
</widget> </widget>
</item> <widget class="QLabel" name="label_23">
<item row="1" column="2"> <property name="geometry">
<widget class="QLabel"> <rect>
<x>170</x>
<y>41</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>months.</string> <string>months.</string>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
@ -1056,14 +1017,7 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>LanguageBox</class>
<extends>QComboBox</extends>
<header>bitmessageqt.languagebox</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>tabWidgetSettings</tabstop> <tabstop>tabWidgetSettings</tabstop>
<tabstop>checkBoxStartOnLogon</tabstop> <tabstop>checkBoxStartOnLogon</tabstop>
@ -1147,53 +1101,5 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>comboBoxProxyType</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>settingsDialog</receiver>
<slot>comboBoxProxyTypeChanged</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioButtonNamecoinNamecoind</sender>
<signal>toggled(bool)</signal>
<receiver>settingsDialog</receiver>
<slot>namecoinTypeChanged</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonNamecoinTest</sender>
<signal>clicked()</signal>
<receiver>settingsDialog</receiver>
<slot>click_pushButtonNamecoinTest</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View File

@ -15,7 +15,6 @@ from openclpow import openclAvailable, openclEnabled
import paths import paths
import proofofwork import proofofwork
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
from settings import getSOCKSProxyType
import queues import queues
import network.stats import network.stats
import state import state
@ -119,7 +118,8 @@ def createSupportMessage(myapp):
BMConfigParser().safeGet('bitmessagesettings', 'opencl') BMConfigParser().safeGet('bitmessagesettings', 'opencl')
) if openclEnabled() else "None" ) if openclEnabled() else "None"
locale = getTranslationLanguage() locale = getTranslationLanguage()
socks = getSOCKSProxyType(BMConfigParser()) or "N/A" socks = BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype', "N/A")
upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A") upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A")
connectedhosts = len(network.stats.connectedHostsList()) connectedhosts = len(network.stats.connectedHostsList())

View File

@ -3,8 +3,8 @@ BMConfigParser class definition and default configuration settings
""" """
import ConfigParser import ConfigParser
import os
import shutil import shutil
import os
from datetime import datetime from datetime import datetime
import state import state
@ -43,13 +43,8 @@ BMConfigDefaults = {
@Singleton @Singleton
class BMConfigParser(ConfigParser.SafeConfigParser): class BMConfigParser(ConfigParser.SafeConfigParser):
""" """Singleton class inherited from ConfigParser.SafeConfigParser
Singleton class inherited from :class:`ConfigParser.SafeConfigParser` with additional methods specific to bitmessage config."""
with additional methods specific to bitmessage config.
"""
# pylint: disable=too-many-ancestors
_temp = {}
def set(self, section, option, value=None): def set(self, section, option, value=None):
if self._optcre is self.OPTCRE or value: if self._optcre is self.OPTCRE or value:
@ -60,15 +55,10 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return ConfigParser.ConfigParser.set(self, section, option, value) return ConfigParser.ConfigParser.set(self, section, option, value)
def get(self, section, option, raw=False, variables=None): def get(self, section, option, raw=False, variables=None):
# pylint: disable=arguments-differ
try: try:
if section == "bitmessagesettings" and option == "timeformat": if section == "bitmessagesettings" and option == "timeformat":
return ConfigParser.ConfigParser.get( return ConfigParser.ConfigParser.get(
self, section, option, raw, variables) self, section, option, raw, variables)
try:
return self._temp[section][option]
except KeyError:
pass
return ConfigParser.ConfigParser.get( return ConfigParser.ConfigParser.get(
self, section, option, True, variables) self, section, option, True, variables)
except ConfigParser.InterpolationError: except ConfigParser.InterpolationError:
@ -80,15 +70,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
except (KeyError, ValueError, AttributeError): except (KeyError, ValueError, AttributeError):
raise e raise e
def setTemp(self, section, option, value=None):
"""Temporary set option to value, not saving."""
try:
self._temp[section][option] = value
except KeyError:
self._temp[section] = {option: value}
def safeGetBoolean(self, section, field): def safeGetBoolean(self, section, field):
"""Return value as boolean, False on exceptions"""
try: try:
return self.getboolean(section, field) return self.getboolean(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -96,8 +78,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return False return False
def safeGetInt(self, section, field, default=0): def safeGetInt(self, section, field, default=0):
"""Return value as integer, default on exceptions,
0 if default missing"""
try: try:
return self.getint(section, field) return self.getint(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -105,7 +85,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def safeGet(self, section, option, default=None): def safeGet(self, section, option, default=None):
"""Return value as is, default on exceptions, None if default missing"""
try: try:
return self.get(section, option) return self.get(section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -113,16 +92,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def items(self, section, raw=False, variables=None): def items(self, section, raw=False, variables=None):
"""Return section variables as parent,
but override the "raw" argument to always True"""
# pylint: disable=arguments-differ
return ConfigParser.ConfigParser.items(self, section, True, variables) return ConfigParser.ConfigParser.items(self, section, True, variables)
@staticmethod def addresses(self):
def addresses(): return filter(
"""Return a list of local bitmessage addresses (from section labels)""" lambda x: x.startswith('BM-'), BMConfigParser().sections())
return [
x for x in BMConfigParser().sections() if x.startswith('BM-')]
def read(self, filenames): def read(self, filenames):
ConfigParser.ConfigParser.read(self, filenames) ConfigParser.ConfigParser.read(self, filenames)
@ -143,7 +117,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
continue continue
def save(self): def save(self):
"""Save the runtime config onto the filesystem"""
fileName = os.path.join(state.appdata, 'keys.dat') fileName = os.path.join(state.appdata, 'keys.dat')
fileNameBak = '.'.join([ fileNameBak = '.'.join([
fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak']) fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak'])
@ -165,15 +138,12 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
os.remove(fileNameBak) os.remove(fileNameBak)
def validate(self, section, option, value): def validate(self, section, option, value):
"""Input validator interface (using factory pattern)"""
try: try:
return getattr(self, 'validate_%s_%s' % (section, option))(value) return getattr(self, 'validate_%s_%s' % (section, option))(value)
except AttributeError: except AttributeError:
return True return True
@staticmethod def validate_bitmessagesettings_maxoutboundconnections(self, value):
def validate_bitmessagesettings_maxoutboundconnections(value):
"""Reject maxoutboundconnections that are too high or too low"""
try: try:
value = int(value) value = int(value)
except ValueError: except ValueError:

View File

@ -1,6 +1,6 @@
"""Building osx.""" """Building osx."""
import os
from glob import glob from glob import glob
import os
from PyQt4 import QtCore from PyQt4 import QtCore
from setuptools import setup from setuptools import setup
@ -13,14 +13,8 @@ DATA_FILES = [
('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']), ('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']),
('translations', glob('translations/*.qm')), ('translations', glob('translations/*.qm')),
('ui', glob('bitmessageqt/*.ui')), ('ui', glob('bitmessageqt/*.ui')),
( ('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??.qm')),
'translations', ('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??_??.qm')),
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??.qm'))),
(
'translations',
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??_??.qm'))),
] ]
setup( setup(

View File

@ -1,26 +1,24 @@
"""
A thread for creating addresses
"""
import hashlib
import time
from binascii import hexlify
import defaults import time
import highlevelcrypto import hashlib
import queues from binascii import hexlify
import shared
import state
import tr
from addresses import decodeAddress, encodeAddress, encodeVarint
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash
from network import StoppableThread
from pyelliptic import arithmetic from pyelliptic import arithmetic
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import tr
import queues
import state
import shared
import defaults
import highlevelcrypto
from bmconfigparser import BMConfigParser
from debug import logger
from addresses import decodeAddress, encodeAddress, encodeVarint
from fallback import RIPEMD160Hash
from helper_threading import StoppableThread
class addressGenerator(StoppableThread): class addressGenerator(StoppableThread):
"""A thread for creating addresses"""
name = "addressGenerator" name = "addressGenerator"
@ -32,12 +30,6 @@ class addressGenerator(StoppableThread):
super(addressGenerator, self).stopThread() super(addressGenerator, self).stopThread()
def run(self): def run(self):
"""
Process the requests for addresses generation
from `.queues.addressGeneratorQueue`
"""
# pylint: disable=too-many-locals, too-many-branches
# pylint: disable=protected-access, too-many-statements
while state.shutdown == 0: while state.shutdown == 0:
queueValue = queues.addressGeneratorQueue.get() queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0 nonceTrialsPerByte = 0
@ -93,12 +85,12 @@ class addressGenerator(StoppableThread):
elif queueValue[0] == 'stopThread': elif queueValue[0] == 'stopThread':
break break
else: else:
self.logger.error( logger.error(
'Programming error: A structure with the wrong number' 'Programming error: A structure with the wrong number'
' of values was passed into the addressGeneratorQueue.' ' of values was passed into the addressGeneratorQueue.'
' Here is the queueValue: %r\n', queueValue) ' Here is the queueValue: %r\n', queueValue)
if addressVersionNumber < 3 or addressVersionNumber > 4: if addressVersionNumber < 3 or addressVersionNumber > 4:
self.logger.error( logger.error(
'Program error: For some reason the address generator' 'Program error: For some reason the address generator'
' queue has been given a request to create at least' ' queue has been given a request to create at least'
' one version %s address which it cannot do.\n', ' one version %s address which it cannot do.\n',
@ -147,10 +139,10 @@ class addressGenerator(StoppableThread):
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash '\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
): ):
break break
self.logger.info( logger.info(
'Generated address with ripe digest: %s', hexlify(ripe)) 'Generated address with ripe digest: %s', hexlify(ripe))
try: try:
self.logger.info( logger.info(
'Address generator calculated %s addresses at %s' 'Address generator calculated %s addresses at %s'
' addresses per second before finding one with' ' addresses per second before finding one with'
' the correct ripe-prefix.', ' the correct ripe-prefix.',
@ -217,8 +209,8 @@ class addressGenerator(StoppableThread):
elif command == 'createDeterministicAddresses' \ elif command == 'createDeterministicAddresses' \
or command == 'getDeterministicAddress' \ or command == 'getDeterministicAddress' \
or command == 'createChan' or command == 'joinChan': or command == 'createChan' or command == 'joinChan':
if not deterministicPassphrase: if len(deterministicPassphrase) == 0:
self.logger.warning( logger.warning(
'You are creating deterministic' 'You are creating deterministic'
' address(es) using a blank passphrase.' ' address(es) using a blank passphrase.'
' Bitmessage will do it but it is rather stupid.') ' Bitmessage will do it but it is rather stupid.')
@ -271,10 +263,10 @@ class addressGenerator(StoppableThread):
): ):
break break
self.logger.info( logger.info(
'Generated address with ripe digest: %s', hexlify(ripe)) 'Generated address with ripe digest: %s', hexlify(ripe))
try: try:
self.logger.info( logger.info(
'Address generator calculated %s addresses' 'Address generator calculated %s addresses'
' at %s addresses per second before finding' ' at %s addresses per second before finding'
' one with the correct ripe-prefix.', ' one with the correct ripe-prefix.',
@ -324,7 +316,7 @@ class addressGenerator(StoppableThread):
addressAlreadyExists = True addressAlreadyExists = True
if addressAlreadyExists: if addressAlreadyExists:
self.logger.info( logger.info(
'%s already exists. Not adding it again.', '%s already exists. Not adding it again.',
address address
) )
@ -337,7 +329,7 @@ class addressGenerator(StoppableThread):
).arg(address) ).arg(address)
)) ))
else: else:
self.logger.debug('label: %s', label) logger.debug('label: %s', label)
BMConfigParser().set(address, 'label', label) BMConfigParser().set(address, 'label', label)
BMConfigParser().set(address, 'enabled', 'true') BMConfigParser().set(address, 'enabled', 'true')
BMConfigParser().set(address, 'decoy', 'false') BMConfigParser().set(address, 'decoy', 'false')

View File

@ -1,42 +1,32 @@
"""
The objectProcessor thread, of which there is only one,
processes the network objects
"""
# pylint: disable=too-many-locals,too-many-return-statements
# pylint: disable=too-many-branches,too-many-statements
import hashlib import hashlib
import logging
import random import random
import shared
import threading import threading
import time import time
from binascii import hexlify from binascii import hexlify
from subprocess import call # nosec from subprocess import call # nosec
import highlevelcrypto
import knownnodes
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeAddress,
encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
import helper_bitcoin import helper_bitcoin
import helper_inbox import helper_inbox
import helper_msgcoding import helper_msgcoding
import helper_sent import helper_sent
import highlevelcrypto from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
import knownnodes from helper_ackPayload import genAckPayload
import l10n from network import bmproto
import protocol import protocol
import queues import queues
import shared
import state import state
import tr import tr
from addresses import ( from debug import logger
calculateInventoryHash, decodeAddress, decodeVarint,
encodeAddress, encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash from fallback import RIPEMD160Hash
from helper_ackPayload import genAckPayload import l10n
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from network import bmproto
from network.node import Peer
# pylint: disable=too-many-locals, too-many-return-statements, too-many-branches, too-many-statements
logger = logging.getLogger('default')
class objectProcessor(threading.Thread): class objectProcessor(threading.Thread):
@ -65,7 +55,6 @@ class objectProcessor(threading.Thread):
self.successfullyDecryptMessageTimings = [] self.successfullyDecryptMessageTimings = []
def run(self): def run(self):
"""Process the objects from `.queues.objectProcessorQueue`"""
while True: while True:
objectType, data = queues.objectProcessorQueue.get() objectType, data = queues.objectProcessorQueue.get()
@ -129,10 +118,7 @@ class objectProcessor(threading.Thread):
state.shutdown = 2 state.shutdown = 2
break break
@staticmethod def checkackdata(self, data):
def checkackdata(data):
"""Checking Acknowledgement of message received or not?"""
# pylint: disable=protected-access
# Let's check whether this is a message acknowledgement bound for us. # Let's check whether this is a message acknowledgement bound for us.
if len(data) < 32: if len(data) < 32:
return return
@ -149,13 +135,11 @@ class objectProcessor(threading.Thread):
'ackreceived', int(time.time()), data[readPosition:]) 'ackreceived', int(time.time()), data[readPosition:])
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', 'updateSentItemStatusByAckdata',
( (data[readPosition:],
data[readPosition:],
tr._translate( tr._translate(
"MainWindow", "MainWindow",
"Acknowledgement of the message received %1" "Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp()) ).arg(l10n.formatTimestamp()))
)
)) ))
else: else:
logger.debug('This object is not an acknowledgement bound for me.') logger.debug('This object is not an acknowledgement bound for me.')
@ -174,7 +158,7 @@ class objectProcessor(threading.Thread):
if not host: if not host:
return return
peer = Peer(host, port) peer = state.Peer(host, port)
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
knownnodes.addKnownNode( knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer)) stream, peer, is_self=state.ownAddresses.get(peer))
@ -284,7 +268,6 @@ class objectProcessor(threading.Thread):
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress)) queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
def processpubkey(self, data): def processpubkey(self, data):
"""Process a pubkey object"""
pubkeyProcessingStartTime = time.time() pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1 shared.numberOfPubkeysProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -333,7 +316,6 @@ class objectProcessor(threading.Thread):
'\x04' + publicSigningKey + '\x04' + publicEncryptionKey) '\x04' + publicSigningKey + '\x04' + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s' 'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s' '\nripe %s\npublicSigningKey in hex: %s'
@ -398,7 +380,6 @@ class objectProcessor(threading.Thread):
sha.update(publicSigningKey + publicEncryptionKey) sha.update(publicSigningKey + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s' 'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s' '\nripe %s\npublicSigningKey in hex: %s'
@ -457,7 +438,6 @@ class objectProcessor(threading.Thread):
timeRequiredToProcessPubkey) timeRequiredToProcessPubkey)
def processmsg(self, data): def processmsg(self, data):
"""Process a message object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1 shared.numberOfMessagesProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -599,7 +579,6 @@ class objectProcessor(threading.Thread):
logger.debug('ECDSA verify failed') logger.debug('ECDSA verify failed')
return return
logger.debug('ECDSA verify passed') logger.debug('ECDSA verify passed')
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'As a matter of intellectual curiosity, here is the Bitcoin' 'As a matter of intellectual curiosity, here is the Bitcoin'
' address associated with the keys owned by the other person:' ' address associated with the keys owned by the other person:'
@ -647,8 +626,7 @@ class objectProcessor(threading.Thread):
if decodeAddress(toAddress)[1] >= 3 \ if decodeAddress(toAddress)[1] >= 3 \
and not BMConfigParser().safeGetBoolean(toAddress, 'chan'): and not BMConfigParser().safeGetBoolean(toAddress, 'chan'):
# If I'm not friendly with this person: # If I'm not friendly with this person:
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist( if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(fromAddress):
fromAddress):
requiredNonceTrialsPerByte = BMConfigParser().getint( requiredNonceTrialsPerByte = BMConfigParser().getint(
toAddress, 'noncetrialsperbyte') toAddress, 'noncetrialsperbyte')
requiredPayloadLengthExtraBytes = BMConfigParser().getint( requiredPayloadLengthExtraBytes = BMConfigParser().getint(
@ -754,7 +732,7 @@ class objectProcessor(threading.Thread):
# We really should have a discussion about how to # We really should have a discussion about how to
# set the TTL for mailing list broadcasts. This is obviously # set the TTL for mailing list broadcasts. This is obviously
# hard-coded. # hard-coded.
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks TTL = 2*7*24*60*60 # 2 weeks
t = ('', t = ('',
toAddress, toAddress,
ripe, ripe,
@ -806,7 +784,6 @@ class objectProcessor(threading.Thread):
) )
def processbroadcast(self, data): def processbroadcast(self, data):
"""Process a broadcast object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1 shared.numberOfBroadcastsProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -991,7 +968,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.info('fromAddress: %s', fromAddress) logger.info('fromAddress: %s' % fromAddress)
# Let's store the public key in case we want to reply to this person. # Let's store the public key in case we want to reply to this person.
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''', sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
@ -1008,7 +985,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.debug('fromAddress: %s', fromAddress) logger.debug('fromAddress: ' + fromAddress)
try: try:
decodedMessage = helper_msgcoding.MsgDecode( decodedMessage = helper_msgcoding.MsgDecode(
@ -1069,18 +1046,17 @@ class objectProcessor(threading.Thread):
# for it. # for it.
elif addressVersion >= 4: elif addressVersion >= 4:
tag = hashlib.sha512(hashlib.sha512( tag = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) + encodeVarint(streamNumber) encodeVarint(addressVersion) + encodeVarint(streamNumber) + ripe
+ ripe
).digest()).digest()[32:] ).digest()).digest()[32:]
if tag in state.neededPubkeys: if tag in state.neededPubkeys:
del state.neededPubkeys[tag] del state.neededPubkeys[tag]
self.sendMessages(address) self.sendMessages(address)
@staticmethod def sendMessages(self, address):
def sendMessages(address):
""" """
This method is called by the `possibleNewPubkey` when it sees This function is called by the possibleNewPubkey function when
that we now have the necessary pubkey to send one or more messages. that function sees that we now have the necessary pubkey
to send one or more messages.
""" """
logger.info('We have been awaiting the arrival of this pubkey.') logger.info('We have been awaiting the arrival of this pubkey.')
sqlExecute( sqlExecute(
@ -1090,9 +1066,7 @@ class objectProcessor(threading.Thread):
" AND folder='sent'", address) " AND folder='sent'", address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
@staticmethod def ackDataHasAValidHeader(self, ackData):
def ackDataHasAValidHeader(ackData):
"""Checking ackData with valid Header, not sending ackData when false"""
if len(ackData) < protocol.Header.size: if len(ackData) < protocol.Header.size:
logger.info( logger.info(
'The length of ackData is unreasonably short. Not sending' 'The length of ackData is unreasonably short. Not sending'
@ -1127,12 +1101,11 @@ class objectProcessor(threading.Thread):
return False return False
return True return True
@staticmethod def addMailingListNameToSubject(self, subject, mailingListName):
def addMailingListNameToSubject(subject, mailingListName):
"""Adding mailingListName to subject"""
subject = subject.strip() subject = subject.strip()
if subject[:3] == 'Re:' or subject[:3] == 'RE:': if subject[:3] == 'Re:' or subject[:3] == 'RE:':
subject = subject[3:].strip() subject = subject[3:].strip()
if '[' + mailingListName + ']' in subject: if '[' + mailingListName + ']' in subject:
return subject return subject
else:
return '[' + mailingListName + '] ' + subject return '[' + mailingListName + '] ' + subject

View File

@ -0,0 +1,24 @@
import Queue
import threading
import time
class ObjectProcessorQueue(Queue.Queue):
maxSize = 32000000
def __init__(self):
Queue.Queue.__init__(self)
self.sizeLock = threading.Lock()
self.curSize = 0 # in Bytes. We maintain this to prevent nodes from flooing us with objects which take up too much memory. If this gets too big we'll sleep before asking for further objects.
def put(self, item, block = True, timeout = None):
while self.curSize >= self.maxSize:
time.sleep(1)
with self.sizeLock:
self.curSize += len(item[1])
Queue.Queue.put(self, item, block, timeout)
def get(self, block = True, timeout = None):
item = Queue.Queue.get(self, block, timeout)
with self.sizeLock:
self.curSize -= len(item[1])
return item

View File

@ -1,57 +1,57 @@
""" """
The `singleCleaner` class is a timer-driven thread that cleans data structures The singleCleaner class is a timer-driven thread that cleans data structures
to free memory, resends messages when a remote node doesn't respond, and to free memory, resends messages when a remote node doesn't respond, and
sends pong messages to keep connections alive if the network isn't busy. sends pong messages to keep connections alive if the network isn't busy.
It cleans these data structures in memory: It cleans these data structures in memory:
- inventory (moves data to the on-disk sql database) inventory (moves data to the on-disk sql database)
- inventorySets (clears then reloads data out of sql database) inventorySets (clears then reloads data out of sql database)
It cleans these tables on the disk: It cleans these tables on the disk:
- inventory (clears expired objects) inventory (clears expired objects)
- pubkeys (clears pubkeys older than 4 weeks old which we have not used pubkeys (clears pubkeys older than 4 weeks old which we have not used
personally) personally)
- knownNodes (clears addresses which have not been online for over 3 days) knownNodes (clears addresses which have not been online for over 3 days)
It resends messages when there has been no response: It resends messages when there has been no response:
- resends getpubkey messages in 5 days (then 10 days, then 20 days, etc...) resends getpubkey messages in 5 days (then 10 days, then 20 days, etc...)
- resends msg messages in 5 days (then 10 days, then 20 days, etc...) resends msg messages in 5 days (then 10 days, then 20 days, etc...)
""" """
import gc import gc
import os import os
import shared
import time import time
import knownnodes
import queues
import shared
import state
import tr import tr
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlQuery, sqlExecute
from helper_threading import StoppableThread
from inventory import Inventory from inventory import Inventory
from network import BMConnectionPool, StoppableThread from network.connectionpool import BMConnectionPool
from debug import logger
import knownnodes
import queues
import state
class singleCleaner(StoppableThread): class singleCleaner(StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner" name = "singleCleaner"
cycleLength = 300 cycleLength = 300
expireDiscoveredPeers = 300 expireDiscoveredPeers = 300
def run(self): # pylint: disable=too-many-branches def run(self):
gc.disable() gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0 timeWeLastClearedInventoryAndPubkeysTables = 0
try: try:
shared.maximumLengthOfTimeToBotherResendingMessages = ( shared.maximumLengthOfTimeToBotherResendingMessages = (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxdays')) 'bitmessagesettings', 'stopresendingafterxdays')) *
* 24 * 60 * 60 24 * 60 * 60
) + ( ) + (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxmonths')) 'bitmessagesettings', 'stopresendingafterxmonths')) *
* (60 * 60 * 24 * 365) / 12) (60 * 60 * 24 * 365) / 12)
except: except:
# Either the user hasn't set stopresendingafterxdays and # Either the user hasn't set stopresendingafterxdays and
# stopresendingafterxmonths yet or the options are missing # stopresendingafterxmonths yet or the options are missing
@ -93,12 +93,12 @@ class singleCleaner(StoppableThread):
"SELECT toaddress, ackdata, status FROM sent" "SELECT toaddress, ackdata, status FROM sent"
" WHERE ((status='awaitingpubkey' OR status='msgsent')" " WHERE ((status='awaitingpubkey' OR status='msgsent')"
" AND folder='sent' AND sleeptill<? AND senttime>?)", " AND folder='sent' AND sleeptill<? AND senttime>?)",
int(time.time()), int(time.time()) int(time.time()), int(time.time()) -
- shared.maximumLengthOfTimeToBotherResendingMessages shared.maximumLengthOfTimeToBotherResendingMessages
) )
for row in queryreturn: for row in queryreturn:
if len(row) < 2: if len(row) < 2:
self.logger.error( logger.error(
'Something went wrong in the singleCleaner thread:' 'Something went wrong in the singleCleaner thread:'
' a query did not return the requested fields. %r', ' a query did not return the requested fields. %r',
row row
@ -107,18 +107,17 @@ class singleCleaner(StoppableThread):
break break
toAddress, ackData, status = row toAddress, ackData, status = row
if status == 'awaitingpubkey': if status == 'awaitingpubkey':
self.resendPubkeyRequest(toAddress) resendPubkeyRequest(toAddress)
elif status == 'msgsent': elif status == 'msgsent':
self.resendMsg(ackData) resendMsg(ackData)
try: try:
# Cleanup knownnodes and handle possible severe exception # Cleanup knownnodes and handle possible severe exception
# while writing it to disk # while writing it to disk
knownnodes.cleanupKnownNodes() knownnodes.cleanupKnownNodes()
except Exception as err: except Exception as err:
# pylint: disable=protected-access
if "Errno 28" in str(err): if "Errno 28" in str(err):
self.logger.fatal( logger.fatal(
'(while writing knownnodes to disk)' '(while writing knownnodes to disk)'
' Alert: Your disk or data storage volume is full.' ' Alert: Your disk or data storage volume is full.'
) )
@ -131,11 +130,19 @@ class singleCleaner(StoppableThread):
' is full. Bitmessage will now exit.'), ' is full. Bitmessage will now exit.'),
True) True)
)) ))
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
if shared.daemon or not state.enableGUI:
os._exit(1) os._exit(1)
# # clear download queues
# for thread in threading.enumerate():
# if thread.isAlive() and hasattr(thread, 'downloadQueue'):
# thread.downloadQueue.clear()
# inv/object tracking # inv/object tracking
for connection in BMConnectionPool().connections(): for connection in \
BMConnectionPool().inboundConnections.values() + \
BMConnectionPool().outboundConnections.values():
connection.clean() connection.clean()
# discovery tracking # discovery tracking
@ -146,16 +153,16 @@ class singleCleaner(StoppableThread):
del state.discoveredPeers[k] del state.discoveredPeers[k]
except KeyError: except KeyError:
pass pass
# ..todo:: cleanup pending upload / download # TODO: cleanup pending upload / download
gc.collect() gc.collect()
if state.shutdown == 0: if state.shutdown == 0:
self.stop.wait(singleCleaner.cycleLength) self.stop.wait(singleCleaner.cycleLength)
def resendPubkeyRequest(self, address):
"""Resend pubkey request for address""" def resendPubkeyRequest(address):
self.logger.debug( logger.debug(
'It has been a long time and we haven\'t heard a response to our' 'It has been a long time and we haven\'t heard a response to our'
' getpubkey request. Sending again.' ' getpubkey request. Sending again.'
) )
@ -177,9 +184,9 @@ class singleCleaner(StoppableThread):
address) address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
def resendMsg(self, ackdata):
"""Resend message by ackdata""" def resendMsg(ackdata):
self.logger.debug( logger.debug(
'It has been a long time and we haven\'t heard an acknowledgement' 'It has been a long time and we haven\'t heard an acknowledgement'
' to our msg. Sending again.' ' to our msg. Sending again.'
) )

View File

@ -1,8 +1,8 @@
""" """
Thread for performing PoW src/class_singleWorker.py
=========================
""" """
# pylint: disable=protected-access,too-many-branches,too-many-statements # pylint: disable=protected-access,too-many-branches,too-many-statements,no-self-use,too-many-lines,too-many-locals
# pylint: disable=no-self-use,too-many-lines,too-many-locals
from __future__ import division from __future__ import division
@ -24,13 +24,12 @@ import queues
import shared import shared
import state import state
import tr import tr
from addresses import ( from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from helper_threading import StoppableThread
from inventory import Inventory from inventory import Inventory
from network import StoppableThread
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):
@ -99,7 +98,7 @@ class singleWorker(StoppableThread):
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''') '''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
for row in queryreturn: for row in queryreturn:
ackdata, = row ackdata, = row
self.logger.info('Watching for ackdata %s', hexlify(ackdata)) logger.info('Watching for ackdata %s', hexlify(ackdata))
shared.ackdataForWhichImWatching[ackdata] = 0 shared.ackdataForWhichImWatching[ackdata] = 0
# Fix legacy (headerless) watched ackdata to include header # Fix legacy (headerless) watched ackdata to include header
@ -174,14 +173,14 @@ class singleWorker(StoppableThread):
self.busy = 0 self.busy = 0
return return
else: else:
self.logger.error( logger.error(
'Probable programming error: The command sent' 'Probable programming error: The command sent'
' to the workerThread is weird. It is: %s\n', ' to the workerThread is weird. It is: %s\n',
command command
) )
queues.workerQueue.task_done() queues.workerQueue.task_done()
self.logger.info("Quitting...") logger.info("Quitting...")
def _getKeysForAddress(self, address): def _getKeysForAddress(self, address):
privSigningKeyBase58 = BMConfigParser().get( privSigningKeyBase58 = BMConfigParser().get(
@ -218,34 +217,33 @@ class singleWorker(StoppableThread):
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
initialHash = hashlib.sha512(payload).digest() initialHash = hashlib.sha512(payload).digest()
self.logger.info( logger.info(
'%s Doing proof of work... TTL set to %s', log_prefix, TTL) '%s Doing proof of work... TTL set to %s', log_prefix, TTL)
if log_time: if log_time:
start_time = time.time() start_time = time.time()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
self.logger.info( logger.info(
'%s Found proof of work %s Nonce: %s', '%s Found proof of work %s Nonce: %s',
log_prefix, trialValue, nonce log_prefix, trialValue, nonce
) )
try: try:
delta = time.time() - start_time delta = time.time() - start_time
self.logger.info( logger.info(
'PoW took %.1f seconds, speed %s.', 'PoW took %.1f seconds, speed %s.',
delta, sizeof_fmt(nonce / delta) delta, sizeof_fmt(nonce / delta)
) )
except: # NameError except: # NameError
pass pass
payload = pack('>Q', nonce) + payload payload = pack('>Q', nonce) + payload
# inventoryHash = calculateInventoryHash(payload)
return payload return payload
def doPOWForMyV2Pubkey(self, adressHash): def doPOWForMyV2Pubkey(self, adressHash):
""" This function also broadcasts out the pubkey """ This function also broadcasts out the pubkey message once it is done with the POW"""
message once it is done with the POW"""
# Look up my stream number based on my address hash # Look up my stream number based on my address hash
myAddress = shared.myAddressesByHash[adressHash] myAddress = shared.myAddressesByHash[adressHash]
# status # status
_, addressVersionNumber, streamNumber, adressHash = ( _, addressVersionNumber, streamNumber, adressHash = decodeAddress(myAddress)
decodeAddress(myAddress))
# 28 days from now plus or minus five minutes # 28 days from now plus or minus five minutes
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300)) TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
@ -262,7 +260,7 @@ class singleWorker(StoppableThread):
_, _, pubSigningKey, pubEncryptionKey = \ _, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within doPOWForMyV2Pubkey. Could not read' 'Error within doPOWForMyV2Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -280,8 +278,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -306,7 +303,7 @@ class singleWorker(StoppableThread):
# The address has been deleted. # The address has been deleted.
return return
if BMConfigParser().safeGetBoolean(myAddress, 'chan'): if BMConfigParser().safeGetBoolean(myAddress, 'chan'):
self.logger.info('This is a chan address. Not sending pubkey.') logger.info('This is a chan address. Not sending pubkey.')
return return
_, addressVersionNumber, streamNumber, adressHash = decodeAddress( _, addressVersionNumber, streamNumber, adressHash = decodeAddress(
myAddress) myAddress)
@ -336,7 +333,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \ privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within sendOutOrStoreMyV3Pubkey. Could not read' 'Error within sendOutOrStoreMyV3Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -363,8 +360,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -387,7 +383,7 @@ class singleWorker(StoppableThread):
# The address has been deleted. # The address has been deleted.
return return
if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'): if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'):
self.logger.info('This is a chan address. Not sending pubkey.') logger.info('This is a chan address. Not sending pubkey.')
return return
_, addressVersionNumber, streamNumber, addressHash = decodeAddress( _, addressVersionNumber, streamNumber, addressHash = decodeAddress(
myAddress) myAddress)
@ -406,7 +402,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \ privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within sendOutOrStoreMyV4Pubkey. Could not read' 'Error within sendOutOrStoreMyV4Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -454,8 +450,7 @@ class singleWorker(StoppableThread):
doubleHashOfAddressData[32:] doubleHashOfAddressData[32:]
) )
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -464,7 +459,7 @@ class singleWorker(StoppableThread):
myAddress, 'lastpubkeysendtime', str(int(time.time()))) myAddress, 'lastpubkeysendtime', str(int(time.time())))
BMConfigParser().save() BMConfigParser().save()
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error: Couldn\'t add the lastpubkeysendtime' 'Error: Couldn\'t add the lastpubkeysendtime'
' to the keys.dat file. Error message: %s', err ' to the keys.dat file. Error message: %s', err
) )
@ -502,7 +497,7 @@ class singleWorker(StoppableThread):
objectType, streamNumber, buffer(payload), objectType, streamNumber, buffer(payload),
embeddedTime, buffer(tag) embeddedTime, buffer(tag)
) )
self.logger.info( logger.info(
'sending inv (within sendOnionPeerObj function) for object: %s', 'sending inv (within sendOnionPeerObj function) for object: %s',
hexlify(inventoryHash)) hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
@ -525,7 +520,7 @@ class singleWorker(StoppableThread):
_, addressVersionNumber, streamNumber, ripe = \ _, addressVersionNumber, streamNumber, ripe = \
decodeAddress(fromaddress) decodeAddress(fromaddress)
if addressVersionNumber <= 1: if addressVersionNumber <= 1:
self.logger.error( logger.error(
'Error: In the singleWorker thread, the ' 'Error: In the singleWorker thread, the '
' sendBroadcast function doesn\'t understand' ' sendBroadcast function doesn\'t understand'
' the address version.\n') ' the address version.\n')
@ -641,7 +636,7 @@ class singleWorker(StoppableThread):
# to not let the user try to send a message this large # to not let the user try to send a message this large
# until we implement message continuation. # until we implement message continuation.
if len(payload) > 2 ** 18: # 256 KiB if len(payload) > 2 ** 18: # 256 KiB
self.logger.critical( logger.critical(
'This broadcast object is too large to send.' 'This broadcast object is too large to send.'
' This should never happen. Object size: %s', ' This should never happen. Object size: %s',
len(payload) len(payload)
@ -652,7 +647,7 @@ class singleWorker(StoppableThread):
objectType = 3 objectType = 3
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, tag) objectType, streamNumber, payload, embeddedTime, tag)
self.logger.info( logger.info(
'sending inv (within sendBroadcast function)' 'sending inv (within sendBroadcast function)'
' for object: %s', ' for object: %s',
hexlify(inventoryHash) hexlify(inventoryHash)
@ -872,8 +867,8 @@ class singleWorker(StoppableThread):
"MainWindow", "MainWindow",
"Looking up the receiver\'s public key")) "Looking up the receiver\'s public key"))
)) ))
self.logger.info('Sending a message.') logger.info('Sending a message.')
self.logger.debug( logger.debug(
'First 150 characters of message: %s', 'First 150 characters of message: %s',
repr(message[:150]) repr(message[:150])
) )
@ -917,7 +912,7 @@ class singleWorker(StoppableThread):
if not shared.BMConfigParser().safeGetBoolean( if not shared.BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile' 'bitmessagesettings', 'willinglysendtomobile'
): ):
self.logger.info( logger.info(
'The receiver is a mobile user but the' 'The receiver is a mobile user but the'
' sender (you) has not selected that you' ' sender (you) has not selected that you'
' are willing to send to mobiles. Aborting' ' are willing to send to mobiles. Aborting'
@ -983,7 +978,7 @@ class singleWorker(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes: defaults.networkDefaultPayloadLengthExtraBytes:
requiredPayloadLengthExtraBytes = \ requiredPayloadLengthExtraBytes = \
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
self.logger.debug( logger.debug(
'Using averageProofOfWorkNonceTrialsPerByte: %s' 'Using averageProofOfWorkNonceTrialsPerByte: %s'
' and payloadLengthExtraBytes: %s.', ' and payloadLengthExtraBytes: %s.',
requiredAverageProofOfWorkNonceTrialsPerByte, requiredAverageProofOfWorkNonceTrialsPerByte,
@ -1048,9 +1043,8 @@ class singleWorker(StoppableThread):
l10n.formatTimestamp())))) l10n.formatTimestamp()))))
continue continue
else: # if we are sending a message to ourselves or a chan.. else: # if we are sending a message to ourselves or a chan..
self.logger.info('Sending a message.') logger.info('Sending a message.')
self.logger.debug( logger.debug('First 150 characters of message: %r', message[:150])
'First 150 characters of message: %r', message[:150])
behaviorBitfield = protocol.getBitfield(fromaddress) behaviorBitfield = protocol.getBitfield(fromaddress)
try: try:
@ -1069,7 +1063,7 @@ class singleWorker(StoppableThread):
" message. %1" " message. %1"
).arg(l10n.formatTimestamp())) ).arg(l10n.formatTimestamp()))
)) ))
self.logger.error( logger.error(
'Error within sendMsg. Could not read the keys' 'Error within sendMsg. Could not read the keys'
' from the keys.dat file for our own address. %s\n', ' from the keys.dat file for our own address. %s\n',
err) err)
@ -1145,14 +1139,14 @@ class singleWorker(StoppableThread):
payload += encodeVarint(encodedMessage.length) payload += encodeVarint(encodedMessage.length)
payload += encodedMessage.data payload += encodedMessage.data
if BMConfigParser().has_section(toaddress): if BMConfigParser().has_section(toaddress):
self.logger.info( logger.info(
'Not bothering to include ackdata because we are' 'Not bothering to include ackdata because we are'
' sending to ourselves or a chan.' ' sending to ourselves or a chan.'
) )
fullAckPayload = '' fullAckPayload = ''
elif not protocol.checkBitfield( elif not protocol.checkBitfield(
behaviorBitfield, protocol.BITFIELD_DOESACK): behaviorBitfield, protocol.BITFIELD_DOESACK):
self.logger.info( logger.info(
'Not bothering to include ackdata because' 'Not bothering to include ackdata because'
' the receiver said that they won\'t relay it anyway.' ' the receiver said that they won\'t relay it anyway.'
) )
@ -1205,7 +1199,7 @@ class singleWorker(StoppableThread):
requiredPayloadLengthExtraBytes requiredPayloadLengthExtraBytes
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
self.logger.info( logger.info(
'(For msg message) Doing proof of work. Total required' '(For msg message) Doing proof of work. Total required'
' difficulty: %f. Required small message difficulty: %f.', ' difficulty: %f. Required small message difficulty: %f.',
float(requiredAverageProofOfWorkNonceTrialsPerByte) / float(requiredAverageProofOfWorkNonceTrialsPerByte) /
@ -1217,12 +1211,12 @@ class singleWorker(StoppableThread):
powStartTime = time.time() powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest() initialHash = hashlib.sha512(encryptedPayload).digest()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
self.logger.info( logger.info(
'(For msg message) Found proof of work %s Nonce: %s', '(For msg message) Found proof of work %s Nonce: %s',
trialValue, nonce trialValue, nonce
) )
try: try:
self.logger.info( logger.info(
'PoW took %.1f seconds, speed %s.', 'PoW took %.1f seconds, speed %s.',
time.time() - powStartTime, time.time() - powStartTime,
sizeof_fmt(nonce / (time.time() - powStartTime)) sizeof_fmt(nonce / (time.time() - powStartTime))
@ -1237,7 +1231,7 @@ class singleWorker(StoppableThread):
# in the code to not let the user try to send a message # in the code to not let the user try to send a message
# this large until we implement message continuation. # this large until we implement message continuation.
if len(encryptedPayload) > 2 ** 18: # 256 KiB if len(encryptedPayload) > 2 ** 18: # 256 KiB
self.logger.critical( logger.critical(
'This msg object is too large to send. This should' 'This msg object is too large to send. This should'
' never happen. Object size: %i', ' never happen. Object size: %i',
len(encryptedPayload) len(encryptedPayload)
@ -1268,7 +1262,7 @@ class singleWorker(StoppableThread):
" Sent on %1" " Sent on %1"
).arg(l10n.formatTimestamp())) ).arg(l10n.formatTimestamp()))
)) ))
self.logger.info( logger.info(
'Broadcasting inv for my msg(within sendmsg function): %s', 'Broadcasting inv for my msg(within sendmsg function): %s',
hexlify(inventoryHash) hexlify(inventoryHash)
) )
@ -1321,7 +1315,7 @@ class singleWorker(StoppableThread):
toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress( toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if toStatus != 'success': if toStatus != 'success':
self.logger.error( logger.error(
'Very abnormal error occurred in requestPubKey.' 'Very abnormal error occurred in requestPubKey.'
' toAddress is: %r. Please report this error to Atheros.', ' toAddress is: %r. Please report this error to Atheros.',
toAddress toAddress
@ -1335,7 +1329,7 @@ class singleWorker(StoppableThread):
toAddress toAddress
) )
if not queryReturn: if not queryReturn:
self.logger.critical( logger.critical(
'BUG: Why are we requesting the pubkey for %s' 'BUG: Why are we requesting the pubkey for %s'
' if there are no messages in the sent folder' ' if there are no messages in the sent folder'
' to that address?', toAddress ' to that address?', toAddress
@ -1383,11 +1377,11 @@ class singleWorker(StoppableThread):
payload += encodeVarint(streamNumber) payload += encodeVarint(streamNumber)
if addressVersionNumber <= 3: if addressVersionNumber <= 3:
payload += ripe payload += ripe
self.logger.info( logger.info(
'making request for pubkey with ripe: %s', hexlify(ripe)) 'making request for pubkey with ripe: %s', hexlify(ripe))
else: else:
payload += tag payload += tag
self.logger.info( logger.info(
'making request for v4 pubkey with tag: %s', hexlify(tag)) 'making request for v4 pubkey with tag: %s', hexlify(tag))
# print 'trial value', trialValue # print 'trial value', trialValue
@ -1408,7 +1402,7 @@ class singleWorker(StoppableThread):
objectType = 1 objectType = 1
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info('sending inv (for the getpubkey message)') logger.info('sending inv (for the getpubkey message)')
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
# wait 10% past expiration # wait 10% past expiration

View File

@ -1,9 +1,11 @@
""" """
SMTP client thread for delivering emails src/class_smtpDeliver.py
========================
""" """
# pylint: disable=unused-variable # pylint: disable=unused-variable
import smtplib import smtplib
import sys
import urlparse import urlparse
from email.header import Header from email.header import Header
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -11,7 +13,8 @@ from email.mime.text import MIMEText
import queues import queues
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from network.threads import StoppableThread from debug import logger
from helper_threading import StoppableThread
SMTPDOMAIN = "bmaddr.lan" SMTPDOMAIN = "bmaddr.lan"
@ -22,9 +25,8 @@ class smtpDeliver(StoppableThread):
_instance = None _instance = None
def stopThread(self): def stopThread(self):
# pylint: disable=no-member
try: try:
queues.UISignallerQueue.put(("stopThread", "data")) queues.UISignallerQueue.put(("stopThread", "data")) # pylint: disable=no-member
except: except:
pass pass
super(smtpDeliver, self).stopThread() super(smtpDeliver, self).stopThread()
@ -38,7 +40,6 @@ class smtpDeliver(StoppableThread):
def run(self): def run(self):
# pylint: disable=too-many-branches,too-many-statements,too-many-locals # pylint: disable=too-many-branches,too-many-statements,too-many-locals
# pylint: disable=deprecated-lambda
while state.shutdown == 0: while state.shutdown == 0:
command, data = queues.UISignalQueue.get() command, data = queues.UISignalQueue.get()
if command == 'writeNewAddressToTable': if command == 'writeNewAddressToTable':
@ -61,9 +62,9 @@ class smtpDeliver(StoppableThread):
msg = MIMEText(body, 'plain', 'utf-8') msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8') msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress + '@' + SMTPDOMAIN msg['From'] = fromAddress + '@' + SMTPDOMAIN
toLabel = map( toLabel = map( # pylint: disable=deprecated-lambda
lambda y: BMConfigParser().safeGet(y, "label"), lambda y: BMConfigParser().safeGet(y, "label"),
filter( filter( # pylint: disable=deprecated-lambda
lambda x: x == toAddress, BMConfigParser().addresses()) lambda x: x == toAddress, BMConfigParser().addresses())
) )
if toLabel: if toLabel:
@ -74,12 +75,10 @@ class smtpDeliver(StoppableThread):
client.starttls() client.starttls()
client.ehlo() client.ehlo()
client.sendmail(msg['From'], [to], msg.as_string()) client.sendmail(msg['From'], [to], msg.as_string())
self.logger.info( logger.info("Delivered via SMTP to %s through %s:%i ...", to, u.hostname, u.port)
'Delivered via SMTP to %s through %s:%i ...',
to, u.hostname, u.port)
client.quit() client.quit()
except: except:
self.logger.error('smtp delivery error', exc_info=True) logger.error("smtp delivery error", exc_info=True)
elif command == 'displayNewSentMessage': elif command == 'displayNewSentMessage':
toAddress, fromLabel, fromAddress, subject, message, ackdata = data toAddress, fromLabel, fromAddress, subject, message, ackdata = data
elif command == 'updateNetworkStatusTab': elif command == 'updateNetworkStatusTab':
@ -113,5 +112,5 @@ class smtpDeliver(StoppableThread):
elif command == 'stopThread': elif command == 'stopThread':
break break
else: else:
self.logger.warning( sys.stderr.write(
'Command sent to smtpDeliver not recognized: %s', command) 'Command sent to smtpDeliver not recognized: %s\n' % command)

View File

@ -1,37 +1,28 @@
"""
SMTP server thread
"""
import asyncore import asyncore
import base64 import base64
import email import email
import logging from email.parser import Parser
from email.header import decode_header
import re import re
import signal import signal
import smtpd import smtpd
import threading import threading
import time import time
from email.header import decode_header
from email.parser import Parser
import queues
from addresses import decodeAddress from addresses import decodeAddress
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload from debug import logger
from helper_sql import sqlExecute from helper_sql import sqlExecute
from network.threads import StoppableThread from helper_ackPayload import genAckPayload
from helper_threading import StoppableThread
import queues
from version import softwareVersion from version import softwareVersion
SMTPDOMAIN = "bmaddr.lan" SMTPDOMAIN = "bmaddr.lan"
LISTENPORT = 8425 LISTENPORT = 8425
logger = logging.getLogger('default')
# pylint: disable=attribute-defined-outside-init
class smtpServerChannel(smtpd.SMTPChannel): class smtpServerChannel(smtpd.SMTPChannel):
"""Asyncore channel for SMTP protocol (server)"""
def smtp_EHLO(self, arg): def smtp_EHLO(self, arg):
"""Process an EHLO"""
if not arg: if not arg:
self.push('501 Syntax: HELO hostname') self.push('501 Syntax: HELO hostname')
return return
@ -39,17 +30,15 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('250 AUTH PLAIN') self.push('250 AUTH PLAIN')
def smtp_AUTH(self, arg): def smtp_AUTH(self, arg):
"""Process AUTH"""
if not arg or arg[0:5] not in ["PLAIN"]: if not arg or arg[0:5] not in ["PLAIN"]:
self.push('501 Syntax: AUTH PLAIN') self.push('501 Syntax: AUTH PLAIN')
return return
authstring = arg[6:] authstring = arg[6:]
try: try:
decoded = base64.b64decode(authstring) decoded = base64.b64decode(authstring)
correctauth = "\x00" + BMConfigParser().safeGet( correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \
"bitmessagesettings", "smtpdusername", "") + "\x00" + BMConfigParser().safeGet( "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "")
"bitmessagesettings", "smtpdpassword", "") logger.debug("authstring: %s / %s", correctauth, decoded)
logger.debug('authstring: %s / %s', correctauth, decoded)
if correctauth == decoded: if correctauth == decoded:
self.auth = True self.auth = True
self.push('235 2.7.0 Authentication successful') self.push('235 2.7.0 Authentication successful')
@ -59,17 +48,14 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('501 Authentication fail') self.push('501 Authentication fail')
def smtp_DATA(self, arg): def smtp_DATA(self, arg):
"""Process DATA"""
if not hasattr(self, "auth") or not self.auth: if not hasattr(self, "auth") or not self.auth:
self.push('530 Authentication required') self.push ("530 Authentication required")
return return
smtpd.SMTPChannel.smtp_DATA(self, arg) smtpd.SMTPChannel.smtp_DATA(self, arg)
class smtpServerPyBitmessage(smtpd.SMTPServer): class smtpServerPyBitmessage(smtpd.SMTPServer):
"""Asyncore SMTP server class"""
def handle_accept(self): def handle_accept(self):
"""Accept a connection"""
pair = self.accept() pair = self.accept()
if pair is not None: if pair is not None:
conn, addr = pair conn, addr = pair
@ -77,9 +63,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
self.channel = smtpServerChannel(self, conn, addr) self.channel = smtpServerChannel(self, conn, addr)
def send(self, fromAddress, toAddress, subject, message): def send(self, fromAddress, toAddress, subject, message):
"""Send a bitmessage""" status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
# pylint: disable=arguments-differ
streamNumber, ripe = decodeAddress(toAddress)[2:]
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute( sqlExecute(
@ -98,14 +82,12 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
0, # retryNumber 0, # retryNumber
'sent', # folder 'sent', # folder
2, # encodingtype 2, # encodingtype
# not necessary to have a TTL higher than 2 days min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2) # not necessary to have a TTL higher than 2 days
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2)
) )
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
def decode_header(self, hdr): def decode_header(self, hdr):
"""Email header decoding"""
ret = [] ret = []
for h in decode_header(self.msg_headers[hdr]): for h in decode_header(self.msg_headers[hdr]):
if h[1]: if h[1]:
@ -115,38 +97,37 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
return ret return ret
def process_message(self, peer, mailfrom, rcpttos, data): def process_message(self, peer, mailfrom, rcpttos, data):
"""Process an email""" # print 'Receiving message from:', peer
# pylint: disable=too-many-locals, too-many-branches
# print 'Receiving message from:', peer
p = re.compile(".*<([^>]+)>") p = re.compile(".*<([^>]+)>")
if not hasattr(self.channel, "auth") or not self.channel.auth: if not hasattr(self.channel, "auth") or not self.channel.auth:
logger.error('Missing or invalid auth') logger.error("Missing or invalid auth")
return return
try: try:
self.msg_headers = Parser().parsestr(data) self.msg_headers = Parser().parsestr(data)
except: except:
logger.error('Invalid headers') logger.error("Invalid headers")
return return
try: try:
sender, domain = p.sub(r'\1', mailfrom).split("@") sender, domain = p.sub(r'\1', mailfrom).split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses(): if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender) raise Exception("Nonexisting user %s", sender)
except Exception as err: except Exception as err:
logger.debug('Bad envelope from %s: %r', mailfrom, err) logger.debug("Bad envelope from %s: %s", mailfrom, repr(err))
msg_from = self.decode_header("from") msg_from = self.decode_header("from")
try: try:
msg_from = p.sub(r'\1', self.decode_header("from")[0]) msg_from = p.sub(r'\1', self.decode_header("from")[0])
sender, domain = msg_from.split("@") sender, domain = msg_from.split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses(): if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender) raise Exception("Nonexisting user %s", sender)
except Exception as err: except Exception as err:
logger.error('Bad headers from %s: %r', msg_from, err) logger.error("Bad headers from %s: %s", msg_from, repr(err))
return return
try: try:
@ -164,20 +145,18 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
try: try:
rcpt, domain = p.sub(r'\1', to).split("@") rcpt, domain = p.sub(r'\1', to).split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
logger.debug( logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
'Sending %s to %s about %s', sender, rcpt, msg_subject)
self.send(sender, rcpt, msg_subject, body) self.send(sender, rcpt, msg_subject, body)
logger.info('Relayed %s to %s', sender, rcpt) logger.info("Relayed %s to %s", sender, rcpt)
except Exception as err: except Exception as err:
logger.error('Bad to %s: %r', to, err) logger.error( "Bad to %s: %s", to, repr(err))
continue continue
return return
class smtpServer(StoppableThread): class smtpServer(StoppableThread):
"""SMTP server thread""" def __init__(self, parent=None):
def __init__(self, _=None):
super(smtpServer, self).__init__(name="smtpServerThread") super(smtpServer, self).__init__(name="smtpServerThread")
self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None) self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None)
@ -189,26 +168,21 @@ class smtpServer(StoppableThread):
def run(self): def run(self):
asyncore.loop(1) asyncore.loop(1)
def signals(signal, frame):
def signals(_, __): print "Got signal, terminating"
"""Signal handler"""
logger.warning('Got signal, terminating')
for thread in threading.enumerate(): for thread in threading.enumerate():
if thread.isAlive() and isinstance(thread, StoppableThread): if thread.isAlive() and isinstance(thread, StoppableThread):
thread.stopThread() thread.stopThread()
def runServer(): def runServer():
"""Run SMTP server as a standalone python process""" print "Running SMTPd thread"
logger.warning('Running SMTPd thread')
smtpThread = smtpServer() smtpThread = smtpServer()
smtpThread.start() smtpThread.start()
signal.signal(signal.SIGINT, signals) signal.signal(signal.SIGINT, signals)
signal.signal(signal.SIGTERM, signals) signal.signal(signal.SIGTERM, signals)
logger.warning('Processing') print "Processing"
smtpThread.join() smtpThread.join()
logger.warning('The end') print "The end"
if __name__ == "__main__": if __name__ == "__main__":
runServer() runServer()

View File

@ -1,33 +1,29 @@
"""
sqlThread is defined here
"""
import os
import shutil # used for moving the messages.dat file
import sqlite3
import sys
import threading import threading
from bmconfigparser import BMConfigParser
import sqlite3
import time import time
import shutil # used for moving the messages.dat file
import sys
import os
from debug import logger
import helper_sql import helper_sql
import helper_startup import helper_startup
import paths import paths
import queues import queues
import state import state
import tr import tr
from bmconfigparser import BMConfigParser
from debug import logger # This thread exists because SQLITE3 is so un-threadsafe that we must
# pylint: disable=attribute-defined-outside-init,protected-access # submit queries to it and it puts results back in a different queue. They
# won't let us just use locks.
class sqlThread(threading.Thread): class sqlThread(threading.Thread):
"""A thread for all SQL operations"""
def __init__(self): def __init__(self):
threading.Thread.__init__(self, name="SQL") threading.Thread.__init__(self, name="SQL")
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements def run(self):
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
self.conn = sqlite3.connect(state.appdata + 'messages.dat') self.conn = sqlite3.connect(state.appdata + 'messages.dat')
self.conn.text_factory = str self.conn.text_factory = str
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
@ -36,38 +32,30 @@ class sqlThread(threading.Thread):
try: try:
self.cur.execute( self.cur.execute(
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,''' '''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text, received text, message text, folder text, encodingtype int, read bool, sighash blob, UNIQUE(msgid) ON CONFLICT REPLACE)''' )
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,''' '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' )
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''') '''CREATE TABLE subscriptions (label text, address text, enabled bool)''' )
self.cur.execute( self.cur.execute(
'''CREATE TABLE addressbook (label text, address text)''') '''CREATE TABLE addressbook (label text, address text)''' )
self.cur.execute( self.cur.execute(
'''CREATE TABLE blacklist (label text, address text, enabled bool)''') '''CREATE TABLE blacklist (label text, address text, enabled bool)''' )
self.cur.execute( self.cur.execute(
'''CREATE TABLE whitelist (label text, address text, enabled bool)''') '''CREATE TABLE whitelist (label text, address text, enabled bool)''' )
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,''' '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,''' '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES''' '''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''') '''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' )
self.cur.execute('''INSERT INTO settings VALUES('version','10')''') self.cur.execute( '''INSERT INTO settings VALUES('version','10')''')
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue''' '''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' )
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
self.conn.commit() self.conn.commit()
logger.info('Created messages database file') logger.info('Created messages database file')
except Exception as err: except Exception as err:
@ -132,38 +120,33 @@ class sqlThread(threading.Thread):
logger.debug( logger.debug(
"In messages.dat database, creating new 'settings' table.") "In messages.dat database, creating new 'settings' table.")
self.cur.execute( self.cur.execute(
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''') '''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' )
self.cur.execute('''INSERT INTO settings VALUES('version','1')''') self.cur.execute( '''INSERT INTO settings VALUES('version','1')''')
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.') logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,''' '''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''') '''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute('''DROP TABLE pubkeys''') self.cur.execute( '''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys''' '''CREATE TABLE pubkeys (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''') '''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute('''DROP TABLE pubkeys_backup;''') self.cur.execute( '''DROP TABLE pubkeys_backup;''')
logger.debug( logger.debug('Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.')
'Deleting all pubkeys from inventory.'
' They will be redownloaded and then saved with the correct times.')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
logger.debug('replacing Bitmessage announcements mailing list with a new one.') logger.debug('replacing Bitmessage announcements mailing list with a new one.')
self.cur.execute( self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''') '''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES''' '''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
logger.debug('Commiting.') logger.debug('Commiting.')
self.conn.commit() self.conn.commit()
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.') logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
self.cur.execute(''' VACUUM ''') self.cur.execute( ''' VACUUM ''')
# After code refactoring, the possible status values for sent messages # After code refactoring, the possible status values for sent messages
# have changed. # have changed.
@ -187,21 +170,15 @@ class sqlThread(threading.Thread):
'In messages.dat database, removing an obsolete field from' 'In messages.dat database, removing an obsolete field from'
' the inventory table.') ' the inventory table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE inventory_backup''' '''CREATE TEMPORARY TABLE inventory_backup(hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
'''(hash blob, objecttype text, streamnumber int, payload blob,'''
''' receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime''' '''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;''')
''' FROM inventory;''') self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute('''DROP TABLE inventory''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory''' '''CREATE TABLE inventory (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer,'''
''' UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime''' '''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;''')
''' FROM inventory_backup;''') self.cur.execute( '''DROP TABLE inventory_backup;''')
self.cur.execute('''DROP TABLE inventory_backup;''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (3,) parameters = (3,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -231,8 +208,7 @@ class sqlThread(threading.Thread):
if currentVersion == 4: if currentVersion == 4:
self.cur.execute('''DROP TABLE pubkeys''') self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int,''' '''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
'''usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
@ -248,8 +224,7 @@ class sqlThread(threading.Thread):
if currentVersion == 5: if currentVersion == 5:
self.cur.execute('''DROP TABLE knownnodes''') self.cur.execute('''DROP TABLE knownnodes''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue''' '''CREATE TABLE objectprocessorqueue (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
''' (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (6,) parameters = (6,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -265,15 +240,10 @@ class sqlThread(threading.Thread):
logger.debug( logger.debug(
'In messages.dat database, dropping and recreating' 'In messages.dat database, dropping and recreating'
' the inventory table.') ' the inventory table.')
self.cur.execute('''DROP TABLE inventory''') self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute( self.cur.execute( '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' )
'''CREATE TABLE inventory''' self.cur.execute( '''DROP TABLE objectprocessorqueue''')
''' (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer,''' self.cur.execute( '''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' )
''' tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute('''DROP TABLE objectprocessorqueue''')
self.cur.execute(
'''CREATE TABLE objectprocessorqueue'''
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (7,) parameters = (7,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -335,24 +305,15 @@ class sqlThread(threading.Thread):
' fields into the retrynumber field and adding the' ' fields into the retrynumber field and adding the'
' sleeptill and ttl fields...') ' sleeptill and ttl fields...')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE sent_backup''' '''CREATE TEMPORARY TABLE sent_backup (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, lastactiontime integer, status text, retrynumber integer, folder text, encodingtype int)''' )
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, lastactiontime integer, status text, retrynumber integer,'''
''' folder text, encodingtype int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress,''' '''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;''')
''' subject, message, ackdata, lastactiontime,''' self.cur.execute( '''DROP TABLE sent''')
''' status, 0, folder, encodingtype FROM sent;''')
self.cur.execute('''DROP TABLE sent''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent''' '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' )
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text,'''
''' retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata,''' '''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
''' lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''') self.cur.execute( '''DROP TABLE sent_backup''')
self.cur.execute('''DROP TABLE sent_backup''')
logger.info('In messages.dat database, finished making TTL-related changes.') logger.info('In messages.dat database, finished making TTL-related changes.')
logger.debug('In messages.dat database, adding address field to the pubkeys table.') logger.debug('In messages.dat database, adding address field to the pubkeys table.')
# We're going to have to calculate the address for each row in the pubkeys # We're going to have to calculate the address for each row in the pubkeys
@ -369,24 +330,16 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
# Now we can remove the hash field from the pubkeys table. # Now we can remove the hash field from the pubkeys table.
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup''' '''CREATE TEMPORARY TABLE pubkeys_backup (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup''' '''INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
''' SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''') self.cur.execute( '''DROP TABLE pubkeys''')
self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys''' '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' (address text, addressversion int, transmitdata blob, time int, usedpersonally text,'''
''' UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT''' '''INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
''' address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''') self.cur.execute( '''DROP TABLE pubkeys_backup''')
self.cur.execute('''DROP TABLE pubkeys_backup''') logger.debug('In messages.dat database, done adding address field to the pubkeys table and removing the hash field.')
logger.debug(
'In messages.dat database, done adding address field to the pubkeys table'
' and removing the hash field.')
self.cur.execute('''update settings set value=10 WHERE key='version';''') self.cur.execute('''update settings set value=10 WHERE key='version';''')
# Are you hoping to add a new option to the keys.dat file of existing # Are you hoping to add a new option to the keys.dat file of existing
@ -396,7 +349,7 @@ class sqlThread(threading.Thread):
try: try:
testpayload = '\x00\x00' testpayload = '\x00\x00'
t = ('1234', 1, testpayload, '12345678', 'no') t = ('1234', 1, testpayload, '12345678', 'no')
self.cur.execute('''INSERT INTO pubkeys VALUES(?,?,?,?,?)''', t) self.cur.execute( '''INSERT INTO pubkeys VALUES(?,?,?,?,?)''', t)
self.conn.commit() self.conn.commit()
self.cur.execute( self.cur.execute(
'''SELECT transmitdata FROM pubkeys WHERE address='1234' ''') '''SELECT transmitdata FROM pubkeys WHERE address='1234' ''')
@ -406,29 +359,13 @@ class sqlThread(threading.Thread):
self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''') self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''')
self.conn.commit() self.conn.commit()
if transmitdata == '': if transmitdata == '':
logger.fatal( logger.fatal('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n')
'Problem: The version of SQLite you have cannot store Null values.' logger.fatal('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n')
' Please download and install the latest revision of your version of Python'
' (for example, the latest Python 2.7 revision) and try again.\n')
logger.fatal(
'PyBitmessage will now exit very abruptly.'
' You may now see threading errors related to this abrupt exit'
' but the problem you need to solve is related to SQLite.\n\n')
os._exit(0) os._exit(0)
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While null value test) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While null value test) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.error(err) logger.error(err)
@ -444,21 +381,11 @@ class sqlThread(threading.Thread):
if int(value) < int(time.time()) - 86400: if int(value) < int(time.time()) - 86400:
logger.info('It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...') logger.info('It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...')
try: try:
self.cur.execute(''' VACUUM ''') self.cur.execute( ''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While VACUUM) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While VACUUM) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
item = '''update settings set value=? WHERE key='lastvacuumtime';''' item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),) parameters = (int(time.time()),)
@ -473,18 +400,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While committing) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While committing) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
elif item == 'exit': elif item == 'exit':
self.conn.close() self.conn.close()
@ -498,18 +415,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while movemessagstoprog) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while movemessagstoprog) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -524,18 +431,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while movemessagstoappdata) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while movemessagstoappdata) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -548,21 +445,11 @@ class sqlThread(threading.Thread):
self.cur.execute('''delete from sent where folder='trash' ''') self.cur.execute('''delete from sent where folder='trash' ''')
self.conn.commit() self.conn.commit()
try: try:
self.cur.execute(''' VACUUM ''') self.cur.execute( ''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while deleteandvacuume) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while deleteandvacuume) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
parameters = helper_sql.sqlSubmitQueue.get() parameters = helper_sql.sqlSubmitQueue.get()
@ -574,30 +461,11 @@ class sqlThread(threading.Thread):
rowcount = self.cur.rowcount rowcount = self.cur.rowcount
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while cur.execute) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while cur.execute) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.fatal( logger.fatal('Major error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "%s" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: %s. Here is the actual error message thrown by the sqlThread: %s', str(item), str(repr(parameters)), str(err))
'Major error occurred when trying to execute a SQL statement within the sqlThread.'
' Please tell Atheros about this error message or post it in the forum!'
' Error occurred while trying to execute statement: "%s" Here are the parameters;'
' you might want to censor this data with asterisks (***)'
' as it can contain private information: %s.'
' Here is the actual error message thrown by the sqlThread: %s',
str(item),
str(repr(parameters)),
str(err))
logger.fatal('This program shall now abruptly exit!') logger.fatal('This program shall now abruptly exit!')
os._exit(0) os._exit(0)

View File

@ -1,6 +1,6 @@
""" """
Logging and debuging facility Logging and debuging facility
----------------------------- =============================
Levels: Levels:
@ -9,30 +9,18 @@ Levels:
INFO INFO
Confirmation that things are working as expected. Confirmation that things are working as expected.
WARNING WARNING
An indication that something unexpected happened, or indicative of An indication that something unexpected happened, or indicative of some problem in the
some problem in the near future (e.g. 'disk space low'). The software near future (e.g. 'disk space low'). The software is still working as expected.
is still working as expected.
ERROR ERROR
Due to a more serious problem, the software has not been able to Due to a more serious problem, the software has not been able to perform some function.
perform some function.
CRITICAL CRITICAL
A serious error, indicating that the program itself may be unable to A serious error, indicating that the program itself may be unable to continue running.
continue running.
There are three loggers by default: `console_only`, `file_only` and `both`. There are three loggers: `console_only`, `file_only` and `both`.
You can configure logging in the logging.dat in the appdata dir.
It's format is described in the :func:`logging.config.fileConfig` doc.
Use: Use: `from debug import logger` to import this facility into whatever module you wish to log messages from.
Logging is thread-safe so you don't have to worry about locks, just import and log.
>>> import logging
>>> logger = logging.getLogger('default')
The old form: ``from debug import logger`` is also may be used,
but only in the top level modules.
Logging is thread-safe so you don't have to worry about locks,
just import and log.
""" """
import ConfigParser import ConfigParser
@ -40,7 +28,6 @@ import logging
import logging.config import logging.config
import os import os
import sys import sys
import helper_startup import helper_startup
import state import state
@ -54,22 +41,14 @@ log_level = 'WARNING'
def log_uncaught_exceptions(ex_cls, ex, tb): def log_uncaught_exceptions(ex_cls, ex, tb):
"""The last resort logging function used for sys.excepthook"""
logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb)) logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb))
def configureLogging(): def configureLogging():
"""
Configure logging,
using either logging.dat file in the state.appdata dir
or dictionary with hardcoded settings.
"""
sys.excepthook = log_uncaught_exceptions
fail_msg = '' fail_msg = ''
try: try:
logging_config = os.path.join(state.appdata, 'logging.dat') logging_config = os.path.join(state.appdata, 'logging.dat')
logging.config.fileConfig( logging.config.fileConfig(logging_config)
logging_config, disable_existing_loggers=False)
return ( return (
False, False,
'Loaded logger configuration from %s' % logging_config 'Loaded logger configuration from %s' % logging_config
@ -81,11 +60,12 @@ def configureLogging():
' logging config\n%s' % \ ' logging config\n%s' % \
(logging_config, sys.exc_info()) (logging_config, sys.exc_info())
else: else:
# no need to confuse the user if the logger config # no need to confuse the user if the logger config is missing entirely
# is missing entirely
fail_msg = 'Using default logger configuration' fail_msg = 'Using default logger configuration'
logging_config = { sys.excepthook = log_uncaught_exceptions
logging.config.dictConfig({
'version': 1, 'version': 1,
'formatters': { 'formatters': {
'default': { 'default': {
@ -127,29 +107,34 @@ def configureLogging():
'level': log_level, 'level': log_level,
'handlers': ['console'], 'handlers': ['console'],
}, },
} })
logging_config['loggers']['default'] = logging_config['loggers'][
'file_only' if '-c' in sys.argv else 'both']
logging.config.dictConfig(logging_config)
return True, fail_msg return True, fail_msg
def initLogging():
preconfigured, msg = configureLogging()
if preconfigured:
if '-c' in sys.argv:
logger = logging.getLogger('file_only')
else:
logger = logging.getLogger('both')
else:
logger = logging.getLogger('default')
if msg:
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)
return logger
def resetLogging(): def resetLogging():
"""Reconfigure logging in runtime when state.appdata dir changed"""
# pylint: disable=global-statement, used-before-assignment
global logger global logger
for i in logger.handlers: for i in logger.handlers.iterkeys():
logger.removeHandler(i) logger.removeHandler(i)
i.flush() i.flush()
i.close() i.close()
configureLogging() logger = initLogging()
logger = logging.getLogger('default')
# ! # !
preconfigured, msg = configureLogging() logger = initLogging()
logger = logging.getLogger('default')
if msg:
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)

View File

@ -1,24 +1,24 @@
""" """
Common default values src/defaults.py
===============
""" """
#: sanity check, prevent doing ridiculous PoW # sanity check, prevent doing ridiculous PoW
#: 20 million PoWs equals approximately 2 days on dev's dual R9 290 # 20 million PoWs equals approximately 2 days on dev's dual R9 290
ridiculousDifficulty = 20000000 ridiculousDifficulty = 20000000
#: Remember here the RPC port read from namecoin.conf so we can restore to # Remember here the RPC port read from namecoin.conf so we can restore to
#: it as default whenever the user changes the "method" selection for # it as default whenever the user changes the "method" selection for
#: namecoin integration to "namecoind". # namecoin integration to "namecoind".
namecoinDefaultRpcPort = "8336" namecoinDefaultRpcPort = "8336"
# If changed, these values will cause particularly unexpected behavior: # If changed, these values will cause particularly unexpected behavior:
# You won't be able to either send or receive messages because the proof # You won't be able to either send or receive messages because the proof
# of work you do (or demand) won't match that done or demanded by others. # of work you do (or demand) won't match that done or demanded by others.
# Don't change them! # Don't change them!
#: The amount of work that should be performed (and demanded) per byte # The amount of work that should be performed (and demanded) per byte of the payload.
#: of the payload.
networkDefaultProofOfWorkNonceTrialsPerByte = 1000 networkDefaultProofOfWorkNonceTrialsPerByte = 1000
#: To make sending short messages a little more difficult, this value is # To make sending short messages a little more difficult, this value is
#: added to the payload length for use in calculating the proof of work # added to the payload length for use in calculating the proof of work
#: target. # target.
networkDefaultPayloadLengthExtraBytes = 1000 networkDefaultPayloadLengthExtraBytes = 1000

View File

@ -113,7 +113,6 @@ PACKAGES = {
def detectOS(): def detectOS():
"""Finding out what Operating System is running"""
if detectOS.result is not None: if detectOS.result is not None:
return detectOS.result return detectOS.result
if sys.platform.startswith('openbsd'): if sys.platform.startswith('openbsd'):
@ -133,7 +132,6 @@ detectOS.result = None
def detectOSRelease(): def detectOSRelease():
"""Detecting the release of OS"""
with open("/etc/os-release", 'r') as osRelease: with open("/etc/os-release", 'r') as osRelease:
version = None version = None
for line in osRelease: for line in osRelease:
@ -150,7 +148,6 @@ def detectOSRelease():
def try_import(module, log_extra=False): def try_import(module, log_extra=False):
"""Try to import the non imported packages"""
try: try:
return import_module(module) return import_module(module)
except ImportError: except ImportError:
@ -211,8 +208,10 @@ def check_sqlite():
).fetchone()[0] ).fetchone()[0]
logger.info('SQLite Library Source ID: %s', sqlite_source_id) logger.info('SQLite Library Source ID: %s', sqlite_source_id)
if sqlite_version_number >= 3006023: if sqlite_version_number >= 3006023:
compile_options = ', '.join( compile_options = ', '.join(map(
[row[0] for row in conn.execute('PRAGMA compile_options;')]) lambda row: row[0],
conn.execute('PRAGMA compile_options;')
))
logger.info( logger.info(
'SQLite Library Compile Options: %s', compile_options) 'SQLite Library Compile Options: %s', compile_options)
# There is no specific version requirement as yet, so we just # There is no specific version requirement as yet, so we just
@ -237,8 +236,7 @@ def check_openssl():
Here we are checking for openssl with its all dependent libraries Here we are checking for openssl with its all dependent libraries
and version checking. and version checking.
""" """
# pylint: disable=too-many-branches, too-many-return-statements
# pylint: disable=protected-access, redefined-outer-name
ctypes = try_import('ctypes') ctypes = try_import('ctypes')
if not ctypes: if not ctypes:
logger.error('Unable to check OpenSSL.') logger.error('Unable to check OpenSSL.')
@ -302,7 +300,7 @@ def check_openssl():
' ECDH, and ECDSA enabled.') ' ECDH, and ECDSA enabled.')
return False return False
matches = cflags_regex.findall(openssl_cflags) matches = cflags_regex.findall(openssl_cflags)
if matches: if len(matches) > 0:
logger.error( logger.error(
'This OpenSSL library is missing the following required' 'This OpenSSL library is missing the following required'
' features: %s. PyBitmessage requires OpenSSL 0.9.8b' ' features: %s. PyBitmessage requires OpenSSL 0.9.8b'
@ -313,13 +311,13 @@ def check_openssl():
return False return False
# ..todo:: The minimum versions of pythondialog and dialog need to be determined # TODO: The minimum versions of pythondialog and dialog need to be determined
def check_curses(): def check_curses():
"""Do curses dependency check. """Do curses dependency check.
Here we are checking for curses if available or not with check as interface Here we are checking for curses if available or not with check
requires the `pythondialog <https://pypi.org/project/pythondialog>`_ package as interface requires the pythondialog\ package and the dialog
and the dialog utility. utility.
""" """
if sys.hexversion < 0x20600F0: if sys.hexversion < 0x20600F0:
logger.error( logger.error(

View File

@ -1,19 +1,13 @@
""" """
Fallback expressions help PyBitmessage modules to run without some external .. todo:: hello world
dependencies.
RIPEMD160Hash
-------------
We need to check :mod:`hashlib` for RIPEMD-160, as it won't be available
if OpenSSL is not linked against or the linked OpenSSL has RIPEMD disabled.
Try to use `pycryptodome <https://pypi.org/project/pycryptodome/>`_
in that case.
""" """
import hashlib import hashlib
# We need to check hashlib for RIPEMD-160, as it won't be available
# if OpenSSL is not linked against or the linked OpenSSL has RIPEMD
# disabled.
try: try:
hashlib.new('ripemd160') hashlib.new('ripemd160')
except ValueError: except ValueError:

View File

@ -1,28 +1,22 @@
""" """This module is for generating ack payload."""
This module is for generating ack payload
"""
import highlevelcrypto
import helper_random
from binascii import hexlify from binascii import hexlify
from struct import pack from struct import pack
import helper_random
import highlevelcrypto
from addresses import encodeVarint from addresses import encodeVarint
# This function generates payload objects for message acknowledgements
# Several stealth levels are available depending on the privacy needs;
# a higher level means better stealth, but also higher cost (size+POW)
# - level 0: a random 32-byte sequence with a message header appended
# - level 1: a getpubkey request for a (random) dummy key hash
# - level 2: a standard message, encrypted to a random pubkey
def genAckPayload(streamNumber=1, stealthLevel=0): def genAckPayload(streamNumber=1, stealthLevel=0):
""" """Generate and return payload obj."""
Generate and return payload obj. if (stealthLevel == 2): # Generate privacy-enhanced payload
This function generates payload objects for message acknowledgements
Several stealth levels are available depending on the privacy needs;
a higher level means better stealth, but also higher cost (size+POW)
- level 0: a random 32-byte sequence with a message header appended
- level 1: a getpubkey request for a (random) dummy key hash
- level 2: a standard message, encrypted to a random pubkey
"""
if stealthLevel == 2: # Generate privacy-enhanced payload
# Generate a dummy privkey and derive the pubkey # Generate a dummy privkey and derive the pubkey
dummyPubKeyHex = highlevelcrypto.privToPub( dummyPubKeyHex = highlevelcrypto.privToPub(
hexlify(helper_random.randomBytes(32))) hexlify(helper_random.randomBytes(32)))
@ -35,7 +29,7 @@ def genAckPayload(streamNumber=1, stealthLevel=0):
acktype = 2 # message acktype = 2 # message
version = 1 version = 1
elif stealthLevel == 1: # Basic privacy payload (random getpubkey) elif (stealthLevel == 1): # Basic privacy payload (random getpubkey)
ackdata = helper_random.randomBytes(32) ackdata = helper_random.randomBytes(32)
acktype = 0 # getpubkey acktype = 0 # getpubkey
version = 4 version = 4

View File

@ -1,19 +1,10 @@
"""
Calculates bitcoin and testnet address from pubkey
"""
import hashlib import hashlib
from debug import logger
from pyelliptic import arithmetic from pyelliptic import arithmetic
# This function expects that pubkey begin with \x04
def calculateBitcoinAddressFromPubkey(pubkey): def calculateBitcoinAddressFromPubkey(pubkey):
"""Calculate bitcoin address from given pubkey (65 bytes long hex string)"""
if len(pubkey) != 65: if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because' print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')
@ -33,11 +24,8 @@ def calculateBitcoinAddressFromPubkey(pubkey):
def calculateTestnetAddressFromPubkey(pubkey): def calculateTestnetAddressFromPubkey(pubkey):
"""This function expects that pubkey begin with the testnet prefix"""
if len(pubkey) != 65: if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because' print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')

84
src/helper_bootstrap.py Normal file
View File

@ -0,0 +1,84 @@
import socket
import knownnodes
import socks
import state
from bmconfigparser import BMConfigParser
from debug import logger
def dns():
"""
DNS bootstrap. This could be programmed to use the SOCKS proxy to do the
DNS lookup some day but for now we will just rely on the entries in
defaultKnownNodes.py. Hopefully either they are up to date or the user
has run Bitmessage recently without SOCKS turned on and received good
bootstrap nodes using that method.
"""
def try_add_known_node(stream, addr, port, method=''):
try:
socket.inet_aton(addr)
except (TypeError, socket.error):
return
logger.info(
'Adding %s to knownNodes based on %s DNS bootstrap method',
addr, method)
knownnodes.addKnownNode(stream, state.Peer(addr, port))
proxy_type = BMConfigParser().get('bitmessagesettings', 'socksproxytype')
if proxy_type == 'none':
for port in [8080, 8444]:
try:
for item in socket.getaddrinfo(
'bootstrap%s.bitmessage.org' % port, 80):
try_add_known_node(1, item[4][0], port)
except:
logger.error(
'bootstrap%s.bitmessage.org DNS bootstrapping failed.',
port, exc_info=True
)
elif proxy_type == 'SOCKS5':
knownnodes.createDefaultKnownNodes(onion=True)
logger.debug('Adding default onion knownNodes.')
for port in [8080, 8444]:
logger.debug("Resolving %i through SOCKS...", port)
address_family = socket.AF_INET
sock = socks.socksocket(address_family, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(20)
proxytype = socks.PROXY_TYPE_SOCKS5
sockshostname = BMConfigParser().get(
'bitmessagesettings', 'sockshostname')
socksport = BMConfigParser().getint(
'bitmessagesettings', 'socksport')
# Do domain name lookups through the proxy;
# though this setting doesn't really matter since we won't
# be doing any domain name lookups anyway.
rdns = True
if BMConfigParser().getboolean(
'bitmessagesettings', 'socksauthentication'):
socksusername = BMConfigParser().get(
'bitmessagesettings', 'socksusername')
sockspassword = BMConfigParser().get(
'bitmessagesettings', 'sockspassword')
sock.setproxy(
proxytype, sockshostname, socksport, rdns,
socksusername, sockspassword)
else:
sock.setproxy(
proxytype, sockshostname, socksport, rdns)
try:
ip = sock.resolve("bootstrap" + str(port) + ".bitmessage.org")
sock.shutdown(socket.SHUT_RDWR)
sock.close()
except:
logger.error("SOCKS DNS resolving failed", exc_info=True)
else:
try_add_known_node(1, ip, port, 'SOCKS')
else:
logger.info(
'DNS bootstrap skipped because the proxy type does not support'
' DNS resolution.'
)

View File

@ -1,11 +1,10 @@
"""Helper Inbox performs inbox messages related operations""" """Helper Inbox performs inbox messagese related operations."""
import queues
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
import queues
def insert(t): def insert(t):
"""Perform an insert into the "inbox" table"""
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t)
# shouldn't emit changedInboxUnread and displayNewInboxMessage # shouldn't emit changedInboxUnread and displayNewInboxMessage
# at the same time # at the same time
@ -13,13 +12,11 @@ def insert(t):
def trash(msgid): def trash(msgid):
"""Mark a message in the `inbox` as `trash`"""
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)
queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid)) queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid))
def isMessageAlreadyInInbox(sigHash): def isMessageAlreadyInInbox(sigHash):
"""Check for previous instances of this message"""
queryReturn = sqlQuery( queryReturn = sqlQuery(
'''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash) '''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash)
return queryReturn[0][0] != 0 return queryReturn[0][0] != 0

View File

@ -5,11 +5,6 @@ Message encoding end decoding functions
import string import string
import zlib import zlib
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
try: try:
import msgpack import msgpack
except ImportError: except ImportError:
@ -18,6 +13,11 @@ except ImportError:
except ImportError: except ImportError:
import fallback.umsgpack.umsgpack as msgpack import fallback.umsgpack.umsgpack as msgpack
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
BITMESSAGE_ENCODING_IGNORE = 0 BITMESSAGE_ENCODING_IGNORE = 0
BITMESSAGE_ENCODING_TRIVIAL = 1 BITMESSAGE_ENCODING_TRIVIAL = 1
BITMESSAGE_ENCODING_SIMPLE = 2 BITMESSAGE_ENCODING_SIMPLE = 2
@ -25,24 +25,19 @@ BITMESSAGE_ENCODING_EXTENDED = 3
class MsgEncodeException(Exception): class MsgEncodeException(Exception):
"""Exception during message encoding"""
pass pass
class MsgDecodeException(Exception): class MsgDecodeException(Exception):
"""Exception during message decoding"""
pass pass
class DecompressionSizeException(MsgDecodeException): class DecompressionSizeException(MsgDecodeException):
# pylint: disable=super-init-not-called
"""Decompression resulted in too much data (attack protection)"""
def __init__(self, size): def __init__(self, size):
self.size = size self.size = size
class MsgEncode(object): class MsgEncode(object):
"""Message encoder class"""
def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE): def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE):
self.data = None self.data = None
self.encoding = encoding self.encoding = encoding
@ -57,7 +52,6 @@ class MsgEncode(object):
raise MsgEncodeException("Unknown encoding %i" % (encoding)) raise MsgEncodeException("Unknown encoding %i" % (encoding))
def encodeExtended(self, message): def encodeExtended(self, message):
"""Handle extended encoding"""
try: try:
msgObj = messagetypes.message.Message() msgObj = messagetypes.message.Message()
self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9) self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9)
@ -70,18 +64,15 @@ class MsgEncode(object):
self.length = len(self.data) self.length = len(self.data)
def encodeSimple(self, message): def encodeSimple(self, message):
"""Handle simple encoding"""
self.data = 'Subject:%(subject)s\nBody:%(body)s' % message self.data = 'Subject:%(subject)s\nBody:%(body)s' % message
self.length = len(self.data) self.length = len(self.data)
def encodeTrivial(self, message): def encodeTrivial(self, message):
"""Handle trivial encoding"""
self.data = message['body'] self.data = message['body']
self.length = len(self.data) self.length = len(self.data)
class MsgDecode(object): class MsgDecode(object):
"""Message decoder class"""
def __init__(self, encoding, data): def __init__(self, encoding, data):
self.encoding = encoding self.encoding = encoding
if self.encoding == BITMESSAGE_ENCODING_EXTENDED: if self.encoding == BITMESSAGE_ENCODING_EXTENDED:
@ -97,7 +88,6 @@ class MsgDecode(object):
self.subject = _translate("MsgDecode", "Unknown encoding") self.subject = _translate("MsgDecode", "Unknown encoding")
def decodeExtended(self, data): def decodeExtended(self, data):
"""Handle extended encoding"""
dc = zlib.decompressobj() dc = zlib.decompressobj()
tmp = "" tmp = ""
while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"): while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"):
@ -141,7 +131,6 @@ class MsgDecode(object):
self.body = msgObj.body self.body = msgObj.body
def decodeSimple(self, data): def decodeSimple(self, data):
"""Handle simple encoding"""
bodyPositionIndex = string.find(data, '\nBody:') bodyPositionIndex = string.find(data, '\nBody:')
if bodyPositionIndex > 1: if bodyPositionIndex > 1:
subject = data[8:bodyPositionIndex] subject = data[8:bodyPositionIndex]

View File

@ -2,9 +2,7 @@
import os import os
import random import random
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
NoneType = type(None) NoneType = type(None)
@ -58,6 +56,7 @@ def randomrandrange(x, y=None):
""" """
if isinstance(y, NoneType): if isinstance(y, NoneType):
return random.randrange(x) # nosec return random.randrange(x) # nosec
else:
return random.randrange(x, y) # nosec return random.randrange(x, y) # nosec

View File

@ -1,6 +1,6 @@
"""Additional SQL helper for searching messages""" #!/usr/bin/python2.7
from helper_sql import sqlQuery from helper_sql import *
try: try:
from PyQt4 import QtGui from PyQt4 import QtGui
@ -8,17 +8,13 @@ try:
except ImportError: except ImportError:
haveQt = False haveQt = False
def search_translate (context, text):
def search_translate(context, text):
"""Translation wrapper"""
if haveQt: if haveQt:
return QtGui.QApplication.translate(context, text) return QtGui.QApplication.translate(context, text)
else:
return text.lower() return text.lower()
def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False):
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False):
"""Perform a search in mailbox tables"""
# pylint: disable=too-many-arguments, too-many-branches
if what is not None and what != "": if what is not None and what != "":
what = "%" + what + "%" what = "%" + what + "%"
if where == search_translate("MainWindow", "To"): if where == search_translate("MainWindow", "To"):
@ -66,16 +62,13 @@ def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, w
sqlArguments.append(what) sqlArguments.append(what)
if unreadOnly: if unreadOnly:
sqlStatementParts.append("read = 0") sqlStatementParts.append("read = 0")
if sqlStatementParts: if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent": if folder == "sent":
sqlStatementBase += " ORDER BY lastactiontime" sqlStatementBase += " ORDER BY lastactiontime"
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)
def check_match(toAddress, fromAddress, subject, message, where = None, what = None):
def check_match(toAddress, fromAddress, subject, message, where=None, what=None):
"""Check if a single message matches a filter (used when new messages are added to messagelists)"""
# pylint: disable=too-many-arguments
if what is not None and what != "": if what is not None and what != "":
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")): if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")):
if what.lower() not in toAddress.lower(): if what.lower() not in toAddress.lower():

View File

@ -1,10 +1,4 @@
""" from helper_sql import *
Insert values into sent table
"""
from helper_sql import sqlExecute
def insert(t): def insert(t):
"""Perform an insert into the `sent` table"""
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)

View File

@ -1,39 +1,17 @@
""" """Helper Sql performs sql operations."""
SQL-related functions defined here are really pass the queries (or other SQL
commands) to :class:`.threads.sqlThread` through `sqlSubmitQueue` queue and check
or return the result got from `sqlReturnQueue`.
This is done that way because :mod:`sqlite3` is so thread-unsafe that they
won't even let you call it from different threads using your own locks.
SQLite objects can only be used from one thread.
.. note:: This actually only applies for certain deployments, and/or
really old version of sqlite. I haven't actually seen it anywhere.
Current versions do have support for threading and multiprocessing.
I don't see an urgent reason to refactor this, but it should be noted
in the comment that the problem is mostly not valid. Sadly, last time
I checked, there is no reliable way to check whether the library is
or isn't thread-safe.
"""
import Queue
import threading import threading
import Queue
sqlSubmitQueue = Queue.Queue() sqlSubmitQueue = Queue.Queue()
"""the queue for SQL""" # SQLITE3 is so thread-unsafe that they won't even let you call it from different threads using your own locks.
# SQL objects #can only be called from one thread.
sqlReturnQueue = Queue.Queue() sqlReturnQueue = Queue.Queue()
"""the queue for results"""
sqlLock = threading.Lock() sqlLock = threading.Lock()
def sqlQuery(sqlStatement, *args): def sqlQuery(sqlStatement, *args):
""" """SQLLITE execute statement and return query."""
Query sqlite and return results
:param str sqlStatement: SQL statement string
:param list args: SQL query parameters
:rtype: list
"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
@ -50,7 +28,6 @@ def sqlQuery(sqlStatement, *args):
def sqlExecuteChunked(sqlStatement, idCount, *args): def sqlExecuteChunked(sqlStatement, idCount, *args):
"""Execute chunked SQL statement to avoid argument limit"""
# SQLITE_MAX_VARIABLE_NUMBER, # SQLITE_MAX_VARIABLE_NUMBER,
# unfortunately getting/setting isn't exposed to python # unfortunately getting/setting isn't exposed to python
sqlExecuteChunked.chunkSize = 999 sqlExecuteChunked.chunkSize = 999
@ -81,7 +58,6 @@ def sqlExecuteChunked(sqlStatement, idCount, *args):
def sqlExecute(sqlStatement, *args): def sqlExecute(sqlStatement, *args):
"""Execute SQL statement (optionally with arguments)"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
@ -94,15 +70,13 @@ def sqlExecute(sqlStatement, *args):
sqlLock.release() sqlLock.release()
return rowcount return rowcount
def sqlStoredProcedure(procName): def sqlStoredProcedure(procName):
"""Schedule procName to be run"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(procName) sqlSubmitQueue.put(procName)
sqlLock.release() sqlLock.release()
class SqlBulkExecute(object): class SqlBulkExecute:
"""This is used when you have to execute the same statement in a cycle.""" """This is used when you have to execute the same statement in a cycle."""
def __enter__(self): def __enter__(self):

View File

@ -1,13 +1,16 @@
""" """
Startup operations. src/helper_startup.py
=====================
Helper Start performs all the startup operations.
""" """
# pylint: disable=too-many-branches,too-many-statements # pylint: disable=too-many-branches,too-many-statements
from __future__ import print_function
import logging import ConfigParser
import os import os
import platform import platform
import sys import sys
import time
from distutils.version import StrictVersion from distutils.version import StrictVersion
import defaults import defaults
@ -16,19 +19,28 @@ import paths
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
try:
from plugins.plugin import get_plugin
except ImportError:
get_plugin = None
logger = logging.getLogger('default')
# The user may de-select Portable Mode in the settings if they want # The user may de-select Portable Mode in the settings if they want
# the config files to stay in the application data folder. # the config files to stay in the application data folder.
StoreConfigFilesInSameDirectoryAsProgramByDefault = False StoreConfigFilesInSameDirectoryAsProgramByDefault = False
def _loadTrustedPeer():
try:
trustedPeer = BMConfigParser().get('bitmessagesettings', 'trustedpeer')
except ConfigParser.Error:
# This probably means the trusted peer wasn't specified so we
# can just leave it as None
return
try:
host, port = trustedPeer.split(':')
except ValueError:
sys.exit(
'Bad trustedpeer config setting! It should be set as'
' trustedpeer=<hostname>:<portnumber>'
)
state.trustedPeer = state.Peer(host, int(port))
def loadConfig(): def loadConfig():
"""Load the config""" """Load the config"""
config = BMConfigParser() config = BMConfigParser()
@ -38,14 +50,14 @@ def loadConfig():
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
logger.info( print(
'Loading config files from directory specified' 'Loading config files from directory specified'
' on startup: %s', state.appdata) ' on startup: %s' % state.appdata)
else: else:
config.read(paths.lookupExeFolder() + 'keys.dat') config.read(paths.lookupExeFolder() + 'keys.dat')
try: try:
config.get('bitmessagesettings', 'settingsversion') config.get('bitmessagesettings', 'settingsversion')
logger.info('Loading config files from same directory as program.') print('Loading config files from same directory as program.')
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except:
@ -56,8 +68,7 @@ def loadConfig():
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
logger.info( print('Loading existing config files from', state.appdata)
'Loading existing config files from %s', state.appdata)
if needToCreateKeysFile: if needToCreateKeysFile:
@ -112,10 +123,9 @@ def loadConfig():
# Just use the same directory as the program and forget about # Just use the same directory as the program and forget about
# the appdata folder # the appdata folder
state.appdata = '' state.appdata = ''
logger.info( print('Creating new config files in same directory as program.')
'Creating new config files in same directory as program.')
else: else:
logger.info('Creating new config files in %s', state.appdata) print('Creating new config files in', state.appdata)
if not os.path.exists(state.appdata): if not os.path.exists(state.appdata):
os.makedirs(state.appdata) os.makedirs(state.appdata)
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
@ -124,6 +134,8 @@ def loadConfig():
else: else:
updateConfig() updateConfig()
_loadTrustedPeer()
def updateConfig(): def updateConfig():
"""Save the config""" """Save the config"""
@ -265,7 +277,7 @@ def updateConfig():
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false') 'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1: if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
config.set('bitmessagesettings', 'maxoutboundconnections', '8') config.set('bitmessagesettings', 'maxoutboundconnections', '8')
logger.warning('Your maximum outbound connections must be a number.') print('WARNING: your maximum outbound connections must be a number.')
# TTL is now user-specifiable. Let's add an option to save # TTL is now user-specifiable. Let's add an option to save
# whatever the user selects. # whatever the user selects.
@ -288,26 +300,3 @@ def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
return False return False
except Exception: except Exception:
pass pass
def start_proxyconfig():
"""Check socksproxytype and start any proxy configuration plugin"""
if not get_plugin:
return
config = BMConfigParser()
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
if proxy_type and proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
try:
proxyconfig_start = time.time()
if not get_plugin('proxyconfig', name=proxy_type)(config):
raise TypeError()
except TypeError:
# cannot import shutdown here ):
logger.error(
'Failed to run proxy config plugin %s',
proxy_type, exc_info=True)
os._exit(0) # pylint: disable=protected-access
else:
logger.info(
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)

58
src/helper_threading.py Normal file
View File

@ -0,0 +1,58 @@
"""Helper threading perform all the threading operations."""
import threading
from contextlib import contextmanager
import helper_random
try:
import prctl
except ImportError:
def set_thread_name(name):
"""Set the thread name for external use (visible from the OS)."""
threading.current_thread().name = name
else:
def set_thread_name(name):
"""Set a name for the thread for python internal use."""
prctl.set_name(name)
def _thread_name_hack(self):
set_thread_name(self.name)
threading.Thread.__bootstrap_original__(self)
threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
threading.Thread._Thread__bootstrap = _thread_name_hack
class StoppableThread(threading.Thread):
name = None
def __init__(self, name=None):
if name:
self.name = name
super(StoppableThread, self).__init__(name=self.name)
self.initStop()
helper_random.seed()
def initStop(self):
self.stop = threading.Event()
self._stopped = False
def stopThread(self):
self._stopped = True
self.stop.set()
class BusyError(threading.ThreadError):
pass
@contextmanager
def nonBlocking(lock):
locked = lock.acquire(False)
if not locked:
raise BusyError
try:
yield
finally:
lock.release()

View File

@ -1,10 +1,6 @@
""" """
High level cryptographic functions based on `.pyelliptic` OpenSSL bindings. src/highlevelcrypto.py
======================
.. note::
Upstream pyelliptic was upgraded from SHA1 to SHA256 for signing.
We must upgrade PyBitmessage gracefully.
`More discussion. <https://github.com/yann2192/pyelliptic/issues/32>`_
""" """
from binascii import hexlify from binascii import hexlify
@ -16,13 +12,12 @@ from pyelliptic import arithmetic as a
def makeCryptor(privkey): def makeCryptor(privkey):
"""Return a private `.pyelliptic.ECC` instance""" """Return a private pyelliptic.ECC() instance"""
private_key = a.changebase(privkey, 16, 256, minlen=32) private_key = a.changebase(privkey, 16, 256, minlen=32)
public_key = pointMult(private_key) public_key = pointMult(private_key)
privkey_bin = '\x02\xca\x00\x20' + private_key privkey_bin = '\x02\xca\x00\x20' + private_key
pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + public_key[-32:] pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + public_key[-32:]
cryptor = pyelliptic.ECC( cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
return cryptor return cryptor
@ -34,7 +29,7 @@ def hexToPubkey(pubkey):
def makePubCryptor(pubkey): def makePubCryptor(pubkey):
"""Return a public `.pyelliptic.ECC` instance""" """Return a public pyelliptic.ECC() instance"""
pubkey_bin = hexToPubkey(pubkey) pubkey_bin = hexToPubkey(pubkey)
return pyelliptic.ECC(curve='secp256k1', pubkey=pubkey_bin) return pyelliptic.ECC(curve='secp256k1', pubkey=pubkey_bin)
@ -48,8 +43,7 @@ def privToPub(privkey):
def encrypt(msg, hexPubkey): def encrypt(msg, hexPubkey):
"""Encrypts message with hex public key""" """Encrypts message with hex public key"""
return pyelliptic.ECC(curve='secp256k1').encrypt( return pyelliptic.ECC(curve='secp256k1').encrypt(msg, hexToPubkey(hexPubkey))
msg, hexToPubkey(hexPubkey))
def decrypt(msg, hexPrivkey): def decrypt(msg, hexPrivkey):
@ -58,38 +52,36 @@ def decrypt(msg, hexPrivkey):
def decryptFast(msg, cryptor): def decryptFast(msg, cryptor):
"""Decrypts message with an existing `.pyelliptic.ECC` object""" """Decrypts message with an existing pyelliptic.ECC.ECC object"""
return cryptor.decrypt(msg) return cryptor.decrypt(msg)
def sign(msg, hexPrivkey): def sign(msg, hexPrivkey):
""" """Signs with hex private key"""
Signs with hex private key using SHA1 or SHA256 depending on # pyelliptic is upgrading from SHA1 to SHA256 for signing. We must
"digestalg" setting # upgrade PyBitmessage gracefully.
""" # https://github.com/yann2192/pyelliptic/pull/33
digestAlg = BMConfigParser().safeGet( # More discussion: https://github.com/yann2192/pyelliptic/issues/32
'bitmessagesettings', 'digestalg', 'sha1') digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1')
if digestAlg == "sha1": if digestAlg == "sha1":
# SHA1, this will eventually be deprecated # SHA1, this will eventually be deprecated
return makeCryptor(hexPrivkey).sign( return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
elif digestAlg == "sha256": elif digestAlg == "sha256":
# SHA256. Eventually this will become the default # SHA256. Eventually this will become the default
return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256) return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256)
else: else:
raise ValueError("Unknown digest algorithm %s" % digestAlg) raise ValueError("Unknown digest algorithm %s" % (digestAlg))
def verify(msg, sig, hexPubkey): def verify(msg, sig, hexPubkey):
"""Verifies with hex public key using SHA1 or SHA256""" """Verifies with hex public key"""
# As mentioned above, we must upgrade gracefully to use SHA256. So # As mentioned above, we must upgrade gracefully to use SHA256. So
# let us check the signature using both SHA1 and SHA256 and if one # let us check the signature using both SHA1 and SHA256 and if one
# of them passes then we will be satisfied. Eventually this can # of them passes then we will be satisfied. Eventually this can
# be simplified and we'll only check with SHA256. # be simplified and we'll only check with SHA256.
try: try:
# old SHA1 algorithm. # old SHA1 algorithm.
sigVerifyPassed = makePubCryptor(hexPubkey).verify( sigVerifyPassed = makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
except: except:
sigVerifyPassed = False sigVerifyPassed = False
if sigVerifyPassed: if sigVerifyPassed:
@ -97,8 +89,7 @@ def verify(msg, sig, hexPubkey):
return True return True
# The signature check using SHA1 failed. Let us try it with SHA256. # The signature check using SHA1 failed. Let us try it with SHA256.
try: try:
return makePubCryptor(hexPubkey).verify( return makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.EVP_sha256)
sig, msg, digest_alg=OpenSSL.EVP_sha256)
except: except:
return False return False
@ -109,14 +100,13 @@ def pointMult(secret):
Evidently, this type of error can occur very rarely: Evidently, this type of error can occur very rarely:
>>> File "highlevelcrypto.py", line 54, in pointMult File "highlevelcrypto.py", line 54, in pointMult
>>> group = OpenSSL.EC_KEY_get0_group(k) group = OpenSSL.EC_KEY_get0_group(k)
>>> WindowsError: exception: access violation reading 0x0000000000000008 WindowsError: exception: access violation reading 0x0000000000000008
""" """
while True: while True:
try: try:
k = OpenSSL.EC_KEY_new_by_curve_name( k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
OpenSSL.get_curve('secp256k1'))
priv_key = OpenSSL.BN_bin2bn(secret, 32, None) priv_key = OpenSSL.BN_bin2bn(secret, 32, None)
group = OpenSSL.EC_KEY_get0_group(k) group = OpenSSL.EC_KEY_get0_group(k)
pub_key = OpenSSL.EC_POINT_new(group) pub_key = OpenSSL.EC_POINT_new(group)

View File

@ -1,8 +1,8 @@
"""The Inventory singleton""" """The Inventory singleton"""
# TODO make this dynamic, and watch out for frozen, like with messagetypes # TODO make this dynamic, and watch out for frozen, like with messagetypes
import storage.filesystem
import storage.sqlite import storage.sqlite
import storage.filesystem
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from singleton import Singleton from singleton import Singleton

View File

@ -3,7 +3,6 @@ Manipulations with knownNodes dictionary.
""" """
import json import json
import logging
import os import os
import pickle import pickle
import threading import threading
@ -11,33 +10,33 @@ import time
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from network.node import Peer from debug import logger
from helper_bootstrap import dns
knownNodesLock = threading.Lock() knownNodesLock = threading.Lock()
"""Thread lock for knownnodes modification"""
knownNodes = {stream: {} for stream in range(1, 4)} knownNodes = {stream: {} for stream in range(1, 4)}
"""The dict of known nodes for each stream"""
knownNodesTrimAmount = 2000 knownNodesTrimAmount = 2000
"""trim stream knownnodes dict to this length"""
# forget a node after rating is this low
knownNodesForgetRating = -0.5 knownNodesForgetRating = -0.5
"""forget a node after rating is this low"""
knownNodesActual = False knownNodesActual = False
logger = logging.getLogger('default')
DEFAULT_NODES = ( DEFAULT_NODES = (
Peer('5.45.99.75', 8444), state.Peer('5.45.99.75', 8444),
Peer('75.167.159.54', 8444), state.Peer('75.167.159.54', 8444),
Peer('95.165.168.168', 8444), state.Peer('95.165.168.168', 8444),
Peer('85.180.139.241', 8444), state.Peer('85.180.139.241', 8444),
Peer('158.222.217.190', 8080), state.Peer('158.222.217.190', 8080),
Peer('178.62.12.187', 8448), state.Peer('178.62.12.187', 8448),
Peer('24.188.198.204', 8111), state.Peer('24.188.198.204', 8111),
Peer('109.147.204.113', 1195), state.Peer('109.147.204.113', 1195),
Peer('178.11.46.221', 8444) state.Peer('178.11.46.221', 8444)
)
DEFAULT_NODES_ONION = (
state.Peer('quzwelsuziwqgpt2.onion', 8444),
) )
@ -63,17 +62,20 @@ def json_deserialize_knownnodes(source):
for node in json.load(source): for node in json.load(source):
peer = node['peer'] peer = node['peer']
info = node['info'] info = node['info']
peer = Peer(str(peer['host']), peer.get('port', 8444)) peer = state.Peer(str(peer['host']), peer.get('port', 8444))
knownNodes[node['stream']][peer] = info knownNodes[node['stream']][peer] = info
if not (knownNodesActual if (
or info.get('self')) and peer not in DEFAULT_NODES: not (knownNodesActual or info.get('self')) and
peer not in DEFAULT_NODES and
peer not in DEFAULT_NODES_ONION
):
knownNodesActual = True knownNodesActual = True
def pickle_deserialize_old_knownnodes(source): def pickle_deserialize_old_knownnodes(source):
""" """
Unpickle source and reorganize knownnodes dict if it has old format Unpickle source and reorganize knownnodes dict if it's in old format
the old format was {Peer:lastseen, ...} the old format was {Peer:lastseen, ...}
the new format is {Peer:{"lastseen":i, "rating":f}} the new format is {Peer:{"lastseen":i, "rating":f}}
""" """
@ -86,7 +88,6 @@ def pickle_deserialize_old_knownnodes(source):
def saveKnownNodes(dirName=None): def saveKnownNodes(dirName=None):
"""Save knownnodes to filesystem"""
if dirName is None: if dirName is None:
dirName = state.appdata dirName = state.appdata
with knownNodesLock: with knownNodesLock:
@ -95,7 +96,6 @@ def saveKnownNodes(dirName=None):
def addKnownNode(stream, peer, lastseen=None, is_self=False): def addKnownNode(stream, peer, lastseen=None, is_self=False):
"""Add a new node to the dict"""
knownNodes[stream][peer] = { knownNodes[stream][peer] = {
"lastseen": lastseen or time.time(), "lastseen": lastseen or time.time(),
"rating": 1 if is_self else 0, "rating": 1 if is_self else 0,
@ -103,16 +103,14 @@ def addKnownNode(stream, peer, lastseen=None, is_self=False):
} }
def createDefaultKnownNodes(): def createDefaultKnownNodes(onion=False):
"""Creating default Knownnodes"""
past = time.time() - 2418600 # 28 days - 10 min past = time.time() - 2418600 # 28 days - 10 min
for peer in DEFAULT_NODES: for peer in DEFAULT_NODES_ONION if onion else DEFAULT_NODES:
addKnownNode(1, peer, past) addKnownNode(1, peer, past)
saveKnownNodes() saveKnownNodes()
def readKnownNodes(): def readKnownNodes():
"""Load knownnodes from filesystem"""
try: try:
with open(state.appdata + 'knownnodes.dat', 'rb') as source: with open(state.appdata + 'knownnodes.dat', 'rb') as source:
with knownNodesLock: with knownNodesLock:
@ -133,13 +131,12 @@ def readKnownNodes():
if onionhostname and ".onion" in onionhostname: if onionhostname and ".onion" in onionhostname:
onionport = config.safeGetInt('bitmessagesettings', 'onionport') onionport = config.safeGetInt('bitmessagesettings', 'onionport')
if onionport: if onionport:
self_peer = Peer(onionhostname, onionport) self_peer = state.Peer(onionhostname, onionport)
addKnownNode(1, self_peer, is_self=True) addKnownNode(1, self_peer, is_self=True)
state.ownAddresses[self_peer] = True state.ownAddresses[self_peer] = True
def increaseRating(peer): def increaseRating(peer):
"""Increase rating of a peer node"""
increaseAmount = 0.1 increaseAmount = 0.1
maxRating = 1 maxRating = 1
with knownNodesLock: with knownNodesLock:
@ -154,7 +151,6 @@ def increaseRating(peer):
def decreaseRating(peer): def decreaseRating(peer):
"""Decrease rating of a peer node"""
decreaseAmount = 0.1 decreaseAmount = 0.1
minRating = -1 minRating = -1
with knownNodesLock: with knownNodesLock:
@ -169,7 +165,6 @@ def decreaseRating(peer):
def trimKnownNodes(recAddrStream=1): def trimKnownNodes(recAddrStream=1):
"""Triming Knownnodes"""
if len(knownNodes[recAddrStream]) < \ if len(knownNodes[recAddrStream]) < \
BMConfigParser().safeGetInt("knownnodes", "maxnodes"): BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
return return
@ -182,38 +177,40 @@ def trimKnownNodes(recAddrStream=1):
del knownNodes[recAddrStream][oldest] del knownNodes[recAddrStream][oldest]
def dns():
"""Add DNS names to knownnodes"""
for port in [8080, 8444]:
addKnownNode(
1, Peer('bootstrap%s.bitmessage.org' % port, port))
def cleanupKnownNodes(): def cleanupKnownNodes():
""" """
Cleanup knownnodes: remove old nodes and nodes with low rating Cleanup knownnodes: remove old nodes and nodes with low rating
""" """
now = int(time.time()) now = int(time.time())
needToWriteKnownNodesToDisk = False needToWriteKnownNodesToDisk = False
dns_done = False
spawnConnections = not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'
) and BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'sendoutgoingconnections')
with knownNodesLock: with knownNodesLock:
for stream in knownNodes: for stream in knownNodes:
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
keys = knownNodes[stream].keys() keys = knownNodes[stream].keys()
if len(keys) <= 1: # leave at least one node
if not dns_done and spawnConnections:
dns()
dns_done = True
continue
for node in keys: for node in keys:
if len(knownNodes[stream]) <= 1: # leave at least one node
break
try: try:
age = now - knownNodes[stream][node]["lastseen"] # scrap old nodes
# scrap old nodes (age > 28 days) if (now - knownNodes[stream][node]["lastseen"] >
if age > 2419200: 2419200): # 28 days
needToWriteKnownNodesToDisk = True needToWriteKnownNodesToDisk = True
del knownNodes[stream][node] del knownNodes[stream][node]
continue continue
# scrap old nodes (age > 3 hours) with low rating # scrap old nodes with low rating
if (age > 10800 and knownNodes[stream][node]["rating"] if (now - knownNodes[stream][node]["lastseen"] > 10800 and
<= knownNodesForgetRating): knownNodes[stream][node]["rating"] <=
knownNodesForgetRating):
needToWriteKnownNodesToDisk = True needToWriteKnownNodesToDisk = True
del knownNodes[stream][node] del knownNodes[stream][node]
continue continue

View File

@ -1,13 +1,13 @@
"""
Localization
"""
import logging import logging
import os import os
import time import time
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
logger = logging.getLogger('default')
#logger = logging.getLogger(__name__)
logger = logging.getLogger('file_only')
DEFAULT_ENCODING = 'ISO8859-1' DEFAULT_ENCODING = 'ISO8859-1'
@ -50,7 +50,7 @@ except:
if BMConfigParser().has_option('bitmessagesettings', 'timeformat'): if BMConfigParser().has_option('bitmessagesettings', 'timeformat'):
time_format = BMConfigParser().get('bitmessagesettings', 'timeformat') time_format = BMConfigParser().get('bitmessagesettings', 'timeformat')
# Test the format string #Test the format string
try: try:
time.strftime(time_format) time.strftime(time_format)
except: except:
@ -59,52 +59,48 @@ if BMConfigParser().has_option('bitmessagesettings', 'timeformat'):
else: else:
time_format = DEFAULT_TIME_FORMAT time_format = DEFAULT_TIME_FORMAT
# It seems some systems lie about the encoding they use so we perform #It seems some systems lie about the encoding they use so we perform
# comprehensive decoding tests #comprehensive decoding tests
if time_format != DEFAULT_TIME_FORMAT: if time_format != DEFAULT_TIME_FORMAT:
try: try:
# Check day names #Check day names
for i in xrange(7): for i in xrange(7):
unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, i, 0, 0)), encoding) unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, i, 0, 0)), encoding)
# Check month names #Check month names
for i in xrange(1, 13): for i in xrange(1, 13):
unicode(time.strftime(time_format, (0, i, 0, 0, 0, 0, 0, 0, 0)), encoding) unicode(time.strftime(time_format, (0, i, 0, 0, 0, 0, 0, 0, 0)), encoding)
# Check AM/PM #Check AM/PM
unicode(time.strftime(time_format, (0, 0, 0, 11, 0, 0, 0, 0, 0)), encoding) unicode(time.strftime(time_format, (0, 0, 0, 11, 0, 0, 0, 0, 0)), encoding)
unicode(time.strftime(time_format, (0, 0, 0, 13, 0, 0, 0, 0, 0)), encoding) unicode(time.strftime(time_format, (0, 0, 0, 13, 0, 0, 0, 0, 0)), encoding)
# Check DST #Check DST
unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, 0, 0, 1)), encoding) unicode(time.strftime(time_format, (0, 0, 0, 0, 0, 0, 0, 0, 1)), encoding)
except: except:
logger.exception('Could not decode locale formatted timestamp') logger.exception('Could not decode locale formatted timestamp')
time_format = DEFAULT_TIME_FORMAT time_format = DEFAULT_TIME_FORMAT
encoding = DEFAULT_ENCODING encoding = DEFAULT_ENCODING
def setlocale(category, newlocale): def setlocale(category, newlocale):
"""Set the locale"""
locale.setlocale(category, newlocale) locale.setlocale(category, newlocale)
# it looks like some stuff isn't initialised yet when this is called the # it looks like some stuff isn't initialised yet when this is called the
# first time and its init gets the locale settings from the environment # first time and its init gets the locale settings from the environment
os.environ["LC_ALL"] = newlocale os.environ["LC_ALL"] = newlocale
def formatTimestamp(timestamp = None, as_unicode = True):
def formatTimestamp(timestamp=None, as_unicode=True): #For some reason some timestamps are strings so we need to sanitize.
"""Return a formatted timestamp"""
# For some reason some timestamps are strings so we need to sanitize.
if timestamp is not None and not isinstance(timestamp, int): if timestamp is not None and not isinstance(timestamp, int):
try: try:
timestamp = int(timestamp) timestamp = int(timestamp)
except: except:
timestamp = None timestamp = None
# timestamp can't be less than 0. #timestamp can't be less than 0.
if timestamp is not None and timestamp < 0: if timestamp is not None and timestamp < 0:
timestamp = None timestamp = None
if timestamp is None: if timestamp is None:
timestring = time.strftime(time_format) timestring = time.strftime(time_format)
else: else:
# In case timestamp is too far in the future #In case timestamp is too far in the future
try: try:
timestring = time.strftime(time_format, time.localtime(timestamp)) timestring = time.strftime(time_format, time.localtime(timestamp))
except ValueError: except ValueError:
@ -114,21 +110,17 @@ def formatTimestamp(timestamp=None, as_unicode=True):
return unicode(timestring, encoding) return unicode(timestring, encoding)
return timestring return timestring
def getTranslationLanguage(): def getTranslationLanguage():
"""Return the user's language choice""" userlocale = None
userlocale = BMConfigParser().safeGet( if BMConfigParser().has_option('bitmessagesettings', 'userlocale'):
'bitmessagesettings', 'userlocale', 'system') userlocale = BMConfigParser().get('bitmessagesettings', 'userlocale')
return userlocale if userlocale and userlocale != 'system' else language
if userlocale in [None, '', 'system']:
return language
return userlocale
def getWindowsLocale(posixLocale): def getWindowsLocale(posixLocale):
"""
Get the Windows locale
Technically this converts the locale string from UNIX to Windows format,
because they use different ones in their
libraries. E.g. "en_EN.UTF-8" to "english".
"""
if posixLocale in windowsLanguageMap: if posixLocale in windowsLanguageMap:
return windowsLanguageMap[posixLocale] return windowsLanguageMap[posixLocale]
if "." in posixLocale: if "." in posixLocale:

View File

@ -1,6 +1,6 @@
"""This module is for thread start.""" """This module is for thread start."""
import state
from bitmessagemain import main from bitmessagemain import main
import state
if __name__ == '__main__': if __name__ == '__main__':
state.kivy = True state.kivy = True

136
src/message_data_reader.py Normal file
View File

@ -0,0 +1,136 @@
# pylint: disable=too-many-locals
"""
This program can be used to print out everything in your Inbox or Sent folders and also take things out of the trash.
Scroll down to the bottom to see the functions that you can uncomment. Save then run this file.
The functions which only read the database file seem to function just
fine even if you have Bitmessage running but you should definitly close
it before running the functions that make changes (like taking items out
of the trash).
"""
from __future__ import absolute_import
import sqlite3
from binascii import hexlify
from time import strftime, localtime
import paths
import queues
appdata = paths.lookupAppdataFolder()
conn = sqlite3.connect(appdata + 'messages.dat')
conn.text_factory = str
cur = conn.cursor()
def readInbox():
"""Print each row from inbox table"""
print 'Printing everything in inbox table:'
item = '''select * from inbox'''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
for row in output:
print row
def readSent():
"""Print each row from sent table"""
print 'Printing everything in Sent table:'
item = '''select * from sent where folder !='trash' '''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
for row in output:
(msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime,
sleeptill, status, retrynumber, folder, encodingtype, ttl) = row # pylint: disable=unused-variable
print(hexlify(msgid), toaddress, 'toripe:', hexlify(toripe), 'fromaddress:', fromaddress, 'ENCODING TYPE:',
encodingtype, 'SUBJECT:', repr(subject), 'MESSAGE:', repr(message), 'ACKDATA:', hexlify(ackdata),
lastactiontime, status, retrynumber, folder)
def readSubscriptions():
"""Print each row from subscriptions table"""
print 'Printing everything in subscriptions table:'
item = '''select * from subscriptions'''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
for row in output:
print row
def readPubkeys():
"""Print each row from pubkeys table"""
print 'Printing everything in pubkeys table:'
item = '''select address, transmitdata, time, usedpersonally from pubkeys'''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
for row in output:
address, transmitdata, time, usedpersonally = row
print(
'Address:', address, '\tTime first broadcast:', unicode(
strftime('%a, %d %b %Y %I:%M %p', localtime(time)), 'utf-8'),
'\tUsed by me personally:', usedpersonally, '\tFull pubkey message:', hexlify(transmitdata),
)
def readInventory():
"""Print each row from inventory table"""
print 'Printing everything in inventory table:'
item = '''select hash, objecttype, streamnumber, payload, expirestime from inventory'''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
for row in output:
obj_hash, objecttype, streamnumber, payload, expirestime = row
print 'Hash:', hexlify(obj_hash), objecttype, streamnumber, '\t', hexlify(payload), '\t', unicode(
strftime('%a, %d %b %Y %I:%M %p', localtime(expirestime)), 'utf-8')
def takeInboxMessagesOutOfTrash():
"""Update all inbox messages with folder=trash to have folder=inbox"""
item = '''update inbox set folder='inbox' where folder='trash' '''
parameters = ''
cur.execute(item, parameters)
_ = cur.fetchall()
conn.commit()
print 'done'
def takeSentMessagesOutOfTrash():
"""Update all sent messages with folder=trash to have folder=sent"""
item = '''update sent set folder='sent' where folder='trash' '''
parameters = ''
cur.execute(item, parameters)
_ = cur.fetchall()
conn.commit()
print 'done'
def markAllInboxMessagesAsUnread():
"""Update all messages in inbox to have read=0"""
item = '''update inbox set read='0' '''
parameters = ''
cur.execute(item, parameters)
_ = cur.fetchall()
conn.commit()
queues.UISignalQueue.put(('changedInboxUnread', None))
print 'done'
def vacuum():
"""Perform a vacuum on the database"""
item = '''VACUUM'''
parameters = ''
cur.execute(item, parameters)
_ = cur.fetchall()
conn.commit()
print 'done'
if __name__ == '__main__':
readInbox()

View File

@ -1,22 +1,17 @@
import logging
from importlib import import_module from importlib import import_module
from os import listdir, path from os import path, listdir
from string import lower from string import lower
from debug import logger
import messagetypes import messagetypes
import paths import paths
logger = logging.getLogger('default') class MsgBase(object):
def encode(self):
class MsgBase(object): # pylint: disable=too-few-public-methods
"""Base class for message types"""
def __init__(self):
self.data = {"": lower(type(self).__name__)} self.data = {"": lower(type(self).__name__)}
def constructObject(data): def constructObject(data):
"""Constructing an object"""
whitelist = ["message"] whitelist = ["message"]
if data[""] not in whitelist: if data[""] not in whitelist:
return None return None
@ -37,7 +32,6 @@ def constructObject(data):
else: else:
return returnObj return returnObj
if paths.frozen is not None: if paths.frozen is not None:
import messagetypes.message import messagetypes.message
import messagetypes.vote import messagetypes.vote

View File

@ -1,29 +1,24 @@
import logging from debug import logger
from messagetypes import MsgBase from messagetypes import MsgBase
logger = logging.getLogger('default')
class Message(MsgBase): class Message(MsgBase):
"""Encapsulate a message""" def __init__(self):
# pylint: disable=attribute-defined-outside-init return
def decode(self, data): def decode(self, data):
"""Decode a message"""
# UTF-8 and variable type validator # UTF-8 and variable type validator
if isinstance(data["subject"], str): if type(data["subject"]) is str:
self.subject = unicode(data["subject"], 'utf-8', 'replace') self.subject = unicode(data["subject"], 'utf-8', 'replace')
else: else:
self.subject = unicode(str(data["subject"]), 'utf-8', 'replace') self.subject = unicode(str(data["subject"]), 'utf-8', 'replace')
if isinstance(data["body"], str): if type(data["body"]) is str:
self.body = unicode(data["body"], 'utf-8', 'replace') self.body = unicode(data["body"], 'utf-8', 'replace')
else: else:
self.body = unicode(str(data["body"]), 'utf-8', 'replace') self.body = unicode(str(data["body"]), 'utf-8', 'replace')
def encode(self, data): def encode(self, data):
"""Encode a message""" super(Message, self).encode()
super(Message, self).__init__()
try: try:
self.data["subject"] = data["subject"] self.data["subject"] = data["subject"]
self.data["body"] = data["body"] self.data["body"] = data["body"]
@ -32,6 +27,5 @@ class Message(MsgBase):
return self.data return self.data
def process(self): def process(self):
"""Process a message"""
logger.debug("Subject: %i bytes", len(self.subject)) logger.debug("Subject: %i bytes", len(self.subject))
logger.debug("Body: %i bytes", len(self.body)) logger.debug("Body: %i bytes", len(self.body))

View File

@ -1,30 +1,23 @@
import logging from debug import logger
from messagetypes import MsgBase from messagetypes import MsgBase
logger = logging.getLogger('default')
class Vote(MsgBase): class Vote(MsgBase):
"""Module used to vote""" def __init__(self):
return
def decode(self, data): def decode(self, data):
"""decode a vote"""
# pylint: disable=attribute-defined-outside-init
self.msgid = data["msgid"] self.msgid = data["msgid"]
self.vote = data["vote"] self.vote = data["vote"]
def encode(self, data): def encode(self, data):
"""Encode a vote""" super(Vote, self).encode()
super(Vote, self).__init__()
try: try:
self.data["msgid"] = data["msgid"] self.data["msgid"] = data["msgid"]
self.data["vote"] = data["vote"] self.data["vote"] = data["vote"]
except KeyError as e: except KeyError as e:
logger.error("Missing key %s", e) logger.error("Missing key %s", e.name)
return self.data return self.data
def process(self): def process(self):
"""Encode a vote"""
logger.debug("msgid: %s", self.msgid) logger.debug("msgid: %s", self.msgid)
logger.debug("vote: %s", self.vote) logger.debug("vote: %s", self.vote)

View File

@ -1,6 +1,6 @@
""" """
A queue with multiple internal subqueues. src/multiqueue.py
Elements are added into a random subqueue, and retrieval rotates =================
""" """
import Queue import Queue

View File

@ -1,7 +1,31 @@
"""
Namecoin queries
"""
# pylint: disable=too-many-branches,protected-access # pylint: disable=too-many-branches,protected-access
"""
Copyright (C) 2013 by Daniel Kraft <d@domob.eu>
This file is part of the Bitmessage project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
.. todo:: from debug import logger crashes PyBitmessage due to a circular dependency. The debug module will also
override/disable logging.getLogger() # loggers so module level logging functions are used instead
"""
from __future__ import absolute_import
import base64 import base64
import httplib import httplib
@ -10,11 +34,11 @@ import os
import socket import socket
import sys import sys
from addresses import decodeAddress
from debug import logger
import defaults import defaults
import tr # translate import tr # translate
from addresses import decodeAddress
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger
configSection = "bitmessagesettings" configSection = "bitmessagesettings"
@ -234,7 +258,7 @@ class namecoinConnection(object):
resp = self.con.getresponse() resp = self.con.getresponse()
result = resp.read() result = resp.read()
if resp.status != 200: if resp.status != 200:
raise Exception("Namecoin returned status %i: %s" % (resp.status, resp.reason)) raise Exception("Namecoin returned status %i: %s" % resp.status, resp.reason)
except: except:
logger.info("HTTP receive error") logger.info("HTTP receive error")
except: except:
@ -264,7 +288,7 @@ class namecoinConnection(object):
return result return result
except socket.error as exc: except socket.error as exc:
raise Exception("Socket error in RPC connection: %s" % exc) raise Exception("Socket error in RPC connection: %s" % str(exc))
def lookupNamecoinFolder(): def lookupNamecoinFolder():

View File

@ -1,20 +0,0 @@
"""
Network subsystem packages
"""
from addrthread import AddrThread
from announcethread import AnnounceThread
from connectionpool import BMConnectionPool
from dandelion import Dandelion
from downloadthread import DownloadThread
from invthread import InvThread
from networkthread import BMNetworkThread
from receivequeuethread import ReceiveQueueThread
from threads import StoppableThread
from uploadthread import UploadThread
__all__ = [
"BMConnectionPool", "Dandelion",
"AddrThread", "AnnounceThread", "BMNetworkThread", "DownloadThread",
"InvThread", "ReceiveQueueThread", "UploadThread", "StoppableThread"
]

View File

@ -1,18 +1,12 @@
"""
Announce addresses as they are received from other hosts
"""
import Queue import Queue
import state from helper_threading import StoppableThread
from helper_random import randomshuffle
from network.assemble import assemble_addr
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from queues import addrQueue from queues import addrQueue
from threads import StoppableThread import state
class AddrThread(StoppableThread): class AddrThread(StoppableThread):
"""(Node) address broadcasting thread"""
name = "AddrBroadcaster" name = "AddrBroadcaster"
def run(self): def run(self):
@ -21,26 +15,15 @@ class AddrThread(StoppableThread):
while True: while True:
try: try:
data = addrQueue.get(False) data = addrQueue.get(False)
chunk.append(data) chunk.append((data[0], data[1]))
if len(data) > 2:
source = BMConnectionPool().getConnectionByAddr(data[2])
except Queue.Empty: except Queue.Empty:
break break
except KeyError:
continue
if chunk: # finish
# Choose peers randomly
connections = BMConnectionPool().establishedConnections()
randomshuffle(connections)
for i in connections:
randomshuffle(chunk)
filtered = []
for stream, peer, seen, destination in chunk:
# peer's own address or address received from peer
if i.destination in (peer, destination):
continue
if stream not in i.streams:
continue
filtered.append((stream, peer, seen))
if filtered:
i.append_write_buf(assemble_addr(filtered))
addrQueue.iterate() addrQueue.iterate()
for i in range(len(chunk)): for i in range(len(chunk)):

View File

@ -1,19 +1,21 @@
""" """
Improved version of asyncore dispatcher src/network/advanceddispatcher.py
=================================
""" """
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
import socket import socket
import threading import threading
import time import time
import network.asyncore_pollchoose as asyncore import network.asyncore_pollchoose as asyncore
import state import state
from threads import BusyError, nonBlocking from debug import logger
from helper_threading import BusyError, nonBlocking
class ProcessingError(Exception): class ProcessingError(Exception):
"""General class for protocol parser exception, """General class for protocol parser exception, use as a base for others."""
use as a base for others."""
pass pass
@ -23,8 +25,7 @@ class UnknownStateError(ProcessingError):
class AdvancedDispatcher(asyncore.dispatcher): class AdvancedDispatcher(asyncore.dispatcher):
"""Improved version of asyncore dispatcher, """Improved version of asyncore dispatcher, with buffers and protocol state."""
with buffers and protocol state."""
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
_buf_len = 131072 # 128kB _buf_len = 131072 # 128kB
@ -72,8 +73,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
del self.read_buf[0:length] del self.read_buf[0:length]
def process(self): def process(self):
"""Process (parse) data that's in the buffer, """Process (parse) data that's in the buffer, as long as there is enough data and the connection is open."""
as long as there is enough data and the connection is open."""
while self.connected and not state.shutdown: while self.connected and not state.shutdown:
try: try:
with nonBlocking(self.processingLock): with nonBlocking(self.processingLock):
@ -84,8 +84,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
try: try:
cmd = getattr(self, "state_" + str(self.state)) cmd = getattr(self, "state_" + str(self.state))
except AttributeError: except AttributeError:
self.logger.error( logger.error("Unknown state %s", self.state, exc_info=True)
'Unknown state %s', self.state, exc_info=True)
raise UnknownStateError(self.state) raise UnknownStateError(self.state)
if not cmd(): if not cmd():
break break
@ -105,9 +104,8 @@ class AdvancedDispatcher(asyncore.dispatcher):
if asyncore.maxUploadRate > 0: if asyncore.maxUploadRate > 0:
self.uploadChunk = int(asyncore.uploadBucket) self.uploadChunk = int(asyncore.uploadBucket)
self.uploadChunk = min(self.uploadChunk, len(self.write_buf)) self.uploadChunk = min(self.uploadChunk, len(self.write_buf))
return asyncore.dispatcher.writable(self) and ( return asyncore.dispatcher.writable(self) and \
self.connecting or ( (self.connecting or (self.connected and self.uploadChunk > 0))
self.connected and self.uploadChunk > 0))
def readable(self): def readable(self):
"""Is the read buffer ready to accept data from the network?""" """Is the read buffer ready to accept data from the network?"""
@ -116,15 +114,13 @@ class AdvancedDispatcher(asyncore.dispatcher):
self.downloadChunk = int(asyncore.downloadBucket) self.downloadChunk = int(asyncore.downloadBucket)
try: try:
if self.expectBytes > 0 and not self.fullyEstablished: if self.expectBytes > 0 and not self.fullyEstablished:
self.downloadChunk = min( self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf))
self.downloadChunk, self.expectBytes - len(self.read_buf))
if self.downloadChunk < 0: if self.downloadChunk < 0:
self.downloadChunk = 0 self.downloadChunk = 0
except AttributeError: except AttributeError:
pass pass
return asyncore.dispatcher.readable(self) and ( return asyncore.dispatcher.readable(self) and \
self.connecting or self.accepting or ( (self.connecting or self.accepting or (self.connected and self.downloadChunk > 0))
self.connected and self.downloadChunk > 0))
def handle_read(self): def handle_read(self):
"""Append incoming data to the read buffer.""" """Append incoming data to the read buffer."""
@ -148,21 +144,20 @@ class AdvancedDispatcher(asyncore.dispatcher):
try: try:
asyncore.dispatcher.handle_connect_event(self) asyncore.dispatcher.handle_connect_event(self)
except socket.error as e: except socket.error as e:
# pylint: disable=protected-access if e.args[0] not in asyncore._DISCONNECTED: # pylint: disable=protected-access
if e.args[0] not in asyncore._DISCONNECTED:
raise raise
def handle_connect(self): def handle_connect(self):
"""Method for handling connection established implementations.""" """Method for handling connection established implementations."""
self.lastTx = time.time() self.lastTx = time.time()
def state_close(self): # pylint: disable=no-self-use def state_close(self):
"""Signal to the processing loop to end.""" """Signal to the processing loop to end."""
# pylint: disable=no-self-use
return False return False
def handle_close(self): def handle_close(self):
"""Callback for connection being closed, """Callback for connection being closed, but can also be called directly when you want connection to close."""
but can also be called directly when you want connection to close."""
with self.readLock: with self.readLock:
self.read_buf = bytearray() self.read_buf = bytearray()
with self.writeLock: with self.writeLock:

View File

@ -1,20 +1,23 @@
""" """
Announce myself (node address) src/network/announcethread.py
=================================
""" """
import time import time
import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from network.assemble import assemble_addr from debug import logger
from helper_threading import StoppableThread
from network.bmproto import BMProto
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from network.udp import UDPSocket from network.udp import UDPSocket
from node import Peer import state
from threads import StoppableThread
class AnnounceThread(StoppableThread): class AnnounceThread(StoppableThread):
"""A thread to manage regular announcing of this node""" """A thread to manage regular announcing of this node"""
name = "Announcer" def __init__(self):
super(AnnounceThread, self).__init__(name="Announcer")
logger.info("init announce thread")
def run(self): def run(self):
lastSelfAnnounced = 0 lastSelfAnnounced = 0
@ -35,9 +38,6 @@ class AnnounceThread(StoppableThread):
for stream in state.streamsInWhichIAmParticipating: for stream in state.streamsInWhichIAmParticipating:
addr = ( addr = (
stream, stream,
Peer( state.Peer('127.0.0.1', BMConfigParser().safeGetInt("bitmessagesettings", "port")),
'127.0.0.1',
BMConfigParser().safeGetInt(
'bitmessagesettings', 'port')),
time.time()) time.time())
connection.append_write_buf(assemble_addr([addr])) connection.append_write_buf(BMProto.assembleAddr([addr]))

View File

@ -1,31 +0,0 @@
"""
Create bitmessage protocol command packets
"""
import struct
import addresses
from network.constants import MAX_ADDR_COUNT
from network.node import Peer
from protocol import CreatePacket, encodeHost
def assemble_addr(peerList):
"""Create address command"""
if isinstance(peerList, Peer):
peerList = [peerList]
if not peerList:
return b''
retval = b''
for i in range(0, len(peerList), MAX_ADDR_COUNT):
payload = addresses.encodeVarint(len(peerList[i:i + MAX_ADDR_COUNT]))
for stream, peer, timestamp in peerList[i:i + MAX_ADDR_COUNT]:
# 64-bit time
payload += struct.pack('>Q', timestamp)
payload += struct.pack('>I', stream)
# service bit flags offered by this node
payload += struct.pack('>q', 1)
payload += encodeHost(peer.host)
# remote port
payload += struct.pack('>H', peer.port)
retval += CreatePacket('addr', payload)
return retval

View File

@ -1,11 +1,56 @@
"""
Basic infrastructure for asynchronous socket service clients and servers.
"""
# -*- Mode: Python -*- # -*- Mode: Python -*-
# Id: asyncore.py,v 2.51 2000/09/07 22:29:26 rushing Exp # Id: asyncore.py,v 2.51 2000/09/07 22:29:26 rushing Exp
# Author: Sam Rushing <rushing@nightmare.com> # Author: Sam Rushing <rushing@nightmare.com>
# pylint: disable=too-many-branches,too-many-lines,global-statement # pylint: disable=too-many-statements,too-many-branches,no-self-use,too-many-lines,attribute-defined-outside-init
# pylint: disable=redefined-builtin,no-self-use # pylint: disable=global-statement
"""
src/network/asyncore_pollchoose.py
==================================
# ======================================================================
# Copyright 1996 by Sam Rushing
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Sam
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ======================================================================
Basic infrastructure for asynchronous socket service clients and servers.
There are only two ways to have a program on a single processor do "more
than one thing at a time". Multi-threaded programming is the simplest and
most popular way to do it, but there is another very different technique,
that lets you have nearly all the advantages of multi-threading, without
actually using multiple threads. it's really only practical if your program
is largely I/O bound. If your program is CPU bound, then pre-emptive
scheduled threads are probably what you really need. Network servers are
rarely CPU-bound, however.
If your operating system supports the select() system call in its I/O
library (and nearly all do), then you can use it to juggle multiple
communication channels at once; doing other work while your I/O is taking
place in the "background." Although this strategy can seem strange and
complex, especially at first, it is in many ways easier to understand and
control than multi-threaded programming. The module documented here solves
many of the difficult problems for you, making the task of building
sophisticated high-performance network servers and clients a snap.
"""
import os import os
import select import select
import socket import socket
@ -13,9 +58,8 @@ import sys
import time import time
import warnings import warnings
from errno import ( from errno import (
EADDRINUSE, EAGAIN, EALREADY, EBADF, ECONNABORTED, ECONNREFUSED, EADDRINUSE, EAGAIN, EALREADY, EBADF, ECONNABORTED, ECONNREFUSED, ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR,
ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EINVAL, EISCONN, ENETUNREACH, EINVAL, EISCONN, ENETUNREACH, ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
) )
from threading import current_thread from threading import current_thread
@ -63,8 +107,7 @@ def _strerror(err):
class ExitNow(Exception): class ExitNow(Exception):
"""We don't use directly but may be necessary as we replace """We don't use directly but may be necessary as we replace asyncore due to some library raising or expecting it"""
asyncore due to some library raising or expecting it"""
pass pass
@ -109,8 +152,7 @@ def write(obj):
def set_rates(download, upload): def set_rates(download, upload):
"""Set throttling rates""" """Set throttling rates"""
global maxDownloadRate, maxUploadRate, downloadBucket global maxDownloadRate, maxUploadRate, downloadBucket, uploadBucket, downloadTimestamp, uploadTimestamp
global uploadBucket, downloadTimestamp, uploadTimestamp
maxDownloadRate = float(download) * 1024 maxDownloadRate = float(download) * 1024
maxUploadRate = float(upload) * 1024 maxUploadRate = float(upload) * 1024
@ -140,8 +182,7 @@ def update_received(download=0):
currentTimestamp = time.time() currentTimestamp = time.time()
receivedBytes += download receivedBytes += download
if maxDownloadRate > 0: if maxDownloadRate > 0:
bucketIncrease = \ bucketIncrease = maxDownloadRate * (currentTimestamp - downloadTimestamp)
maxDownloadRate * (currentTimestamp - downloadTimestamp)
downloadBucket += bucketIncrease downloadBucket += bucketIncrease
if downloadBucket > maxDownloadRate: if downloadBucket > maxDownloadRate:
downloadBucket = int(maxDownloadRate) downloadBucket = int(maxDownloadRate)
@ -201,6 +242,7 @@ def readwrite(obj, flags):
def select_poller(timeout=0.0, map=None): def select_poller(timeout=0.0, map=None):
"""A poller which uses select(), available on most platforms.""" """A poller which uses select(), available on most platforms."""
# pylint: disable=redefined-builtin
if map is None: if map is None:
map = socket_map map = socket_map
@ -256,6 +298,7 @@ def select_poller(timeout=0.0, map=None):
def poll_poller(timeout=0.0, map=None): def poll_poller(timeout=0.0, map=None):
"""A poller which uses poll(), available on most UNIXen.""" """A poller which uses poll(), available on most UNIXen."""
# pylint: disable=redefined-builtin
if map is None: if map is None:
map = socket_map map = socket_map
@ -313,6 +356,7 @@ poll2 = poll3 = poll_poller
def epoll_poller(timeout=0.0, map=None): def epoll_poller(timeout=0.0, map=None):
"""A poller which uses epoll(), supported on Linux 2.5.44 and newer.""" """A poller which uses epoll(), supported on Linux 2.5.44 and newer."""
# pylint: disable=redefined-builtin
if map is None: if map is None:
map = socket_map map = socket_map
@ -368,7 +412,7 @@ def epoll_poller(timeout=0.0, map=None):
def kqueue_poller(timeout=0.0, map=None): def kqueue_poller(timeout=0.0, map=None):
"""A poller which uses kqueue(), BSD specific.""" """A poller which uses kqueue(), BSD specific."""
# pylint: disable=no-member,too-many-statements # pylint: disable=redefined-builtin,no-member
if map is None: if map is None:
map = socket_map map = socket_map
@ -396,20 +440,14 @@ def kqueue_poller(timeout=0.0, map=None):
poller_flags |= select.KQ_EV_ENABLE poller_flags |= select.KQ_EV_ENABLE
else: else:
poller_flags |= select.KQ_EV_DISABLE poller_flags |= select.KQ_EV_DISABLE
updates.append( updates.append(select.kevent(fd, filter=select.KQ_FILTER_READ, flags=poller_flags))
select.kevent(
fd, filter=select.KQ_FILTER_READ,
flags=poller_flags))
if kq_filter & 2 != obj.poller_filter & 2: if kq_filter & 2 != obj.poller_filter & 2:
poller_flags = select.KQ_EV_ADD poller_flags = select.KQ_EV_ADD
if kq_filter & 2: if kq_filter & 2:
poller_flags |= select.KQ_EV_ENABLE poller_flags |= select.KQ_EV_ENABLE
else: else:
poller_flags |= select.KQ_EV_DISABLE poller_flags |= select.KQ_EV_DISABLE
updates.append( updates.append(select.kevent(fd, filter=select.KQ_FILTER_WRITE, flags=poller_flags))
select.kevent(
fd, filter=select.KQ_FILTER_WRITE,
flags=poller_flags))
obj.poller_filter = kq_filter obj.poller_filter = kq_filter
if not selectables: if not selectables:
@ -443,6 +481,7 @@ def kqueue_poller(timeout=0.0, map=None):
def loop(timeout=30.0, use_poll=False, map=None, count=None, poller=None): def loop(timeout=30.0, use_poll=False, map=None, count=None, poller=None):
"""Poll in a loop, until count or timeout is reached""" """Poll in a loop, until count or timeout is reached"""
# pylint: disable=redefined-builtin
if map is None: if map is None:
map = socket_map map = socket_map
@ -481,9 +520,9 @@ def loop(timeout=30.0, use_poll=False, map=None, count=None, poller=None):
count = count - 1 count = count - 1
class dispatcher(object): class dispatcher:
"""Dispatcher for socket objects""" """Dispatcher for socket objects"""
# pylint: disable=too-many-public-methods,too-many-instance-attributes # pylint: disable=too-many-public-methods,too-many-instance-attributes,old-style-class
debug = False debug = False
connected = False connected = False
@ -498,6 +537,7 @@ class dispatcher(object):
minTx = 1500 minTx = 1500
def __init__(self, sock=None, map=None): def __init__(self, sock=None, map=None):
# pylint: disable=redefined-builtin
if map is None: if map is None:
self._map = socket_map self._map = socket_map
else: else:
@ -546,7 +586,8 @@ class dispatcher(object):
def add_channel(self, map=None): def add_channel(self, map=None):
"""Add a channel""" """Add a channel"""
# pylint: disable=attribute-defined-outside-init # pylint: disable=redefined-builtin
if map is None: if map is None:
map = self._map map = self._map
map[self._fileno] = self map[self._fileno] = self
@ -555,6 +596,8 @@ class dispatcher(object):
def del_channel(self, map=None): def del_channel(self, map=None):
"""Delete a channel""" """Delete a channel"""
# pylint: disable=redefined-builtin
fd = self._fileno fd = self._fileno
if map is None: if map is None:
map = self._map map = self._map
@ -562,14 +605,12 @@ class dispatcher(object):
del map[fd] del map[fd]
if self._fileno: if self._fileno:
try: try:
kqueue_poller.pollster.control([select.kevent( kqueue_poller.pollster.control([select.kevent(fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0)
fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0) except (AttributeError, KeyError, TypeError, IOError, OSError):
except(AttributeError, KeyError, TypeError, IOError, OSError):
pass pass
try: try:
kqueue_poller.pollster.control([select.kevent( kqueue_poller.pollster.control([select.kevent(fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0)
fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0) except (AttributeError, KeyError, TypeError, IOError, OSError):
except(AttributeError, KeyError, TypeError, IOError, OSError):
pass pass
try: try:
epoll_poller.pollster.unregister(fd) epoll_poller.pollster.unregister(fd)
@ -586,10 +627,8 @@ class dispatcher(object):
self.poller_filter = 0 self.poller_filter = 0
self.poller_registered = False self.poller_registered = False
def create_socket( def create_socket(self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
"""Create a socket""" """Create a socket"""
# pylint: disable=attribute-defined-outside-init
self.family_and_type = family, socket_type self.family_and_type = family, socket_type
sock = socket.socket(family, socket_type) sock = socket.socket(family, socket_type)
sock.setblocking(0) sock.setblocking(0)
@ -597,16 +636,20 @@ class dispatcher(object):
def set_socket(self, sock, map=None): def set_socket(self, sock, map=None):
"""Set socket""" """Set socket"""
# pylint: disable=redefined-builtin
self.socket = sock self.socket = sock
self._fileno = sock.fileno() self._fileno = sock.fileno()
self.add_channel(map) self.add_channel(map)
def set_reuse_addr(self): def set_reuse_addr(self):
"""try to re-use a server port if possible""" """try to re-use a server port if possible"""
try: try:
self.socket.setsockopt( self.socket.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, self.socket.getsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR,
socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1 self.socket.getsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR) | 1
) )
except socket.error: except socket.error:
pass pass
@ -661,16 +704,13 @@ class dispatcher(object):
raise socket.error(err, errorcode[err]) raise socket.error(err, errorcode[err])
def accept(self): def accept(self):
"""Accept incoming connections. """Accept incoming connections. Returns either an address pair or None."""
Returns either an address pair or None."""
try: try:
conn, addr = self.socket.accept() conn, addr = self.socket.accept()
except TypeError: except TypeError:
return None return None
except socket.error as why: except socket.error as why:
if why.args[0] in ( if why.args[0] in (EWOULDBLOCK, WSAEWOULDBLOCK, ECONNABORTED, EAGAIN, ENOTCONN):
EWOULDBLOCK, WSAEWOULDBLOCK, ECONNABORTED,
EAGAIN, ENOTCONN):
return None return None
else: else:
raise raise
@ -729,12 +769,11 @@ class dispatcher(object):
try: try:
retattr = getattr(self.socket, attr) retattr = getattr(self.socket, attr)
except AttributeError: except AttributeError:
raise AttributeError( raise AttributeError("%s instance has no attribute '%s'"
"%s instance has no attribute '%s'"
% (self.__class__.__name__, attr)) % (self.__class__.__name__, attr))
else: else:
msg = "%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s"\ msg = "%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s " \
" instead" % {'me': self.__class__.__name__, 'attr': attr} "instead" % {'me': self.__class__.__name__, 'attr': attr}
warnings.warn(msg, DeprecationWarning, stacklevel=2) warnings.warn(msg, DeprecationWarning, stacklevel=2)
return retattr return retattr
@ -816,8 +855,13 @@ class dispatcher(object):
self.log_info( self.log_info(
'uncaptured python exception, closing channel %s (%s:%s %s)' % ( 'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr, t, v, tbinfo), self_repr,
'error') t,
v,
tbinfo
),
'error'
)
self.handle_close() self.handle_close()
def handle_accept(self): def handle_accept(self):
@ -858,8 +902,11 @@ class dispatcher_with_send(dispatcher):
adds simple buffered output capability, useful for simple clients. adds simple buffered output capability, useful for simple clients.
[for more sophisticated usage use asynchat.async_chat] [for more sophisticated usage use asynchat.async_chat]
""" """
# pylint: disable=redefined-builtin
def __init__(self, sock=None, map=None): def __init__(self, sock=None, map=None):
# pylint: disable=redefined-builtin
dispatcher.__init__(self, sock, map) dispatcher.__init__(self, sock, map)
self.out_buffer = b'' self.out_buffer = b''
@ -894,8 +941,7 @@ def compact_traceback():
"""Return a compact traceback""" """Return a compact traceback"""
t, v, tb = sys.exc_info() t, v, tb = sys.exc_info()
tbinfo = [] tbinfo = []
# Must have a traceback if not tb: # Must have a traceback
if not tb:
raise AssertionError("traceback does not exist") raise AssertionError("traceback does not exist")
while tb: while tb:
tbinfo.append(( tbinfo.append((
@ -915,6 +961,7 @@ def compact_traceback():
def close_all(map=None, ignore_all=False): def close_all(map=None, ignore_all=False):
"""Close all connections""" """Close all connections"""
# pylint: disable=redefined-builtin
if map is None: if map is None:
map = socket_map map = socket_map
@ -951,13 +998,13 @@ def close_all(map=None, ignore_all=False):
if os.name == 'posix': if os.name == 'posix':
import fcntl import fcntl
class file_wrapper: # pylint: disable=old-style-class class file_wrapper:
""" """
Here we override just enough to make a file look Here we override just enough to make a file look like a socket for the purposes of asyncore.
like a socket for the purposes of asyncore.
The passed fd is automatically os.dup()'d The passed fd is automatically os.dup()'d
""" """
# pylint: disable=old-style-class
def __init__(self, fd): def __init__(self, fd):
self.fd = os.dup(fd) self.fd = os.dup(fd)
@ -972,11 +1019,12 @@ if os.name == 'posix':
def getsockopt(self, level, optname, buflen=None): def getsockopt(self, level, optname, buflen=None):
"""Fake getsockopt()""" """Fake getsockopt()"""
if (level == socket.SOL_SOCKET and optname == socket.SO_ERROR and if (level == socket.SOL_SOCKET and
optname == socket.SO_ERROR and
not buflen): not buflen):
return 0 return 0
raise NotImplementedError( raise NotImplementedError("Only asyncore specific behaviour "
"Only asyncore specific behaviour implemented.") "implemented.")
read = recv read = recv
write = send write = send
@ -993,6 +1041,8 @@ if os.name == 'posix':
"""A dispatcher for file_wrapper objects""" """A dispatcher for file_wrapper objects"""
def __init__(self, fd, map=None): def __init__(self, fd, map=None):
# pylint: disable=redefined-builtin
dispatcher.__init__(self, None, map) dispatcher.__init__(self, None, map)
self.connected = True self.connected = True
try: try:

View File

@ -1,27 +1,26 @@
""" """
BMObject and it's exceptions. src/network/bmobject.py
======================
""" """
import logging
import time import time
import protocol import protocol
import state import state
from addresses import calculateInventoryHash from addresses import calculateInventoryHash
from debug import logger
from inventory import Inventory from inventory import Inventory
from network.dandelion import Dandelion from network.dandelion import Dandelion
logger = logging.getLogger('default')
class BMObjectInsufficientPOWError(Exception): class BMObjectInsufficientPOWError(Exception):
"""Exception indicating the object """Exception indicating the object doesn't have sufficient proof of work."""
doesn't have sufficient proof of work."""
errorCodes = ("Insufficient proof of work") errorCodes = ("Insufficient proof of work")
class BMObjectInvalidDataError(Exception): class BMObjectInvalidDataError(Exception):
"""Exception indicating the data being parsed """Exception indicating the data being parsed does not match the specification."""
does not match the specification."""
errorCodes = ("Data invalid") errorCodes = ("Data invalid")
@ -31,8 +30,7 @@ class BMObjectExpiredError(Exception):
class BMObjectUnwantedStreamError(Exception): class BMObjectUnwantedStreamError(Exception):
"""Exception indicating the object is in a stream """Exception indicating the object is in a stream we didn't advertise as being interested in."""
we didn't advertise as being interested in."""
errorCodes = ("Object in unwanted stream") errorCodes = ("Object in unwanted stream")
@ -46,8 +44,9 @@ class BMObjectAlreadyHaveError(Exception):
errorCodes = ("Already have this object") errorCodes = ("Already have this object")
class BMObject(object): # pylint: disable=too-many-instance-attributes class BMObject(object):
"""Bitmessage Object as a class.""" """Bitmessage Object as a class."""
# pylint: disable=too-many-instance-attributes
# max TTL, 28 days and 3 hours # max TTL, 28 days and 3 hours
maxTTL = 28 * 24 * 60 * 60 + 10800 maxTTL = 28 * 24 * 60 * 60 + 10800
@ -82,36 +81,31 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
raise BMObjectInsufficientPOWError() raise BMObjectInsufficientPOWError()
def checkEOLSanity(self): def checkEOLSanity(self):
"""Check if object's lifetime """Check if object's lifetime isn't ridiculously far in the past or future."""
isn't ridiculously far in the past or future."""
# EOL sanity check # EOL sanity check
if self.expiresTime - int(time.time()) > BMObject.maxTTL: if self.expiresTime - int(time.time()) > BMObject.maxTTL:
logger.info( logger.info(
'This object\'s End of Life time is too far in the future.' 'This object\'s End of Life time is too far in the future. Ignoring it. Time is %i',
' Ignoring it. Time is %i', self.expiresTime) self.expiresTime)
# .. todo:: remove from download queue # .. todo:: remove from download queue
raise BMObjectExpiredError() raise BMObjectExpiredError()
if self.expiresTime - int(time.time()) < BMObject.minTTL: if self.expiresTime - int(time.time()) < BMObject.minTTL:
logger.info( logger.info(
'This object\'s End of Life time was too long ago.' 'This object\'s End of Life time was too long ago. Ignoring the object. Time is %i',
' Ignoring the object. Time is %i', self.expiresTime) self.expiresTime)
# .. todo:: remove from download queue # .. todo:: remove from download queue
raise BMObjectExpiredError() raise BMObjectExpiredError()
def checkStream(self): def checkStream(self):
"""Check if object's stream matches streams we are interested in""" """Check if object's stream matches streams we are interested in"""
if self.streamNumber not in state.streamsInWhichIAmParticipating: if self.streamNumber not in state.streamsInWhichIAmParticipating:
logger.debug( logger.debug('The streamNumber %i isn\'t one we are interested in.', self.streamNumber)
'The streamNumber %i isn\'t one we are interested in.',
self.streamNumber)
raise BMObjectUnwantedStreamError() raise BMObjectUnwantedStreamError()
def checkAlreadyHave(self): def checkAlreadyHave(self):
""" """
Check if we already have the object Check if we already have the object (so that we don't duplicate it in inventory or advertise it unnecessarily)
(so that we don't duplicate it in inventory
or advertise it unnecessarily)
""" """
# if it's a stem duplicate, pretend we don't have it # if it's a stem duplicate, pretend we don't have it
if Dandelion().hasHash(self.inventoryHash): if Dandelion().hasHash(self.inventoryHash):
@ -120,8 +114,7 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
raise BMObjectAlreadyHaveError() raise BMObjectAlreadyHaveError()
def checkObjectByType(self): def checkObjectByType(self):
"""Call a object type specific check """Call a object type specific check (objects can have additional checks based on their types)"""
(objects can have additional checks based on their types)"""
if self.objectType == protocol.OBJECT_GETPUBKEY: if self.objectType == protocol.OBJECT_GETPUBKEY:
self.checkGetpubkey() self.checkGetpubkey()
elif self.objectType == protocol.OBJECT_PUBKEY: elif self.objectType == protocol.OBJECT_PUBKEY:
@ -132,21 +125,20 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
self.checkBroadcast() self.checkBroadcast()
# other objects don't require other types of tests # other objects don't require other types of tests
def checkMessage(self): # pylint: disable=no-self-use def checkMessage(self):
""""Message" object type checks.""" """"Message" object type checks."""
# pylint: disable=no-self-use
return return
def checkGetpubkey(self): def checkGetpubkey(self):
""""Getpubkey" object type checks.""" """"Getpubkey" object type checks."""
if len(self.data) < 42: if len(self.data) < 42:
logger.info( logger.info('getpubkey message doesn\'t contain enough data. Ignoring.')
'getpubkey message doesn\'t contain enough data. Ignoring.')
raise BMObjectInvalidError() raise BMObjectInvalidError()
def checkPubkey(self): def checkPubkey(self):
""""Pubkey" object type checks.""" """"Pubkey" object type checks."""
# sanity check if len(self.data) < 146 or len(self.data) > 440: # sanity check
if len(self.data) < 146 or len(self.data) > 440:
logger.info('pubkey object too short or too long. Ignoring.') logger.info('pubkey object too short or too long. Ignoring.')
raise BMObjectInvalidError() raise BMObjectInvalidError()
@ -154,9 +146,8 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
""""Broadcast" object type checks.""" """"Broadcast" object type checks."""
if len(self.data) < 180: if len(self.data) < 180:
logger.debug( logger.debug(
'The payload length of this broadcast' 'The payload length of this broadcast packet is unreasonably low.'
' packet is unreasonably low. Someone is probably' ' Someone is probably trying funny business. Ignoring message.')
' trying funny business. Ignoring message.')
raise BMObjectInvalidError() raise BMObjectInvalidError()
# this isn't supported anymore # this isn't supported anymore

View File

@ -1,10 +1,10 @@
""" """
Bitmessage Protocol src/network/bmproto.py
==================================
""" """
# pylint: disable=attribute-defined-outside-init, too-few-public-methods # pylint: disable=attribute-defined-outside-init
import base64 import base64
import hashlib import hashlib
import logging
import socket import socket
import struct import struct
import time import time
@ -16,26 +16,20 @@ import knownnodes
import protocol import protocol
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger
from inventory import Inventory from inventory import Inventory
from network.advanceddispatcher import AdvancedDispatcher from network.advanceddispatcher import AdvancedDispatcher
from network.bmobject import (
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
BMObjectInvalidError, BMObjectUnwantedStreamError
)
from network.constants import (
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
MAX_OBJECT_PAYLOAD_SIZE, MAX_TIME_OFFSET
)
from network.dandelion import Dandelion from network.dandelion import Dandelion
from network.bmobject import (
BMObject, BMObjectInsufficientPOWError, BMObjectInvalidDataError,
BMObjectExpiredError, BMObjectUnwantedStreamError,
BMObjectInvalidError, BMObjectAlreadyHaveError)
from network.node import Node
from network.proxy import ProxyError from network.proxy import ProxyError
from node import Node, Peer from objectracker import missingObjects, ObjectTracker
from objectracker import ObjectTracker, missingObjects from queues import objectProcessorQueue, portCheckerQueue, invQueue, addrQueue
from queues import invQueue, objectProcessorQueue, portCheckerQueue
from randomtrackingdict import RandomTrackingDict from randomtrackingdict import RandomTrackingDict
logger = logging.getLogger('default')
class BMProtoError(ProxyError): class BMProtoError(ProxyError):
"""A Bitmessage Protocol Base Error""" """A Bitmessage Protocol Base Error"""
@ -55,17 +49,26 @@ class BMProtoExcessiveDataError(BMProtoError):
class BMProto(AdvancedDispatcher, ObjectTracker): class BMProto(AdvancedDispatcher, ObjectTracker):
"""A parser for the Bitmessage Protocol""" """A parser for the Bitmessage Protocol"""
# pylint: disable=too-many-instance-attributes, too-many-public-methods # pylint: disable=too-many-instance-attributes, too-many-public-methods
# ~1.6 MB which is the maximum possible size of an inv message.
maxMessageSize = 1600100
# 2**18 = 256kB is the maximum size of an object payload
maxObjectPayloadSize = 2**18
# protocol specification says max 1000 addresses in one addr command
maxAddrCount = 1000
# protocol specification says max 50000 objects in one inv command
maxObjectCount = 50000
# address is online if online less than this many seconds ago
addressAlive = 10800
# maximum time offset
maxTimeOffset = 3600
timeOffsetWrongCount = 0 timeOffsetWrongCount = 0
def __init__(self, address=None, sock=None): def __init__(self, address=None, sock=None): # pylint: disable=unused-argument, super-init-not-called
# pylint: disable=unused-argument, super-init-not-called
AdvancedDispatcher.__init__(self, sock) AdvancedDispatcher.__init__(self, sock)
self.isOutbound = False self.isOutbound = False
# packet/connection from a local IP # packet/connection from a local IP
self.local = False self.local = False
self.pendingUpload = RandomTrackingDict() self.pendingUpload = RandomTrackingDict()
# canonical identifier of network group
self.network_group = None
def bm_proto_reset(self): def bm_proto_reset(self):
"""Reset the bitmessage object parser""" """Reset the bitmessage object parser"""
@ -93,7 +96,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.close_reason = "Bad magic" self.close_reason = "Bad magic"
self.set_state("close") self.set_state("close")
return False return False
if self.payloadLength > MAX_MESSAGE_SIZE: if self.payloadLength > BMProto.maxMessageSize:
self.invalid = True self.invalid = True
self.set_state( self.set_state(
"bm_command", "bm_command",
@ -162,8 +165,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def decode_payload_varint(self): def decode_payload_varint(self):
"""Decode a varint from the payload""" """Decode a varint from the payload"""
value, offset = addresses.decodeVarint( value, offset = addresses.decodeVarint(self.payload[self.payloadOffset:])
self.payload[self.payloadOffset:])
self.payloadOffset += offset self.payloadOffset += offset
return value return value
@ -185,8 +187,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
return Node(services, host, port) return Node(services, host, port)
# pylint: disable=too-many-branches, too-many-statements def decode_payload_content(self, pattern="v"): # pylint: disable=too-many-branches, too-many-statements
def decode_payload_content(self, pattern="v"):
""" """
Decode the payload depending on pattern: Decode the payload depending on pattern:
@ -202,8 +204,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
, = end of array , = end of array
""" """
# pylint: disable=inconsistent-return-statements def decode_simple(self, char="v"): # pylint: disable=inconsistent-return-statements
def decode_simple(self, char="v"):
"""Decode the payload using one char pattern""" """Decode the payload using one char pattern"""
if char == "v": if char == "v":
return self.decode_payload_varint() return self.decode_payload_varint()
@ -313,11 +314,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def bm_command_error(self): def bm_command_error(self):
"""Decode an error message and log it""" """Decode an error message and log it"""
err_values = self.decode_payload_content("vvlsls") fatalStatus, banTime, inventoryVector, errorText = \
fatalStatus = err_values[0] self.decode_payload_content("vvlsls")
# banTime = err_values[1]
# inventoryVector = err_values[2]
errorText = err_values[3]
logger.error( logger.error(
'%s:%i error: %i, %s', self.destination.host, '%s:%i error: %i, %s', self.destination.host,
self.destination.port, fatalStatus, errorText) self.destination.port, fatalStatus, errorText)
@ -341,7 +339,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def _command_inv(self, dandelion=False): def _command_inv(self, dandelion=False):
items = self.decode_payload_content("l32s") items = self.decode_payload_content("l32s")
if len(items) > MAX_OBJECT_COUNT: if len(items) > BMProto.maxObjectCount:
logger.error( logger.error(
'Too many items in %sinv message!', 'd' if dandelion else '') 'Too many items in %sinv message!', 'd' if dandelion else '')
raise BMProtoExcessiveDataError() raise BMProtoExcessiveDataError()
@ -376,7 +374,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
nonce, expiresTime, objectType, version, streamNumber, nonce, expiresTime, objectType, version, streamNumber,
self.payload, self.payloadOffset) self.payload, self.payloadOffset)
if len(self.payload) - self.payloadOffset > MAX_OBJECT_PAYLOAD_SIZE: if len(self.payload) - self.payloadOffset > BMProto.maxObjectPayloadSize:
logger.info( logger.info(
'The payload length of this object is too large (%d bytes).' 'The payload length of this object is too large (%d bytes).'
' Ignoring it.', len(self.payload) - self.payloadOffset) ' Ignoring it.', len(self.payload) - self.payloadOffset)
@ -412,10 +410,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
except KeyError: except KeyError:
pass pass
if self.object.inventoryHash in Inventory() and Dandelion().hasHash( if self.object.inventoryHash in Inventory() and Dandelion().hasHash(self.object.inventoryHash):
self.object.inventoryHash): Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
Dandelion().removeHash(
self.object.inventoryHash, "cycle detection")
Inventory()[self.object.inventoryHash] = ( Inventory()[self.object.inventoryHash] = (
self.object.objectType, self.object.streamNumber, self.object.objectType, self.object.streamNumber,
@ -434,46 +430,39 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def bm_command_addr(self): def bm_command_addr(self):
"""Incoming addresses, process them""" """Incoming addresses, process them"""
# pylint: disable=redefined-outer-name addresses = self._decode_addr() # pylint: disable=redefined-outer-name
addresses = self._decode_addr() for i in addresses:
for seenTime, stream, _, ip, port in addresses: seenTime, stream, services, ip, port = i
decodedIP = protocol.checkIPAddress(str(ip)) decodedIP = protocol.checkIPAddress(str(ip))
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
if ( if (
decodedIP and time.time() - seenTime > 0 and decodedIP and time.time() - seenTime > 0 and
seenTime > time.time() - ADDRESS_ALIVE and seenTime > time.time() - BMProto.addressAlive and
port > 0 port > 0
): ):
peer = Peer(decodedIP, port) peer = state.Peer(decodedIP, port)
try: try:
if knownnodes.knownNodes[stream][peer]["lastseen"] > \ if knownnodes.knownNodes[stream][peer]["lastseen"] > seenTime:
seenTime:
continue continue
except KeyError: except KeyError:
pass pass
if len(knownnodes.knownNodes[stream]) < \ if len(knownnodes.knownNodes[stream]) < BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
try: try:
knownnodes.knownNodes[stream][peer]["lastseen"] = \ knownnodes.knownNodes[stream][peer]["lastseen"] = seenTime
seenTime
except (TypeError, KeyError): except (TypeError, KeyError):
knownnodes.knownNodes[stream][peer] = { knownnodes.knownNodes[stream][peer] = {
"lastseen": seenTime, "lastseen": seenTime,
"rating": 0, "rating": 0,
"self": False, "self": False,
} }
# since we don't track peers outside of knownnodes, addrQueue.put((stream, peer, self.destination))
# only spread if in knownnodes to prevent flood
# DISABLED TO WORKAROUND FLOOD/LEAK
# addrQueue.put((stream, peer, seenTime,
# self.destination))
return True return True
def bm_command_portcheck(self): def bm_command_portcheck(self):
"""Incoming port check request, queue it.""" """Incoming port check request, queue it."""
portCheckerQueue.put(Peer(self.destination, self.peerNode.port)) portCheckerQueue.put(state.Peer(self.destination, self.peerNode.port))
return True return True
def bm_command_ping(self): def bm_command_ping(self):
@ -519,7 +508,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.timeOffset = self.timestamp - int(time.time()) self.timeOffset = self.timestamp - int(time.time())
logger.debug('remoteProtocolVersion: %i', self.remoteProtocolVersion) logger.debug('remoteProtocolVersion: %i', self.remoteProtocolVersion)
logger.debug('services: 0x%08X', self.services) logger.debug('services: 0x%08X', self.services)
logger.debug('time offset: %i', self.timeOffset) logger.debug('time offset: %i', self.timestamp - int(time.time()))
logger.debug('my external IP: %s', self.sockNode.host) logger.debug('my external IP: %s', self.sockNode.host)
logger.debug( logger.debug(
'remote node incoming address: %s:%i', 'remote node incoming address: %s:%i',
@ -549,8 +538,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
length=self.payloadLength, expectBytes=0) length=self.payloadLength, expectBytes=0)
return False return False
# pylint: disable=too-many-return-statements def peerValidityChecks(self): # pylint: disable=too-many-return-statements
def peerValidityChecks(self):
"""Check the validity of the peer""" """Check the validity of the peer"""
if self.remoteProtocolVersion < 3: if self.remoteProtocolVersion < 3:
self.append_write_buf(protocol.assembleErrorMessage( self.append_write_buf(protocol.assembleErrorMessage(
@ -560,16 +548,16 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
'Closing connection to old protocol version %s, node: %s', 'Closing connection to old protocol version %s, node: %s',
self.remoteProtocolVersion, self.destination) self.remoteProtocolVersion, self.destination)
return False return False
if self.timeOffset > MAX_TIME_OFFSET: if self.timeOffset > BMProto.maxTimeOffset:
self.append_write_buf(protocol.assembleErrorMessage( self.append_write_buf(protocol.assembleErrorMessage(
errorText="Your time is too far in the future" errorText="Your time is too far in the future compared to mine."
" compared to mine. Closing connection.", fatal=2)) " Closing connection.", fatal=2))
logger.info( logger.info(
"%s's time is too far in the future (%s seconds)." "%s's time is too far in the future (%s seconds)."
" Closing connection to it.", self.destination, self.timeOffset) " Closing connection to it.", self.destination, self.timeOffset)
BMProto.timeOffsetWrongCount += 1 BMProto.timeOffsetWrongCount += 1
return False return False
elif self.timeOffset < -MAX_TIME_OFFSET: elif self.timeOffset < -BMProto.maxTimeOffset:
self.append_write_buf(protocol.assembleErrorMessage( self.append_write_buf(protocol.assembleErrorMessage(
errorText="Your time is too far in the past compared to mine." errorText="Your time is too far in the past compared to mine."
" Closing connection.", fatal=2)) " Closing connection.", fatal=2))
@ -585,8 +573,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
errorText="We don't have shared stream interests." errorText="We don't have shared stream interests."
" Closing connection.", fatal=2)) " Closing connection.", fatal=2))
logger.debug( logger.debug(
'Closed connection to %s because there is no overlapping' 'Closed connection to %s because there is no overlapping interest'
' interest in streams.', self.destination) ' in streams.', self.destination)
return False return False
if self.destination in connectionpool.BMConnectionPool().inboundConnections: if self.destination in connectionpool.BMConnectionPool().inboundConnections:
try: try:
@ -595,8 +583,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
errorText="Too many connections from your IP." errorText="Too many connections from your IP."
" Closing connection.", fatal=2)) " Closing connection.", fatal=2))
logger.debug( logger.debug(
'Closed connection to %s because we are already' 'Closed connection to %s because we are already connected'
' connected to that IP.', self.destination) ' to that IP.', self.destination)
return False return False
except: except:
pass pass
@ -604,14 +592,12 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
# incoming from a peer we're connected to as outbound, # incoming from a peer we're connected to as outbound,
# or server full report the same error to counter deanonymisation # or server full report the same error to counter deanonymisation
if ( if (
Peer(self.destination.host, self.peerNode.port) state.Peer(self.destination.host, self.peerNode.port) in
in connectionpool.BMConnectionPool().inboundConnections connectionpool.BMConnectionPool().inboundConnections or
or len(connectionpool.BMConnectionPool().inboundConnections) len(connectionpool.BMConnectionPool().inboundConnections) +
+ len(connectionpool.BMConnectionPool().outboundConnections) len(connectionpool.BMConnectionPool().outboundConnections) >
> BMConfigParser().safeGetInt( BMConfigParser().safeGetInt("bitmessagesettings", "maxtotalconnections") +
'bitmessagesettings', 'maxtotalconnections') BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections")
+ BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxbootstrapconnections')
): ):
self.append_write_buf(protocol.assembleErrorMessage( self.append_write_buf(protocol.assembleErrorMessage(
errorText="Server full, please try again later.", fatal=2)) errorText="Server full, please try again later.", fatal=2))
@ -631,10 +617,36 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
return True return True
@staticmethod
def assembleAddr(peerList):
"""Build up a packed address"""
if isinstance(peerList, state.Peer):
peerList = (peerList)
if not peerList:
return b''
retval = b''
for i in range(0, len(peerList), BMProto.maxAddrCount):
payload = addresses.encodeVarint(
len(peerList[i:i + BMProto.maxAddrCount]))
for address in peerList[i:i + BMProto.maxAddrCount]:
stream, peer, timestamp = address
payload += struct.pack(
'>Q', timestamp) # 64-bit time
payload += struct.pack('>I', stream)
payload += struct.pack(
'>q', 1) # service bit flags offered by this node
payload += protocol.encodeHost(peer.host)
payload += struct.pack('>H', peer.port) # remote port
retval += protocol.CreatePacket('addr', payload)
return retval
@staticmethod @staticmethod
def stopDownloadingObject(hashId, forwardAnyway=False): def stopDownloadingObject(hashId, forwardAnyway=False):
"""Stop downloading an object""" """Stop downloading an object"""
for connection in connectionpool.BMConnectionPool().connections(): for connection in (
connectionpool.BMConnectionPool().inboundConnections.values() +
connectionpool.BMConnectionPool().outboundConnections.values()
):
try: try:
del connection.objectsNewToMe[hashId] del connection.objectsNewToMe[hashId]
except KeyError: except KeyError:
@ -675,7 +687,7 @@ class BMStringParser(BMProto):
""" """
def __init__(self): def __init__(self):
super(BMStringParser, self).__init__() super(BMStringParser, self).__init__()
self.destination = Peer('127.0.0.1', 8444) self.destination = state.Peer('127.0.0.1', 8444)
self.payload = None self.payload = None
ObjectTracker.__init__(self) ObjectTracker.__init__(self)

View File

@ -1,21 +1,14 @@
"""
Select which node to connect to
"""
# pylint: disable=too-many-branches
import logging
import random # nosec import random # nosec
import knownnodes import knownnodes
import protocol import protocol
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger
from queues import Queue, portCheckerQueue from queues import Queue, portCheckerQueue
logger = logging.getLogger('default')
def getDiscoveredPeer(): def getDiscoveredPeer():
"""Get a peer from the local peer discovery list"""
try: try:
peer = random.choice(state.discoveredPeers.keys()) peer = random.choice(state.discoveredPeers.keys())
except (IndexError, KeyError): except (IndexError, KeyError):
@ -28,11 +21,10 @@ def getDiscoveredPeer():
def chooseConnection(stream): def chooseConnection(stream):
"""Returns an appropriate connection"""
haveOnion = BMConfigParser().safeGet( haveOnion = BMConfigParser().safeGet(
"bitmessagesettings", "socksproxytype")[0:5] == 'SOCKS' "bitmessagesettings", "socksproxytype")[0:5] == 'SOCKS'
onionOnly = BMConfigParser().safeGetBoolean( if state.trustedPeer:
"bitmessagesettings", "onionservicesonly") return state.trustedPeer
try: try:
retval = portCheckerQueue.get(False) retval = portCheckerQueue.get(False)
portCheckerQueue.task_done() portCheckerQueue.task_done()
@ -46,23 +38,15 @@ def chooseConnection(stream):
for _ in range(50): for _ in range(50):
peer = random.choice(knownnodes.knownNodes[stream].keys()) peer = random.choice(knownnodes.knownNodes[stream].keys())
try: try:
peer_info = knownnodes.knownNodes[stream][peer] rating = knownnodes.knownNodes[stream][peer]['rating']
if peer_info.get('self'):
continue
rating = peer_info["rating"]
except TypeError: except TypeError:
logger.warning('Error in %s', peer) logger.warning('Error in %s', peer)
rating = 0 rating = 0
if haveOnion: if haveOnion:
# do not connect to raw IP addresses
# --keep all traffic within Tor overlay
if onionOnly and not peer.host.endswith('.onion'):
continue
# onion addresses have a higher priority when SOCKS # onion addresses have a higher priority when SOCKS
if peer.host.endswith('.onion') and rating > 0: if peer.host.endswith('.onion') and rating > 0:
rating = 1 rating = 1
# TODO: need better check else:
elif not peer.host.startswith('bootstrap'):
encodedAddr = protocol.encodeHost(peer.host) encodedAddr = protocol.encodeHost(peer.host)
# don't connect to local IPs when using SOCKS # don't connect to local IPs when using SOCKS
if not protocol.checkIPAddress(encodedAddr, False): if not protocol.checkIPAddress(encodedAddr, False):

View File

@ -1,49 +1,32 @@
""" """
`BMConnectionPool` class definition src/network/connectionpool.py
==================================
""" """
import errno import errno
import logging
import re import re
import socket import socket
import sys
import time import time
import asyncore_pollchoose as asyncore import asyncore_pollchoose as asyncore
import helper_bootstrap
import helper_random import helper_random
import knownnodes import knownnodes
import protocol import protocol
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from connectionchooser import chooseConnection from connectionchooser import chooseConnection
from node import Peer from debug import logger
from proxy import Proxy from proxy import Proxy
from singleton import Singleton from singleton import Singleton
from tcp import ( from tcp import (
bootstrap, Socks4aBMConnection, Socks5BMConnection, TCPServer, Socks5BMConnection, Socks4aBMConnection, TCPConnection)
TCPConnection, TCPServer)
from udp import UDPSocket from udp import UDPSocket
logger = logging.getLogger('default')
@Singleton @Singleton
# pylint: disable=too-many-instance-attributes
class BMConnectionPool(object): class BMConnectionPool(object):
"""Pool of all existing connections""" """Pool of all existing connections"""
# pylint: disable=too-many-instance-attributes
trustedPeer = None
"""
If the trustedpeer option is specified in keys.dat then this will
contain a Peer which will be connected to instead of using the
addresses advertised by other peers.
The expected use case is where the user has a trusted server where
they run a Bitmessage daemon permanently. If they then run a second
instance of the client on a local machine periodically when they want
to check for messages it will sync with the network a lot faster
without compromising security.
"""
def __init__(self): def __init__(self):
asyncore.set_rates( asyncore.set_rates(
BMConfigParser().safeGetInt( BMConfigParser().safeGetInt(
@ -56,33 +39,9 @@ class BMConnectionPool(object):
self.listeningSockets = {} self.listeningSockets = {}
self.udpSockets = {} self.udpSockets = {}
self.streams = [] self.streams = []
self._lastSpawned = 0 self.lastSpawned = 0
self._spawnWait = 2 self.spawnWait = 2
self._bootstrapped = False self.bootstrapped = False
trustedPeer = BMConfigParser().safeGet(
'bitmessagesettings', 'trustedpeer')
try:
if trustedPeer:
host, port = trustedPeer.split(':')
self.trustedPeer = Peer(host, int(port))
except ValueError:
sys.exit(
'Bad trustedpeer config setting! It should be set as'
' trustedpeer=<hostname>:<portnumber>'
)
def connections(self):
"""
Shortcut for combined list of connections from
`inboundConnections` and `outboundConnections` dicts
"""
return self.inboundConnections.values() + self.outboundConnections.values()
def establishedConnections(self):
"""Shortcut for list of connections having fullyEstablished == True"""
return [
x for x in self.connections() if x.fullyEstablished]
def connectToStream(self, streamNumber): def connectToStream(self, streamNumber):
"""Connect to a bitmessage stream""" """Connect to a bitmessage stream"""
@ -113,7 +72,10 @@ class BMConnectionPool(object):
def isAlreadyConnected(self, nodeid): def isAlreadyConnected(self, nodeid):
"""Check if we're already connected to this peer""" """Check if we're already connected to this peer"""
for i in self.connections(): for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
try: try:
if nodeid == i.nodeid: if nodeid == i.nodeid:
return True return True
@ -139,7 +101,7 @@ class BMConnectionPool(object):
if isinstance(connection, UDPSocket): if isinstance(connection, UDPSocket):
del self.udpSockets[connection.listening.host] del self.udpSockets[connection.listening.host]
elif isinstance(connection, TCPServer): elif isinstance(connection, TCPServer):
del self.listeningSockets[Peer( del self.listeningSockets[state.Peer(
connection.destination.host, connection.destination.port)] connection.destination.host, connection.destination.port)]
elif connection.isOutbound: elif connection.isOutbound:
try: try:
@ -165,11 +127,10 @@ class BMConnectionPool(object):
"bitmessagesettings", "onionbindip") "bitmessagesettings", "onionbindip")
else: else:
host = '127.0.0.1' host = '127.0.0.1'
if ( if (BMConfigParser().safeGetBoolean(
BMConfigParser().safeGetBoolean("bitmessagesettings", "sockslisten") "bitmessagesettings", "sockslisten") or
or BMConfigParser().safeGet("bitmessagesettings", "socksproxytype") BMConfigParser().safeGet(
== "none" "bitmessagesettings", "socksproxytype") == "none"):
):
# python doesn't like bind + INADDR_ANY? # python doesn't like bind + INADDR_ANY?
# host = socket.INADDR_ANY # host = socket.INADDR_ANY
host = BMConfigParser().get("network", "bind") host = BMConfigParser().get("network", "bind")
@ -199,37 +160,8 @@ class BMConnectionPool(object):
udpSocket = UDPSocket(host=bind, announcing=True) udpSocket = UDPSocket(host=bind, announcing=True)
self.udpSockets[udpSocket.listening.host] = udpSocket self.udpSockets[udpSocket.listening.host] = udpSocket
def startBootstrappers(self): def loop(self): # pylint: disable=too-many-branches, too-many-statements
"""Run the process of resolving bootstrap hostnames"""
proxy_type = BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype')
# A plugins may be added here
hostname = None
if not proxy_type or proxy_type == 'none':
connection_base = TCPConnection
elif proxy_type == 'SOCKS5':
connection_base = Socks5BMConnection
hostname = helper_random.randomchoice([
'quzwelsuziwqgpt2.onion', None
])
elif proxy_type == 'SOCKS4a':
connection_base = Socks4aBMConnection # FIXME: I cannot test
else:
# This should never happen because socksproxytype setting
# is handled in bitmessagemain before starting the connectionpool
return
bootstrapper = bootstrap(connection_base)
if not hostname:
port = helper_random.randomchoice([8080, 8444])
hostname = 'bootstrap%s.bitmessage.org' % port
else:
port = 8444
self.addConnection(bootstrapper(hostname, port))
def loop(self): # pylint: disable=too-many-branches,too-many-statements
"""Main Connectionpool's loop""" """Main Connectionpool's loop"""
# pylint: disable=too-many-locals
# defaults to empty loop if outbound connections are maxed # defaults to empty loop if outbound connections are maxed
spawnConnections = False spawnConnections = False
acceptConnections = True acceptConnections = True
@ -243,22 +175,19 @@ class BMConnectionPool(object):
'bitmessagesettings', 'socksproxytype', '') 'bitmessagesettings', 'socksproxytype', '')
onionsocksproxytype = BMConfigParser().safeGet( onionsocksproxytype = BMConfigParser().safeGet(
'bitmessagesettings', 'onionsocksproxytype', '') 'bitmessagesettings', 'onionsocksproxytype', '')
if ( if (socksproxytype[:5] == 'SOCKS' and
socksproxytype[:5] == 'SOCKS' not BMConfigParser().safeGetBoolean(
and not BMConfigParser().safeGetBoolean( 'bitmessagesettings', 'sockslisten') and
'bitmessagesettings', 'sockslisten') '.onion' not in BMConfigParser().safeGet(
and '.onion' not in BMConfigParser().safeGet( 'bitmessagesettings', 'onionhostname', '')):
'bitmessagesettings', 'onionhostname', '')
):
acceptConnections = False acceptConnections = False
# pylint: disable=too-many-nested-blocks # pylint: disable=too-many-nested-blocks
if spawnConnections: if spawnConnections:
if not knownnodes.knownNodesActual: if not knownnodes.knownNodesActual:
self.startBootstrappers() helper_bootstrap.dns()
knownnodes.knownNodesActual = True if not self.bootstrapped:
if not self._bootstrapped: self.bootstrapped = True
self._bootstrapped = True
Proxy.proxy = ( Proxy.proxy = (
BMConfigParser().safeGet( BMConfigParser().safeGet(
'bitmessagesettings', 'sockshostname'), 'bitmessagesettings', 'sockshostname'),
@ -287,7 +216,7 @@ class BMConnectionPool(object):
for i in range( for i in range(
state.maximumNumberOfHalfOpenConnections - pending): state.maximumNumberOfHalfOpenConnections - pending):
try: try:
chosen = self.trustedPeer or chooseConnection( chosen = chooseConnection(
helper_random.randomchoice(self.streams)) helper_random.randomchoice(self.streams))
except ValueError: except ValueError:
continue continue
@ -298,22 +227,10 @@ class BMConnectionPool(object):
# don't connect to self # don't connect to self
if chosen in state.ownAddresses: if chosen in state.ownAddresses:
continue continue
# don't connect to the hosts from the same
# network group, defense against sibyl attacks
host_network_group = protocol.network_group(
chosen.host)
same_group = False
for j in self.outboundConnections.values():
if host_network_group == j.network_group:
same_group = True
if chosen.host == j.destination.host:
knownnodes.decreaseRating(chosen)
break
if same_group:
continue
try: try:
if chosen.host.endswith(".onion") and Proxy.onion_proxy: if (chosen.host.endswith(".onion") and
Proxy.onion_proxy is not None):
if onionsocksproxytype == "SOCKS5": if onionsocksproxytype == "SOCKS5":
self.addConnection(Socks5BMConnection(chosen)) self.addConnection(Socks5BMConnection(chosen))
elif onionsocksproxytype == "SOCKS4a": elif onionsocksproxytype == "SOCKS4a":
@ -328,9 +245,12 @@ class BMConnectionPool(object):
if e.errno == errno.ENETUNREACH: if e.errno == errno.ENETUNREACH:
continue continue
self._lastSpawned = time.time() self.lastSpawned = time.time()
else: else:
for i in self.connections(): for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
# FIXME: rating will be increased after next connection # FIXME: rating will be increased after next connection
i.handle_close() i.handle_close()
@ -340,7 +260,7 @@ class BMConnectionPool(object):
self.startListening() self.startListening()
else: else:
for bind in re.sub( for bind in re.sub(
r'[^\w.]+', ' ', '[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
BMConfigParser().safeGet('network', 'bind') BMConfigParser().safeGet('network', 'bind')
).split(): ).split():
self.startListening(bind) self.startListening(bind)
@ -350,7 +270,7 @@ class BMConnectionPool(object):
self.startUDPSocket() self.startUDPSocket()
else: else:
for bind in re.sub( for bind in re.sub(
r'[^\w.]+', ' ', '[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
BMConfigParser().safeGet('network', 'bind') BMConfigParser().safeGet('network', 'bind')
).split(): ).split():
self.startUDPSocket(bind) self.startUDPSocket(bind)
@ -368,13 +288,16 @@ class BMConnectionPool(object):
i.accepting = i.connecting = i.connected = False i.accepting = i.connecting = i.connected = False
logger.info('Stopped udp sockets.') logger.info('Stopped udp sockets.')
loopTime = float(self._spawnWait) loopTime = float(self.spawnWait)
if self._lastSpawned < time.time() - self._spawnWait: if self.lastSpawned < time.time() - self.spawnWait:
loopTime = 2.0 loopTime = 2.0
asyncore.loop(timeout=loopTime, count=1000) asyncore.loop(timeout=loopTime, count=1000)
reaper = [] reaper = []
for i in self.connections(): for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
minTx = time.time() - 20 minTx = time.time() - 20
if i.fullyEstablished: if i.fullyEstablished:
minTx -= 300 - 20 minTx -= 300 - 20
@ -386,8 +309,10 @@ class BMConnectionPool(object):
time.time() - i.lastTx) time.time() - i.lastTx)
i.set_state("close") i.set_state("close")
for i in ( for i in (
self.connections() self.inboundConnections.values() +
+ self.listeningSockets.values() + self.udpSockets.values() self.outboundConnections.values() +
self.listeningSockets.values() +
self.udpSockets.values()
): ):
if not (i.accepting or i.connecting or i.connected): if not (i.accepting or i.connecting or i.connected):
reaper.append(i) reaper.append(i)

Some files were not shown because too many files have changed in this diff Show More