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
docs/_*/*
docs/autodoc/
build
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:
- build-essential
- libcap-dev
- tor
install:
- pip install -r requirements.txt
- ln -s src pybitmessage # tests environment

View File

@ -1,5 +1,5 @@
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 this software and associated documentation files (the "Software"), to deal

51
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License (MIT)
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
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 is Licensed under FreeBSD License.
qidenticon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html)
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>
identicon.py is Licensed under FreeBSD License.
identicon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html)
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.
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
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
separate issue.
features, it is recommended that you first solicit feedback on the DevTalk
pseudo-mailing list:
BM-2D9QKN4teYRvoq2fyzpiftPh9WP9qggtzh
Feel welcome to join chan "bitmessage", BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY
which is on preview here: https://beamstat.com/chan/bitmessage
References
----------

View File

@ -1,6 +1,6 @@
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:
@ -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 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.

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
"""
Check dependencies and give recommendations about how to satisfy them
Check dependendies and give recommendations about how to satisfy them
Limitations:
@ -164,7 +164,7 @@ if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
if not compiler:
compilerToPackages()
prereqToPackages()
if prereqs and mandatory:
if mandatory:
sys.exit(1)
else:
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.
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
-- 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 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/pyelliptic'))
from importlib import import_module
import version # noqa:E402
import version
# -- Project information -----------------------------------------------------
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'
# The short X.Y version
@ -39,18 +50,15 @@ release = version
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage', # FIXME: unused
'sphinx.ext.imgmath', # legacy unused
# 'sphinx.ext.doctest', # Currently disabled due to bad doctests
'sphinx.ext.intersphinx',
'sphinx.ext.linkcode',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinxcontrib.apidoc',
'sphinx.ext.coverage',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'm2r',
]
default_role = 'obj'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@ -67,29 +75,23 @@ master_doc = 'index'
#
# This is also used if you do content translation via gettext catalogs.
# 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
# directories to ignore when looking for source files.
# 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.
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 -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# 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
# 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".
html_static_path = ['_static']
html_css_files = [
'custom.css',
]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
@ -116,7 +114,10 @@ html_css_files = [
#
# html_sidebars = {}
html_show_sourcelink = False
# Deal with long lines in source view
html_theme_options = {
'page_width': '1366px',
}
# -- Options for HTMLHelp output ---------------------------------------------
@ -198,74 +199,10 @@ epub_exclude_files = ['search.html']
# -- 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 ---------------------------------------
# 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 ----------------------------------------------

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
- 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.
* Use separate addresses for different purposes
* Use separate addresses for different puprose
* 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.

View File

@ -11,17 +11,17 @@ Bitmessage makes use of fabric_ to define tasks such as building documentation o
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
-------------
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
-------------
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.
@ -49,7 +49,7 @@ British vs American spelling
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.

View File

@ -1,8 +1,8 @@
Processes
=========
In order to keep the Bitmessage project running, the team runs a number of systems and accounts that form the
development pipeline and continuous delivery process. We are always striving to improve this process. Towards
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 the process. Towards
that end it is documented here.
@ -20,7 +20,7 @@ Our official Github_ account is Bitmessage. Our issue tracker is here as well.
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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
# 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
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:
* 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
* 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

View File

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

View File

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

View File

@ -17,7 +17,13 @@ EXTRAS_REQUIRE = {
'qrcode': ['qrcode'],
'sound;platform_system=="Windows"': ['winsound'],
'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.plugins',
'pybitmessage.pyelliptic',
'pybitmessage.socks',
'pybitmessage.storage'
]
@ -149,9 +156,5 @@ if __name__ == "__main__":
# ]
},
scripts=['src/pybitmessage'],
cmdclass={'install': InstallCmd},
command_options={
'build_sphinx': {
'source_dir': ('setup.py', 'docs')}
}
cmdclass={'install': InstallCmd}
)

View File

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

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@ from addresses import decodeAddress, addBMIfNotPresent
import shared
from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser
import defaults
import namecoin
from messageview import MessageView
from migrationwizard import Ui_MigrationWizard
@ -30,12 +31,15 @@ from foldertree import (
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
MessageList_AddressWidget, MessageList_SubjectWidget,
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress)
from settings import Ui_settingsDialog
import settingsmixin
import support
import debug
from helper_ackPayload import genAckPayload
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
import helper_search
import l10n
import openclpow
from utils import str_broadcast_subscribers, avatarize
from account import (
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
@ -43,15 +47,16 @@ from account import (
import dialogs
from network.stats import pendingDownload, pendingUpload
from uisignaler import UISignaler
import knownnodes
import paths
from proofofwork import getPowType
import queues
import shutdown
import state
from statusbar import BMStatusBar
from network.asyncore_pollchoose import set_rates
import sound
# This is needed for tray icon
import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
try:
from plugins.plugin import get_plugin, get_plugins
@ -59,6 +64,49 @@ except ImportError:
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
def powQueueSize():
"""Returns the size of queues.workerQueue including current unfinished work"""
@ -74,6 +122,9 @@ def powQueueSize():
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
maxSoundFrequencySec = 60
@ -81,58 +132,6 @@ class MyForm(settingsmixin.SMainWindow):
REPLY_TYPE_CHAN = 1
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):
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL(
"triggered()"), self.quit)
@ -606,13 +605,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui = Ui_MainWindow()
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
# have any.
for addressInKeysFile in getSortedAccounts():
@ -628,9 +620,22 @@ class MyForm(settingsmixin.SMainWindow):
BMConfigParser().remove_section(addressInKeysFile)
BMConfigParser().save()
self.updateStartOnLogon()
self.change_translation()
# 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)
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
self.recurDepth = 0
@ -781,9 +786,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.treeWidgetSubscriptions.keyPressEvent = self.treeWidgetKeyPressEvent
self.ui.treeWidgetChans.keyPressEvent = self.treeWidgetKeyPressEvent
# Key press in addressbook
self.ui.tableWidgetAddressBook.keyPressEvent = self.addressbookKeyPressEvent
# Key press in messagelist
self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetKeyPressEvent
self.ui.tableWidgetInboxSubscriptions.keyPressEvent = self.tableWidgetKeyPressEvent
@ -826,28 +828,6 @@ class MyForm(settingsmixin.SMainWindow):
finally:
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):
TTL = int(sliderPosition ** 3.199 + 3600)
self.updateHumanFriendlyTTLDescription(TTL)
@ -1453,15 +1433,6 @@ class MyForm(settingsmixin.SMainWindow):
def treeWidgetKeyPressEvent(self, event):
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
def tableWidgetKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentMessagelist())
@ -1470,12 +1441,11 @@ class MyForm(settingsmixin.SMainWindow):
def textEditKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentMessageTextedit())
def handleKeyPress(self, event, focus=None):
"""This method handles keypress events for all widgets on MyForm"""
def handleKeyPress(self, event, focus = None):
messagelist = self.getCurrentMessagelist()
folder = self.getCurrentFolder()
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":
self.on_action_SentTrash()
else:
@ -1511,17 +1481,17 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.lineEditTo.setFocus()
event.ignore()
elif event.key() == QtCore.Qt.Key_F:
searchline = self.getCurrentSearchLine(retObj=True)
searchline = self.getCurrentSearchLine(retObj = True)
if searchline:
searchline.setFocus()
event.ignore()
if not event.isAccepted():
return
if isinstance(focus, MessageView):
if isinstance (focus, MessageView):
return MessageView.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTableWidget):
elif isinstance (focus, QtGui.QTableWidget):
return QtGui.QTableWidget.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTreeWidget):
elif isinstance (focus, QtGui.QTreeWidget):
return QtGui.QTreeWidget.keyPressEvent(focus, event)
# menu button 'manage keys'
@ -1652,6 +1622,7 @@ class MyForm(settingsmixin.SMainWindow):
# The window state has just been changed to
# Normal/Maximised/FullScreen
pass
# QtGui.QWidget.changeEvent(self, event)
def __icon_activated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
@ -2463,7 +2434,225 @@ class MyForm(settingsmixin.SMainWindow):
dialogs.AboutDialog(self).exec_()
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):
"""Send message to current selected address"""
@ -3204,7 +3393,8 @@ class MyForm(settingsmixin.SMainWindow):
0].row()
item = self.ui.tableWidgetAddressBook.item(currentRow, 0)
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.rerenderMessagelistFromLabels()
self.rerenderMessagelistToLabels()
@ -4063,6 +4253,237 @@ class MyForm(settingsmixin.SMainWindow):
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
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
@ -4137,6 +4558,7 @@ def init():
def run():
global myapp
app = init()
change_translation(l10n.getTranslationLanguage())
app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm()

View File

@ -46,7 +46,7 @@
<item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_2">
<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 name="alignment">
<set>Qt::AlignLeft</set>

View File

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

View File

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

View File

@ -1,584 +1,630 @@
import ConfigParser
import os
import sys
# -*- coding: utf-8 -*-
# pylint: disable=too-many-instance-attributes,too-many-locals,too-many-statements,attribute-defined-outside-init
"""
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
import debug
import defaults
import knownnodes
import namecoin
import openclpow
import paths
import queues
import shared
import state
import tempfile
import widgets
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network.asyncore_pollchoose import set_rates
from tr import _translate
from . import bitmessage_icons_rc # pylint: disable=unused-import
from .languagebox import LanguageBox
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
def getSOCKSProxyType(config):
"""Get user socksproxytype setting from *config*"""
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
class Ui_settingsDialog(object):
"""Encapsulate a UI settings dialog object"""
def setupUi(self, settingsDialog):
"""Set up the UI"""
class SettingsDialog(QtGui.QDialog):
"""The "Settings" dialog"""
def __init__(self, parent=None, firstrun=False):
super(SettingsDialog, self).__init__(parent)
widgets.load('settings.ui', self)
self.parent = parent
self.firstrun = firstrun
self.config = BMConfigParser()
self.net_restart_needed = False
self.timer = QtCore.QTimer()
try:
import pkg_resources
except ImportError:
pass
else:
# Append proxy types defined in plugins
for ep in pkg_resources.iter_entry_points(
'bitmessage.proxyconfig'):
self.comboBoxProxyType.addItem(ep.name)
settingsDialog.setObjectName(_fromUtf8("settingsDialog"))
settingsDialog.resize(521, 413)
self.gridLayout = QtGui.QGridLayout(settingsDialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.buttonBox = QtGui.QDialogButtonBox(settingsDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.tabWidgetSettings = QtGui.QTabWidget(settingsDialog)
self.tabWidgetSettings.setObjectName(_fromUtf8("tabWidgetSettings"))
self.tabUserInterface = QtGui.QWidget()
self.tabUserInterface.setEnabled(True)
self.tabUserInterface.setObjectName(_fromUtf8("tabUserInterface"))
self.formLayout = QtGui.QFormLayout(self.tabUserInterface)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
self.checkBoxStartOnLogon = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxStartOnLogon.setObjectName(_fromUtf8("checkBoxStartOnLogon"))
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.checkBoxStartOnLogon)
self.groupBoxTray = QtGui.QGroupBox(self.tabUserInterface)
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(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
self.adjust_from_config(self.config)
if firstrun:
# switch to "Network Settings" tab if user selected
# "Let me configure special network settings first" on first run
self.tabWidgetSettings.setCurrentIndex(
self.tabWidgetSettings.indexOf(self.tabNetworkSettings)
)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def adjust_from_config(self, config):
"""Adjust all widgets state according to config settings"""
# pylint: disable=too-many-branches,too-many-statements
if not self.parent.tray.isSystemTrayAvailable():
self.groupBoxTray.setEnabled(False)
self.groupBoxTray.setTitle(_translate(
"MainWindow", "Tray (not available in your system)"))
for setting in (
'minimizetotray', 'trayonclose', 'startintray'):
config.set('bitmessagesettings', setting, 'false')
self.gridLayout_9.addWidget(self.lineEditMaxOutboundConnections, 2, 2, 1, 1)
self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1)
self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
self.gridLayout_2 = QtGui.QGridLayout(self.groupBox_2)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.label_2 = QtGui.QLabel(self.groupBox_2)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1)
self.label_3 = QtGui.QLabel(self.groupBox_2)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.gridLayout_2.addWidget(self.label_3, 1, 1, 1, 1)
self.lineEditSocksHostname = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksHostname.setObjectName(_fromUtf8("lineEditSocksHostname"))
self.lineEditSocksHostname.setPlaceholderText(_fromUtf8("127.0.0.1"))
self.gridLayout_2.addWidget(self.lineEditSocksHostname, 1, 2, 1, 2)
self.label_4 = QtGui.QLabel(self.groupBox_2)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.gridLayout_2.addWidget(self.label_4, 1, 4, 1, 1)
self.lineEditSocksPort = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksPort.setObjectName(_fromUtf8("lineEditSocksPort"))
if platform in ['darwin', 'win32', 'win64']:
self.lineEditSocksPort.setPlaceholderText(_fromUtf8("9150"))
else:
self.checkBoxMinimizeToTray.setChecked(
config.getboolean('bitmessagesettings', 'minimizetotray'))
self.checkBoxTrayOnClose.setChecked(
config.safeGetBoolean('bitmessagesettings', 'trayonclose'))
self.checkBoxStartInTray.setChecked(
config.getboolean('bitmessagesettings', 'startintray'))
self.checkBoxHideTrayConnectionNotifications.setChecked(
config.getboolean(
'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.lineEditSocksPort.setPlaceholderText(_fromUtf8("9050"))
self.gridLayout_2.addWidget(self.lineEditSocksPort, 1, 5, 1, 1)
self.checkBoxAuthentication = QtGui.QCheckBox(self.groupBox_2)
self.checkBoxAuthentication.setObjectName(_fromUtf8("checkBoxAuthentication"))
self.gridLayout_2.addWidget(self.checkBoxAuthentication, 2, 1, 1, 1)
self.label_5 = QtGui.QLabel(self.groupBox_2)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.gridLayout_2.addWidget(self.label_5, 2, 2, 1, 1)
self.lineEditSocksUsername = QtGui.QLineEdit(self.groupBox_2)
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.checkBoxAuthentication.setEnabled(False)
self.checkBoxSocksListen.setEnabled(False)
self.checkBoxOnionOnly.setEnabled(False)
else:
self.lineEditSocksHostname.setEnabled(True)
self.lineEditSocksPort.setEnabled(True)
self.checkBoxAuthentication.setEnabled(True)
self.checkBoxSocksListen.setEnabled(True)
self.checkBoxOnionOnly.setEnabled(True)
if self.checkBoxAuthentication.isChecked():
self.lineEditSocksUsername.setEnabled(True)
self.lineEditSocksPassword.setEnabled(True)
self.lineEditSocksPassword.setInputMethodHints(
QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText)
self.lineEditSocksPassword.setEchoMode(QtGui.QLineEdit.Password)
self.lineEditSocksPassword.setObjectName(_fromUtf8("lineEditSocksPassword"))
self.gridLayout_2.addWidget(self.lineEditSocksPassword, 2, 5, 1, 1)
self.checkBoxSocksListen = QtGui.QCheckBox(self.groupBox_2)
self.checkBoxSocksListen.setObjectName(_fromUtf8("checkBoxSocksListen"))
self.gridLayout_2.addWidget(self.checkBoxSocksListen, 3, 1, 1, 4)
self.comboBoxProxyType = QtGui.QComboBox(self.groupBox_2)
self.comboBoxProxyType.setObjectName(_fromUtf8("comboBoxProxyType")) # pylint: disable=not-callable
self.comboBoxProxyType.addItem(_fromUtf8(""))
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):
"""
Check status of namecoin integration radio buttons
and translate it to a string as in the options.
"""
if self.radioButtonNamecoinNamecoind.isChecked():
return "namecoind"
if self.radioButtonNamecoinNmcontrol.isChecked():
return "nmcontrol"
assert False
self.retranslateUi(settingsDialog)
self.tabWidgetSettings.setCurrentIndex(0)
QtCore.QObject.connect( # pylint: disable=no-member
self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept)
QtCore.QObject.connect( # pylint: disable=no-member
self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), settingsDialog.reject)
QtCore.QObject.connect( # pylint: disable=no-member
self.checkBoxAuthentication,
QtCore.SIGNAL(
_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 namecoinTypeChanged(self, checked): # pylint: disable=unused-argument
"""A callback for toggled event of radioButtonNamecoinNamecoind"""
nmctype = self.getNamecoinType()
assert nmctype == "namecoind" or nmctype == "nmcontrol"
def retranslateUi(self, settingsDialog):
"""Re-translate the UI into the supported languages"""
isNamecoind = (nmctype == "namecoind")
self.lineEditNamecoinUser.setEnabled(isNamecoind)
self.labelNamecoinUser.setEnabled(isNamecoind)
self.lineEditNamecoinPassword.setEnabled(isNamecoind)
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"),
settingsDialog.setWindowTitle(_translate("settingsDialog", "Settings", None))
self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None))
self.groupBoxTray.setTitle(_translate("settingsDialog", "Tray", None))
self.checkBoxStartInTray.setText(
_translate(
"MainWindow",
"Your maximum download and upload rate must be numbers."
" Ignoring what you typed.")
)
else:
set_rates(
self.config.safeGetInt('bitmessagesettings', 'maxdownloadrate'),
self.config.safeGetInt('bitmessagesettings', 'maxuploadrate'))
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"),
"settingsDialog",
"Start Bitmessage in the tray (don\'t show main window)",
None))
self.checkBoxMinimizeToTray.setText(_translate("settingsDialog", "Minimize to tray", None))
self.checkBoxTrayOnClose.setText(_translate("settingsDialog", "Close to tray", None))
self.checkBoxHideTrayConnectionNotifications.setText(
_translate("settingsDialog", "Hide connection notifications", None))
self.checkBoxShowTrayNotifications.setText(
_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.")
)
self.config.set(
'bitmessagesettings', 'stopresendingafterxdays', '0')
self.config.set(
'bitmessagesettings', 'stopresendingafterxmonths', '0')
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0
else:
self.config.set(
'bitmessagesettings', 'stopresendingafterxdays', str(days))
self.config.set(
'bitmessagesettings', 'stopresendingafterxmonths',
str(months))
self.config.save()
if self.net_restart_needed:
self.net_restart_needed = False
self.config.setTemp('bitmessagesettings', 'dontconnect', 'true')
self.timer.singleShot(
5000, lambda:
self.config.setTemp(
'bitmessagesettings', 'dontconnect', 'false')
)
self.parent.updateStartOnLogon()
if (
state.appdata != paths.lookupExeFolder() and
self.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:
self.config.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.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
self.config.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
"settingsDialog",
"Show notification when message received",
None))
self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", None))
self.PortableModeDescription.setText(
_translate(
"settingsDialog",
"In Portable Mode, messages and config files are stored in the same directory as the"
" program rather than the normal application-data folder. This makes it convenient to"
" run Bitmessage from a USB thumb drive.",
None))
self.checkBoxWillinglySendToMobile.setText(
_translate(
"settingsDialog",
"Willingly include unencrypted destination address when sending to a mobile device",
None))
self.checkBoxUseIdenticons.setText(_translate("settingsDialog", "Use Identicons", None))
self.checkBoxReplyBelow.setText(_translate("settingsDialog", "Reply below Quote", None))
self.groupBox.setTitle(_translate("settingsDialog", "Interface Language", None))
self.languageComboBox.setItemText(0, _translate("settingsDialog", "System Settings", "system"))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabUserInterface),
_translate(
"settingsDialog", "User Interface", None))
self.groupBox1.setTitle(_translate("settingsDialog", "Listening port", None))
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.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))
self.label_26.setText(_translate("settingsDialog", "Maximum outbound connections: [0: none]", None))
self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None))
self.label_2.setText(_translate("settingsDialog", "Type:", None))
self.label_3.setText(_translate("settingsDialog", "Server hostname:", None))
self.label_4.setText(_translate("settingsDialog", "Port:", None))
self.checkBoxAuthentication.setText(_translate("settingsDialog", "Authentication", None))
self.label_5.setText(_translate("settingsDialog", "Username:", None))
self.label_6.setText(_translate("settingsDialog", "Pass:", None))
self.checkBoxSocksListen.setText(
_translate(
"settingsDialog",
"Listen for incoming connections when using proxy",
None))
self.comboBoxProxyType.setItemText(0, _translate("settingsDialog", "none", None))
self.comboBoxProxyType.setItemText(1, _translate("settingsDialog", "SOCKS4a", None))
self.comboBoxProxyType.setItemText(2, _translate("settingsDialog", "SOCKS5", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabNetworkSettings),
_translate(
"settingsDialog", "Network Settings", None))
self.label_9.setText(_translate("settingsDialog", "Total difficulty:", None))
self.label_10.setText(
_translate(
"settingsDialog",
"The \'Total difficulty\' affects the absolute amount of work the sender must complete."
" Doubling this value doubles the amount of work.",
None))
self.label_11.setText(_translate("settingsDialog", "Small message difficulty:", None))
self.label_8.setText(_translate(
"settingsDialog",
"When someone sends you a message, their computer must first complete some work. The difficulty of this"
" work, by default, is 1. You may raise this default for new addresses you create by changing the values"
" here. Any new addresses you create will require senders to meet the higher difficulty. There is one"
" exception: if you add a friend or acquaintance to your address book, Bitmessage will automatically"
" notify them when you next send a message that they need only complete the minimum amount of"
" work: difficulty 1. ",
None))
self.label_12.setText(
_translate(
"settingsDialog",
"The \'Small message difficulty\' mostly only affects the difficulty of sending small messages."
" Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really"
" affect large messages.",
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>
</attribute>
<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">
<widget class="QCheckBox" name="checkBoxStartOnLogon">
<property name="text">
@ -56,43 +44,20 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBoxTray">
<property name="title">
<string>Tray</string>
</property>
<layout class="QVBoxLayout" name="formLayoutTray">
<item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxStartInTray">
<property name="text">
<string>Start Bitmessage in the tray (don't show main window)</string>
</property>
</widget>
</item>
<item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxMinimizeToTray">
<property name="text">
<string>Minimize to tray</string>
</property>
<property name="checked">
<bool>false</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>
<bool>true</bool>
</property>
</widget>
</item>
@ -152,15 +117,90 @@
<property name="title">
<string>Interface Language</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="LanguageBox" name="languageComboBox">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QComboBox" name="languageComboBox">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</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>
</item>
</layout>
@ -173,18 +213,6 @@
<string>Network Settings</string>
</attribute>
<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">
<widget class="QGroupBox" name="groupBox">
<property name="title">
@ -192,13 +220,26 @@
</property>
<layout class="QGridLayout" name="gridLayout_3">
<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">
<property name="text">
<string>Listen for connections on port:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QLineEdit" name="lineEditTCPPort">
<property name="maximumSize">
<size>
@ -208,26 +249,6 @@
</property>
</widget>
</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>
</widget>
</item>
@ -403,13 +424,6 @@
</property>
</widget>
</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">
<widget class="QComboBox" name="comboBoxProxyType">
<item>
@ -419,12 +433,12 @@
</item>
<item>
<property name="text">
<string notr="true">SOCKS4a</string>
<string>SOCKS4a</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">SOCKS5</string>
<string>SOCKS5</string>
</property>
</item>
</widget>
@ -452,18 +466,6 @@
<string>Demanded difficulty</string>
</attribute>
<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">
<widget class="QLabel" name="label_9">
<property name="text">
@ -592,18 +594,6 @@
<string>Max acceptable difficulty</string>
</attribute>
<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">
<widget class="QLabel" name="label_15">
<property name="text">
@ -708,33 +698,6 @@
</property>
</spacer>
</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>
</widget>
<widget class="QWidget" name="tabNamecoin">
@ -742,18 +705,6 @@
<string>Namecoin integration</string>
</attribute>
<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">
<spacer name="horizontalSpacer_6">
<property name="orientation">
@ -937,18 +888,6 @@
<string>Resends Expire</string>
</attribute>
<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">
<widget class="QLabel" name="label_7">
<property name="text">
@ -973,16 +912,22 @@
</spacer>
</item>
<item row="1" column="2">
<widget class="QGroupBox">
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>231</width>
<height>75</height>
</size>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<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">
<string>Give up after</string>
</property>
@ -990,9 +935,15 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<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">
<string>and</string>
</property>
@ -1000,42 +951,52 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditDays">
<property name="maximumSize">
<size>
<width>55</width>
<height>100</height>
</size>
<property name="geometry">
<rect>
<x>113</x>
<y>20</y>
<width>51</width>
<height>20</height>
</rect>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditMonths">
<property name="maximumSize">
<size>
<width>55</width>
<height>100</height>
</size>
<property name="geometry">
<rect>
<x>113</x>
<y>40</y>
<width>51</width>
<height>20</height>
</rect>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel">
<widget class="QLabel" name="label_22">
<property name="geometry">
<rect>
<x>169</x>
<y>23</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>days</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel">
<widget class="QLabel" name="label_23">
<property name="geometry">
<rect>
<x>170</x>
<y>41</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>months.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
@ -1056,14 +1017,7 @@
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LanguageBox</class>
<extends>QComboBox</extends>
<header>bitmessageqt.languagebox</header>
</customwidget>
</customwidgets>
</widget>
<tabstops>
<tabstop>tabWidgetSettings</tabstop>
<tabstop>checkBoxStartOnLogon</tabstop>
@ -1147,53 +1101,5 @@
</hint>
</hints>
</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>
</ui>

View File

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

View File

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

View File

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

View File

@ -1,26 +1,24 @@
"""
A thread for creating addresses
"""
import hashlib
import time
from binascii import hexlify
import defaults
import highlevelcrypto
import queues
import shared
import state
import tr
from addresses import decodeAddress, encodeAddress, encodeVarint
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash
from network import StoppableThread
import time
import hashlib
from binascii import hexlify
from pyelliptic import arithmetic
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):
"""A thread for creating addresses"""
name = "addressGenerator"
@ -32,12 +30,6 @@ class addressGenerator(StoppableThread):
super(addressGenerator, self).stopThread()
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:
queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0
@ -93,12 +85,12 @@ class addressGenerator(StoppableThread):
elif queueValue[0] == 'stopThread':
break
else:
self.logger.error(
logger.error(
'Programming error: A structure with the wrong number'
' of values was passed into the addressGeneratorQueue.'
' Here is the queueValue: %r\n', queueValue)
if addressVersionNumber < 3 or addressVersionNumber > 4:
self.logger.error(
logger.error(
'Program error: For some reason the address generator'
' queue has been given a request to create at least'
' one version %s address which it cannot do.\n',
@ -147,10 +139,10 @@ class addressGenerator(StoppableThread):
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
):
break
self.logger.info(
logger.info(
'Generated address with ripe digest: %s', hexlify(ripe))
try:
self.logger.info(
logger.info(
'Address generator calculated %s addresses at %s'
' addresses per second before finding one with'
' the correct ripe-prefix.',
@ -217,8 +209,8 @@ class addressGenerator(StoppableThread):
elif command == 'createDeterministicAddresses' \
or command == 'getDeterministicAddress' \
or command == 'createChan' or command == 'joinChan':
if not deterministicPassphrase:
self.logger.warning(
if len(deterministicPassphrase) == 0:
logger.warning(
'You are creating deterministic'
' address(es) using a blank passphrase.'
' Bitmessage will do it but it is rather stupid.')
@ -271,10 +263,10 @@ class addressGenerator(StoppableThread):
):
break
self.logger.info(
logger.info(
'Generated address with ripe digest: %s', hexlify(ripe))
try:
self.logger.info(
logger.info(
'Address generator calculated %s addresses'
' at %s addresses per second before finding'
' one with the correct ripe-prefix.',
@ -324,7 +316,7 @@ class addressGenerator(StoppableThread):
addressAlreadyExists = True
if addressAlreadyExists:
self.logger.info(
logger.info(
'%s already exists. Not adding it again.',
address
)
@ -337,7 +329,7 @@ class addressGenerator(StoppableThread):
).arg(address)
))
else:
self.logger.debug('label: %s', label)
logger.debug('label: %s', label)
BMConfigParser().set(address, 'label', label)
BMConfigParser().set(address, 'enabled', 'true')
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 logging
import random
import shared
import threading
import time
from binascii import hexlify
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_inbox
import helper_msgcoding
import helper_sent
import highlevelcrypto
import knownnodes
import l10n
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from helper_ackPayload import genAckPayload
from network import bmproto
import protocol
import queues
import shared
import state
import tr
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint,
encodeAddress, encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
from debug import logger
from fallback import RIPEMD160Hash
from helper_ackPayload import genAckPayload
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')
import l10n
class objectProcessor(threading.Thread):
@ -65,7 +55,6 @@ class objectProcessor(threading.Thread):
self.successfullyDecryptMessageTimings = []
def run(self):
"""Process the objects from `.queues.objectProcessorQueue`"""
while True:
objectType, data = queues.objectProcessorQueue.get()
@ -129,10 +118,7 @@ class objectProcessor(threading.Thread):
state.shutdown = 2
break
@staticmethod
def checkackdata(data):
"""Checking Acknowledgement of message received or not?"""
# pylint: disable=protected-access
def checkackdata(self, data):
# Let's check whether this is a message acknowledgement bound for us.
if len(data) < 32:
return
@ -149,13 +135,11 @@ class objectProcessor(threading.Thread):
'ackreceived', int(time.time()), data[readPosition:])
queues.UISignalQueue.put((
'updateSentItemStatusByAckdata',
(
data[readPosition:],
(data[readPosition:],
tr._translate(
"MainWindow",
"Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp())
)
).arg(l10n.formatTimestamp()))
))
else:
logger.debug('This object is not an acknowledgement bound for me.')
@ -174,7 +158,7 @@ class objectProcessor(threading.Thread):
if not host:
return
peer = Peer(host, port)
peer = state.Peer(host, port)
with knownnodes.knownNodesLock:
knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer))
@ -284,7 +268,6 @@ class objectProcessor(threading.Thread):
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
def processpubkey(self, data):
"""Process a pubkey object"""
pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1
queues.UISignalQueue.put((
@ -333,7 +316,6 @@ class objectProcessor(threading.Thread):
'\x04' + publicSigningKey + '\x04' + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s'
@ -398,7 +380,6 @@ class objectProcessor(threading.Thread):
sha.update(publicSigningKey + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s'
@ -457,7 +438,6 @@ class objectProcessor(threading.Thread):
timeRequiredToProcessPubkey)
def processmsg(self, data):
"""Process a message object"""
messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1
queues.UISignalQueue.put((
@ -599,7 +579,6 @@ class objectProcessor(threading.Thread):
logger.debug('ECDSA verify failed')
return
logger.debug('ECDSA verify passed')
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
'As a matter of intellectual curiosity, here is the Bitcoin'
' address associated with the keys owned by the other person:'
@ -647,8 +626,7 @@ class objectProcessor(threading.Thread):
if decodeAddress(toAddress)[1] >= 3 \
and not BMConfigParser().safeGetBoolean(toAddress, 'chan'):
# If I'm not friendly with this person:
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(
fromAddress):
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(fromAddress):
requiredNonceTrialsPerByte = BMConfigParser().getint(
toAddress, 'noncetrialsperbyte')
requiredPayloadLengthExtraBytes = BMConfigParser().getint(
@ -754,7 +732,7 @@ class objectProcessor(threading.Thread):
# We really should have a discussion about how to
# set the TTL for mailing list broadcasts. This is obviously
# hard-coded.
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
TTL = 2*7*24*60*60 # 2 weeks
t = ('',
toAddress,
ripe,
@ -806,7 +784,6 @@ class objectProcessor(threading.Thread):
)
def processbroadcast(self, data):
"""Process a broadcast object"""
messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1
queues.UISignalQueue.put((
@ -991,7 +968,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress(
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.
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
@ -1008,7 +985,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe)
logger.debug('fromAddress: %s', fromAddress)
logger.debug('fromAddress: ' + fromAddress)
try:
decodedMessage = helper_msgcoding.MsgDecode(
@ -1069,18 +1046,17 @@ class objectProcessor(threading.Thread):
# for it.
elif addressVersion >= 4:
tag = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) + encodeVarint(streamNumber)
+ ripe
encodeVarint(addressVersion) + encodeVarint(streamNumber) + ripe
).digest()).digest()[32:]
if tag in state.neededPubkeys:
del state.neededPubkeys[tag]
self.sendMessages(address)
@staticmethod
def sendMessages(address):
def sendMessages(self, address):
"""
This method is called by the `possibleNewPubkey` when it sees
that we now have the necessary pubkey to send one or more messages.
This function is called by the possibleNewPubkey function when
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.')
sqlExecute(
@ -1090,9 +1066,7 @@ class objectProcessor(threading.Thread):
" AND folder='sent'", address)
queues.workerQueue.put(('sendmessage', ''))
@staticmethod
def ackDataHasAValidHeader(ackData):
"""Checking ackData with valid Header, not sending ackData when false"""
def ackDataHasAValidHeader(self, ackData):
if len(ackData) < protocol.Header.size:
logger.info(
'The length of ackData is unreasonably short. Not sending'
@ -1127,12 +1101,11 @@ class objectProcessor(threading.Thread):
return False
return True
@staticmethod
def addMailingListNameToSubject(subject, mailingListName):
"""Adding mailingListName to subject"""
def addMailingListNameToSubject(self, subject, mailingListName):
subject = subject.strip()
if subject[:3] == 'Re:' or subject[:3] == 'RE:':
subject = subject[3:].strip()
if '[' + mailingListName + ']' in subject:
return subject
else:
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
sends pong messages to keep connections alive if the network isn't busy.
It cleans these data structures in memory:
- inventory (moves data to the on-disk sql database)
- inventorySets (clears then reloads data out of sql database)
inventory (moves data to the on-disk sql database)
inventorySets (clears then reloads data out of sql database)
It cleans these tables on the disk:
- inventory (clears expired objects)
- pubkeys (clears pubkeys older than 4 weeks old which we have not used
inventory (clears expired objects)
pubkeys (clears pubkeys older than 4 weeks old which we have not used
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:
- 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 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...)
"""
import gc
import os
import shared
import time
import knownnodes
import queues
import shared
import state
import tr
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 network import BMConnectionPool, StoppableThread
from network.connectionpool import BMConnectionPool
from debug import logger
import knownnodes
import queues
import state
class singleCleaner(StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner"
cycleLength = 300
expireDiscoveredPeers = 300
def run(self): # pylint: disable=too-many-branches
def run(self):
gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0
try:
shared.maximumLengthOfTimeToBotherResendingMessages = (
float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxdays'))
* 24 * 60 * 60
'bitmessagesettings', 'stopresendingafterxdays')) *
24 * 60 * 60
) + (
float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxmonths'))
* (60 * 60 * 24 * 365) / 12)
'bitmessagesettings', 'stopresendingafterxmonths')) *
(60 * 60 * 24 * 365) / 12)
except:
# Either the user hasn't set stopresendingafterxdays and
# stopresendingafterxmonths yet or the options are missing
@ -93,12 +93,12 @@ class singleCleaner(StoppableThread):
"SELECT toaddress, ackdata, status FROM sent"
" WHERE ((status='awaitingpubkey' OR status='msgsent')"
" AND folder='sent' AND sleeptill<? AND senttime>?)",
int(time.time()), int(time.time())
- shared.maximumLengthOfTimeToBotherResendingMessages
int(time.time()), int(time.time()) -
shared.maximumLengthOfTimeToBotherResendingMessages
)
for row in queryreturn:
if len(row) < 2:
self.logger.error(
logger.error(
'Something went wrong in the singleCleaner thread:'
' a query did not return the requested fields. %r',
row
@ -107,18 +107,17 @@ class singleCleaner(StoppableThread):
break
toAddress, ackData, status = row
if status == 'awaitingpubkey':
self.resendPubkeyRequest(toAddress)
resendPubkeyRequest(toAddress)
elif status == 'msgsent':
self.resendMsg(ackData)
resendMsg(ackData)
try:
# Cleanup knownnodes and handle possible severe exception
# while writing it to disk
knownnodes.cleanupKnownNodes()
except Exception as err:
# pylint: disable=protected-access
if "Errno 28" in str(err):
self.logger.fatal(
logger.fatal(
'(while writing knownnodes to disk)'
' Alert: Your disk or data storage volume is full.'
)
@ -131,11 +130,19 @@ class singleCleaner(StoppableThread):
' is full. Bitmessage will now exit.'),
True)
))
if shared.thisapp.daemon or not state.enableGUI:
# FIXME redundant?
if shared.daemon or not state.enableGUI:
os._exit(1)
# # clear download queues
# for thread in threading.enumerate():
# if thread.isAlive() and hasattr(thread, 'downloadQueue'):
# thread.downloadQueue.clear()
# inv/object tracking
for connection in BMConnectionPool().connections():
for connection in \
BMConnectionPool().inboundConnections.values() + \
BMConnectionPool().outboundConnections.values():
connection.clean()
# discovery tracking
@ -146,16 +153,16 @@ class singleCleaner(StoppableThread):
del state.discoveredPeers[k]
except KeyError:
pass
# ..todo:: cleanup pending upload / download
# TODO: cleanup pending upload / download
gc.collect()
if state.shutdown == 0:
self.stop.wait(singleCleaner.cycleLength)
def resendPubkeyRequest(self, address):
"""Resend pubkey request for address"""
self.logger.debug(
def resendPubkeyRequest(address):
logger.debug(
'It has been a long time and we haven\'t heard a response to our'
' getpubkey request. Sending again.'
)
@ -177,9 +184,9 @@ class singleCleaner(StoppableThread):
address)
queues.workerQueue.put(('sendmessage', ''))
def resendMsg(self, ackdata):
"""Resend message by ackdata"""
self.logger.debug(
def resendMsg(ackdata):
logger.debug(
'It has been a long time and we haven\'t heard an acknowledgement'
' 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=no-self-use,too-many-lines,too-many-locals
# pylint: disable=protected-access,too-many-branches,too-many-statements,no-self-use,too-many-lines,too-many-locals
from __future__ import division
@ -24,13 +24,12 @@ import queues
import shared
import state
import tr
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
)
from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
from bmconfigparser import BMConfigParser
from debug import logger
from helper_sql import sqlExecute, sqlQuery
from helper_threading import StoppableThread
from inventory import Inventory
from network import StoppableThread
def sizeof_fmt(num, suffix='h/s'):
@ -99,7 +98,7 @@ class singleWorker(StoppableThread):
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
for row in queryreturn:
ackdata, = row
self.logger.info('Watching for ackdata %s', hexlify(ackdata))
logger.info('Watching for ackdata %s', hexlify(ackdata))
shared.ackdataForWhichImWatching[ackdata] = 0
# Fix legacy (headerless) watched ackdata to include header
@ -174,14 +173,14 @@ class singleWorker(StoppableThread):
self.busy = 0
return
else:
self.logger.error(
logger.error(
'Probable programming error: The command sent'
' to the workerThread is weird. It is: %s\n',
command
)
queues.workerQueue.task_done()
self.logger.info("Quitting...")
logger.info("Quitting...")
def _getKeysForAddress(self, address):
privSigningKeyBase58 = BMConfigParser().get(
@ -218,34 +217,33 @@ class singleWorker(StoppableThread):
)) / (2 ** 16))
))
initialHash = hashlib.sha512(payload).digest()
self.logger.info(
logger.info(
'%s Doing proof of work... TTL set to %s', log_prefix, TTL)
if log_time:
start_time = time.time()
trialValue, nonce = proofofwork.run(target, initialHash)
self.logger.info(
logger.info(
'%s Found proof of work %s Nonce: %s',
log_prefix, trialValue, nonce
)
try:
delta = time.time() - start_time
self.logger.info(
logger.info(
'PoW took %.1f seconds, speed %s.',
delta, sizeof_fmt(nonce / delta)
)
except: # NameError
pass
payload = pack('>Q', nonce) + payload
# inventoryHash = calculateInventoryHash(payload)
return payload
def doPOWForMyV2Pubkey(self, adressHash):
""" This function also broadcasts out the pubkey
message once it is done with the POW"""
""" This function also broadcasts out the pubkey message once it is done with the POW"""
# Look up my stream number based on my address hash
myAddress = shared.myAddressesByHash[adressHash]
# status
_, addressVersionNumber, streamNumber, adressHash = (
decodeAddress(myAddress))
_, addressVersionNumber, streamNumber, adressHash = decodeAddress(myAddress)
# 28 days from now plus or minus five minutes
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
@ -262,7 +260,7 @@ class singleWorker(StoppableThread):
_, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress)
except Exception as err:
self.logger.error(
logger.error(
'Error within doPOWForMyV2Pubkey. Could not read'
' the keys from the keys.dat file for a requested'
' address. %s\n', err
@ -280,8 +278,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '')
self.logger.info(
'broadcasting inv with hash: %s', hexlify(inventoryHash))
logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', ''))
@ -306,7 +303,7 @@ class singleWorker(StoppableThread):
# The address has been deleted.
return
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
_, addressVersionNumber, streamNumber, adressHash = decodeAddress(
myAddress)
@ -336,7 +333,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress)
except Exception as err:
self.logger.error(
logger.error(
'Error within sendOutOrStoreMyV3Pubkey. Could not read'
' the keys from the keys.dat file for a requested'
' address. %s\n', err
@ -363,8 +360,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '')
self.logger.info(
'broadcasting inv with hash: %s', hexlify(inventoryHash))
logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', ''))
@ -387,7 +383,7 @@ class singleWorker(StoppableThread):
# The address has been deleted.
return
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
_, addressVersionNumber, streamNumber, addressHash = decodeAddress(
myAddress)
@ -406,7 +402,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress)
except Exception as err:
self.logger.error(
logger.error(
'Error within sendOutOrStoreMyV4Pubkey. Could not read'
' the keys from the keys.dat file for a requested'
' address. %s\n', err
@ -454,8 +450,7 @@ class singleWorker(StoppableThread):
doubleHashOfAddressData[32:]
)
self.logger.info(
'broadcasting inv with hash: %s', hexlify(inventoryHash))
logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', ''))
@ -464,7 +459,7 @@ class singleWorker(StoppableThread):
myAddress, 'lastpubkeysendtime', str(int(time.time())))
BMConfigParser().save()
except Exception as err:
self.logger.error(
logger.error(
'Error: Couldn\'t add the lastpubkeysendtime'
' to the keys.dat file. Error message: %s', err
)
@ -502,7 +497,7 @@ class singleWorker(StoppableThread):
objectType, streamNumber, buffer(payload),
embeddedTime, buffer(tag)
)
self.logger.info(
logger.info(
'sending inv (within sendOnionPeerObj function) for object: %s',
hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash))
@ -525,7 +520,7 @@ class singleWorker(StoppableThread):
_, addressVersionNumber, streamNumber, ripe = \
decodeAddress(fromaddress)
if addressVersionNumber <= 1:
self.logger.error(
logger.error(
'Error: In the singleWorker thread, the '
' sendBroadcast function doesn\'t understand'
' the address version.\n')
@ -641,7 +636,7 @@ class singleWorker(StoppableThread):
# to not let the user try to send a message this large
# until we implement message continuation.
if len(payload) > 2 ** 18: # 256 KiB
self.logger.critical(
logger.critical(
'This broadcast object is too large to send.'
' This should never happen. Object size: %s',
len(payload)
@ -652,7 +647,7 @@ class singleWorker(StoppableThread):
objectType = 3
Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, tag)
self.logger.info(
logger.info(
'sending inv (within sendBroadcast function)'
' for object: %s',
hexlify(inventoryHash)
@ -872,8 +867,8 @@ class singleWorker(StoppableThread):
"MainWindow",
"Looking up the receiver\'s public key"))
))
self.logger.info('Sending a message.')
self.logger.debug(
logger.info('Sending a message.')
logger.debug(
'First 150 characters of message: %s',
repr(message[:150])
)
@ -917,7 +912,7 @@ class singleWorker(StoppableThread):
if not shared.BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile'
):
self.logger.info(
logger.info(
'The receiver is a mobile user but the'
' sender (you) has not selected that you'
' are willing to send to mobiles. Aborting'
@ -983,7 +978,7 @@ class singleWorker(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes:
requiredPayloadLengthExtraBytes = \
defaults.networkDefaultPayloadLengthExtraBytes
self.logger.debug(
logger.debug(
'Using averageProofOfWorkNonceTrialsPerByte: %s'
' and payloadLengthExtraBytes: %s.',
requiredAverageProofOfWorkNonceTrialsPerByte,
@ -1048,9 +1043,8 @@ class singleWorker(StoppableThread):
l10n.formatTimestamp()))))
continue
else: # if we are sending a message to ourselves or a chan..
self.logger.info('Sending a message.')
self.logger.debug(
'First 150 characters of message: %r', message[:150])
logger.info('Sending a message.')
logger.debug('First 150 characters of message: %r', message[:150])
behaviorBitfield = protocol.getBitfield(fromaddress)
try:
@ -1069,7 +1063,7 @@ class singleWorker(StoppableThread):
" message. %1"
).arg(l10n.formatTimestamp()))
))
self.logger.error(
logger.error(
'Error within sendMsg. Could not read the keys'
' from the keys.dat file for our own address. %s\n',
err)
@ -1145,14 +1139,14 @@ class singleWorker(StoppableThread):
payload += encodeVarint(encodedMessage.length)
payload += encodedMessage.data
if BMConfigParser().has_section(toaddress):
self.logger.info(
logger.info(
'Not bothering to include ackdata because we are'
' sending to ourselves or a chan.'
)
fullAckPayload = ''
elif not protocol.checkBitfield(
behaviorBitfield, protocol.BITFIELD_DOESACK):
self.logger.info(
logger.info(
'Not bothering to include ackdata because'
' the receiver said that they won\'t relay it anyway.'
)
@ -1205,7 +1199,7 @@ class singleWorker(StoppableThread):
requiredPayloadLengthExtraBytes
)) / (2 ** 16))
))
self.logger.info(
logger.info(
'(For msg message) Doing proof of work. Total required'
' difficulty: %f. Required small message difficulty: %f.',
float(requiredAverageProofOfWorkNonceTrialsPerByte) /
@ -1217,12 +1211,12 @@ class singleWorker(StoppableThread):
powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest()
trialValue, nonce = proofofwork.run(target, initialHash)
self.logger.info(
logger.info(
'(For msg message) Found proof of work %s Nonce: %s',
trialValue, nonce
)
try:
self.logger.info(
logger.info(
'PoW took %.1f seconds, speed %s.',
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
# this large until we implement message continuation.
if len(encryptedPayload) > 2 ** 18: # 256 KiB
self.logger.critical(
logger.critical(
'This msg object is too large to send. This should'
' never happen. Object size: %i',
len(encryptedPayload)
@ -1268,7 +1262,7 @@ class singleWorker(StoppableThread):
" Sent on %1"
).arg(l10n.formatTimestamp()))
))
self.logger.info(
logger.info(
'Broadcasting inv for my msg(within sendmsg function): %s',
hexlify(inventoryHash)
)
@ -1321,7 +1315,7 @@ class singleWorker(StoppableThread):
toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress)
if toStatus != 'success':
self.logger.error(
logger.error(
'Very abnormal error occurred in requestPubKey.'
' toAddress is: %r. Please report this error to Atheros.',
toAddress
@ -1335,7 +1329,7 @@ class singleWorker(StoppableThread):
toAddress
)
if not queryReturn:
self.logger.critical(
logger.critical(
'BUG: Why are we requesting the pubkey for %s'
' if there are no messages in the sent folder'
' to that address?', toAddress
@ -1383,11 +1377,11 @@ class singleWorker(StoppableThread):
payload += encodeVarint(streamNumber)
if addressVersionNumber <= 3:
payload += ripe
self.logger.info(
logger.info(
'making request for pubkey with ripe: %s', hexlify(ripe))
else:
payload += tag
self.logger.info(
logger.info(
'making request for v4 pubkey with tag: %s', hexlify(tag))
# print 'trial value', trialValue
@ -1408,7 +1402,7 @@ class singleWorker(StoppableThread):
objectType = 1
Inventory()[inventoryHash] = (
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))
# wait 10% past expiration

View File

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

View File

@ -1,37 +1,28 @@
"""
SMTP server thread
"""
import asyncore
import base64
import email
import logging
from email.parser import Parser
from email.header import decode_header
import re
import signal
import smtpd
import threading
import time
from email.header import decode_header
from email.parser import Parser
import queues
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from debug import logger
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
SMTPDOMAIN = "bmaddr.lan"
LISTENPORT = 8425
logger = logging.getLogger('default')
# pylint: disable=attribute-defined-outside-init
class smtpServerChannel(smtpd.SMTPChannel):
"""Asyncore channel for SMTP protocol (server)"""
def smtp_EHLO(self, arg):
"""Process an EHLO"""
if not arg:
self.push('501 Syntax: HELO hostname')
return
@ -39,17 +30,15 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('250 AUTH PLAIN')
def smtp_AUTH(self, arg):
"""Process AUTH"""
if not arg or arg[0:5] not in ["PLAIN"]:
self.push('501 Syntax: AUTH PLAIN')
return
authstring = arg[6:]
try:
decoded = base64.b64decode(authstring)
correctauth = "\x00" + BMConfigParser().safeGet(
"bitmessagesettings", "smtpdusername", "") + "\x00" + BMConfigParser().safeGet(
"bitmessagesettings", "smtpdpassword", "")
logger.debug('authstring: %s / %s', correctauth, decoded)
correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \
"\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "")
logger.debug("authstring: %s / %s", correctauth, decoded)
if correctauth == decoded:
self.auth = True
self.push('235 2.7.0 Authentication successful')
@ -59,17 +48,14 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('501 Authentication fail')
def smtp_DATA(self, arg):
"""Process DATA"""
if not hasattr(self, "auth") or not self.auth:
self.push('530 Authentication required')
self.push ("530 Authentication required")
return
smtpd.SMTPChannel.smtp_DATA(self, arg)
class smtpServerPyBitmessage(smtpd.SMTPServer):
"""Asyncore SMTP server class"""
def handle_accept(self):
"""Accept a connection"""
pair = self.accept()
if pair is not None:
conn, addr = pair
@ -77,9 +63,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
self.channel = smtpServerChannel(self, conn, addr)
def send(self, fromAddress, toAddress, subject, message):
"""Send a bitmessage"""
# pylint: disable=arguments-differ
streamNumber, ripe = decodeAddress(toAddress)[2:]
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute(
@ -98,14 +82,12 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
0, # retryNumber
'sent', # folder
2, # encodingtype
# not necessary to have a TTL higher than 2 days
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2)
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2) # not necessary to have a TTL higher than 2 days
)
queues.workerQueue.put(('sendmessage', toAddress))
def decode_header(self, hdr):
"""Email header decoding"""
ret = []
for h in decode_header(self.msg_headers[hdr]):
if h[1]:
@ -115,38 +97,37 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
return ret
def process_message(self, peer, mailfrom, rcpttos, data):
"""Process an email"""
# pylint: disable=too-many-locals, too-many-branches
# print 'Receiving message from:', peer
# print 'Receiving message from:', peer
p = re.compile(".*<([^>]+)>")
if not hasattr(self.channel, "auth") or not self.channel.auth:
logger.error('Missing or invalid auth')
logger.error("Missing or invalid auth")
return
try:
self.msg_headers = Parser().parsestr(data)
except:
logger.error('Invalid headers')
logger.error("Invalid headers")
return
try:
sender, domain = p.sub(r'\1', mailfrom).split("@")
if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain)
raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender)
raise Exception("Nonexisting user %s", sender)
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")
try:
msg_from = p.sub(r'\1', self.decode_header("from")[0])
sender, domain = msg_from.split("@")
if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain)
raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender)
raise Exception("Nonexisting user %s", sender)
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
try:
@ -164,20 +145,18 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
try:
rcpt, domain = p.sub(r'\1', to).split("@")
if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain)
logger.debug(
'Sending %s to %s about %s', sender, rcpt, msg_subject)
raise Exception("Bad domain %s", domain)
logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
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:
logger.error('Bad to %s: %r', to, err)
logger.error( "Bad to %s: %s", to, repr(err))
continue
return
class smtpServer(StoppableThread):
"""SMTP server thread"""
def __init__(self, _=None):
def __init__(self, parent=None):
super(smtpServer, self).__init__(name="smtpServerThread")
self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None)
@ -189,26 +168,21 @@ class smtpServer(StoppableThread):
def run(self):
asyncore.loop(1)
def signals(_, __):
"""Signal handler"""
logger.warning('Got signal, terminating')
def signals(signal, frame):
print "Got signal, terminating"
for thread in threading.enumerate():
if thread.isAlive() and isinstance(thread, StoppableThread):
thread.stopThread()
def runServer():
"""Run SMTP server as a standalone python process"""
logger.warning('Running SMTPd thread')
print "Running SMTPd thread"
smtpThread = smtpServer()
smtpThread.start()
signal.signal(signal.SIGINT, signals)
signal.signal(signal.SIGTERM, signals)
logger.warning('Processing')
print "Processing"
smtpThread.join()
logger.warning('The end')
print "The end"
if __name__ == "__main__":
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
from bmconfigparser import BMConfigParser
import sqlite3
import time
import shutil # used for moving the messages.dat file
import sys
import os
from debug import logger
import helper_sql
import helper_startup
import paths
import queues
import state
import tr
from bmconfigparser import BMConfigParser
from debug import logger
# pylint: disable=attribute-defined-outside-init,protected-access
# This thread exists because SQLITE3 is so un-threadsafe that we must
# 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):
"""A thread for all SQL operations"""
def __init__(self):
threading.Thread.__init__(self, name="SQL")
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
def run(self):
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
self.conn.text_factory = str
self.cur = self.conn.cursor()
@ -36,38 +32,30 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(
'''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)''')
'''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)''' )
self.cur.execute(
'''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)''')
'''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)''' )
self.cur.execute(
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''' )
self.cur.execute(
'''CREATE TABLE addressbook (label text, address text)''')
'''CREATE TABLE addressbook (label text, address text)''' )
self.cur.execute(
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
'''CREATE TABLE blacklist (label text, address text, enabled bool)''' )
self.cur.execute(
'''CREATE TABLE whitelist (label text, address text, enabled bool)''')
'''CREATE TABLE whitelist (label text, address text, enabled bool)''' )
self.cur.execute(
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
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 (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' )
self.cur.execute(
'''INSERT INTO subscriptions VALUES'''
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
self.cur.execute(
'''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('lastvacuumtime',?)''', (
'''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('lastvacuumtime',?)''', (
int(time.time()),))
self.cur.execute(
'''CREATE TABLE objectprocessorqueue'''
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
'''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' )
self.conn.commit()
logger.info('Created messages database file')
except Exception as err:
@ -132,38 +120,33 @@ class sqlThread(threading.Thread):
logger.debug(
"In messages.dat database, creating new 'settings' table.")
self.cur.execute(
'''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('lastvacuumtime',?)''', (
'''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('lastvacuumtime',?)''', (
int(time.time()),))
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute(
'''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(
'''CREATE TABLE pubkeys'''
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
'''CREATE TABLE pubkeys (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''' )
self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute('''DROP TABLE pubkeys_backup;''')
logger.debug(
'Deleting all pubkeys from inventory.'
' They will be redownloaded and then saved with the correct times.')
self.cur.execute( '''DROP TABLE pubkeys_backup;''')
logger.debug('Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.')
self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''')
logger.debug('replacing Bitmessage announcements mailing list with a new one.')
self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute(
'''INSERT INTO subscriptions VALUES'''
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
logger.debug('Commiting.')
self.conn.commit()
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
# have changed.
@ -187,21 +170,15 @@ class sqlThread(threading.Thread):
'In messages.dat database, removing an obsolete field from'
' the inventory table.')
self.cur.execute(
'''CREATE TEMPORARY TABLE inventory_backup'''
'''(hash blob, objecttype text, streamnumber int, payload blob,'''
''' receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
'''CREATE TEMPORARY TABLE inventory_backup(hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute(
'''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime'''
''' FROM inventory;''')
self.cur.execute('''DROP TABLE inventory''')
'''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;''')
self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute(
'''CREATE TABLE inventory'''
''' (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer,'''
''' UNIQUE(hash) ON CONFLICT REPLACE)''')
'''CREATE TABLE inventory (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE)''' )
self.cur.execute(
'''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime'''
''' FROM inventory_backup;''')
self.cur.execute('''DROP TABLE inventory_backup;''')
'''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;''')
self.cur.execute( '''DROP TABLE inventory_backup;''')
item = '''update settings set value=? WHERE key='version';'''
parameters = (3,)
self.cur.execute(item, parameters)
@ -231,8 +208,7 @@ class sqlThread(threading.Thread):
if currentVersion == 4:
self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int,'''
'''usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
'''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''')
item = '''update settings set value=? WHERE key='version';'''
@ -248,8 +224,7 @@ class sqlThread(threading.Thread):
if currentVersion == 5:
self.cur.execute('''DROP TABLE knownnodes''')
self.cur.execute(
'''CREATE TABLE objectprocessorqueue'''
''' (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
'''CREATE TABLE objectprocessorqueue (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';'''
parameters = (6,)
self.cur.execute(item, parameters)
@ -265,15 +240,10 @@ class sqlThread(threading.Thread):
logger.debug(
'In messages.dat database, dropping and recreating'
' the inventory table.')
self.cur.execute('''DROP TABLE inventory''')
self.cur.execute(
'''CREATE TABLE inventory'''
''' (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer,'''
''' 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)''')
self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute( '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, 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';'''
parameters = (7,)
self.cur.execute(item, parameters)
@ -335,24 +305,15 @@ class sqlThread(threading.Thread):
' fields into the retrynumber field and adding the'
' sleeptill and ttl fields...')
self.cur.execute(
'''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)''')
'''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)''' )
self.cur.execute(
'''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress,'''
''' subject, message, ackdata, lastactiontime,'''
''' status, 0, folder, encodingtype FROM sent;''')
self.cur.execute('''DROP TABLE sent''')
'''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;''')
self.cur.execute( '''DROP TABLE sent''')
self.cur.execute(
'''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)''')
'''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)''' )
self.cur.execute(
'''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata,'''
''' lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
self.cur.execute('''DROP TABLE sent_backup''')
'''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
self.cur.execute( '''DROP TABLE sent_backup''')
logger.info('In messages.dat database, finished making TTL-related changes.')
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
@ -369,24 +330,16 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters)
# Now we can remove the hash field from the pubkeys table.
self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup'''
''' (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
'''CREATE TEMPORARY TABLE pubkeys_backup (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
self.cur.execute(
'''INSERT INTO pubkeys_backup'''
''' SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute('''DROP TABLE pubkeys''')
'''INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute( '''DROP TABLE pubkeys''')
self.cur.execute(
'''CREATE TABLE pubkeys'''
''' (address text, addressversion int, transmitdata blob, time int, usedpersonally text,'''
''' UNIQUE(address) ON CONFLICT REPLACE)''')
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
self.cur.execute(
'''INSERT INTO pubkeys SELECT'''
''' address, addressversion, transmitdata, time, usedpersonally FROM 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.')
'''INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM 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.')
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
@ -396,7 +349,7 @@ class sqlThread(threading.Thread):
try:
testpayload = '\x00\x00'
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.cur.execute(
'''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.conn.commit()
if transmitdata == '':
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')
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')
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')
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)
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(While null value test) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(While null value test) Alert: Your disk or data storage volume is full. 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)
else:
logger.error(err)
@ -444,21 +381,11 @@ class sqlThread(threading.Thread):
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...')
try:
self.cur.execute(''' VACUUM ''')
self.cur.execute( ''' VACUUM ''')
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(While VACUUM) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(While VACUUM) Alert: Your disk or data storage volume is full. 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)
item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),)
@ -473,18 +400,8 @@ class sqlThread(threading.Thread):
self.conn.commit()
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(While committing) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(While committing) Alert: Your disk or data storage volume is full. 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)
elif item == 'exit':
self.conn.close()
@ -498,18 +415,8 @@ class sqlThread(threading.Thread):
self.conn.commit()
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(while movemessagstoprog) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(while movemessagstoprog) Alert: Your disk or data storage volume is full. 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)
self.conn.close()
shutil.move(
@ -524,18 +431,8 @@ class sqlThread(threading.Thread):
self.conn.commit()
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(while movemessagstoappdata) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(while movemessagstoappdata) Alert: Your disk or data storage volume is full. 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)
self.conn.close()
shutil.move(
@ -548,21 +445,11 @@ class sqlThread(threading.Thread):
self.cur.execute('''delete from sent where folder='trash' ''')
self.conn.commit()
try:
self.cur.execute(''' VACUUM ''')
self.cur.execute( ''' VACUUM ''')
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(while deleteandvacuume) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(while deleteandvacuume) Alert: Your disk or data storage volume is full. 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)
else:
parameters = helper_sql.sqlSubmitQueue.get()
@ -574,30 +461,11 @@ class sqlThread(threading.Thread):
rowcount = self.cur.rowcount
except Exception as err:
if str(err) == 'database or disk is full':
logger.fatal(
'(while cur.execute) Alert: Your disk or data storage volume is full.'
' 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)))
logger.fatal('(while cur.execute) Alert: Your disk or data storage volume is full. 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)
else:
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))
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))
logger.fatal('This program shall now abruptly exit!')
os._exit(0)

View File

@ -1,6 +1,6 @@
"""
Logging and debuging facility
-----------------------------
=============================
Levels:
@ -9,30 +9,18 @@ Levels:
INFO
Confirmation that things are working as expected.
WARNING
An indication that something unexpected happened, or indicative of
some problem in the near future (e.g. 'disk space low'). The software
is still working as expected.
An indication that something unexpected happened, or indicative of some problem in the
near future (e.g. 'disk space low'). The software is still working as expected.
ERROR
Due to a more serious problem, the software has not been able to
perform some function.
Due to a more serious problem, the software has not been able to perform some function.
CRITICAL
A serious error, indicating that the program itself may be unable to
continue running.
A serious error, indicating that the program itself may be unable to continue running.
There are three loggers by default: `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.
There are three loggers: `console_only`, `file_only` and `both`.
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
@ -40,7 +28,6 @@ import logging
import logging.config
import os
import sys
import helper_startup
import state
@ -54,22 +41,14 @@ log_level = 'WARNING'
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))
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 = ''
try:
logging_config = os.path.join(state.appdata, 'logging.dat')
logging.config.fileConfig(
logging_config, disable_existing_loggers=False)
logging.config.fileConfig(logging_config)
return (
False,
'Loaded logger configuration from %s' % logging_config
@ -81,11 +60,12 @@ def configureLogging():
' logging config\n%s' % \
(logging_config, sys.exc_info())
else:
# no need to confuse the user if the logger config
# is missing entirely
# no need to confuse the user if the logger config is missing entirely
fail_msg = 'Using default logger configuration'
logging_config = {
sys.excepthook = log_uncaught_exceptions
logging.config.dictConfig({
'version': 1,
'formatters': {
'default': {
@ -127,29 +107,34 @@ def configureLogging():
'level': log_level,
'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
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():
"""Reconfigure logging in runtime when state.appdata dir changed"""
# pylint: disable=global-statement, used-before-assignment
global logger
for i in logger.handlers:
for i in logger.handlers.iterkeys():
logger.removeHandler(i)
i.flush()
i.close()
configureLogging()
logger = logging.getLogger('default')
logger = initLogging()
# !
preconfigured, msg = configureLogging()
logger = logging.getLogger('default')
if msg:
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)
logger = initLogging()

View File

@ -1,24 +1,24 @@
"""
Common default values
src/defaults.py
===============
"""
#: sanity check, prevent doing ridiculous PoW
#: 20 million PoWs equals approximately 2 days on dev's dual R9 290
# sanity check, prevent doing ridiculous PoW
# 20 million PoWs equals approximately 2 days on dev's dual R9 290
ridiculousDifficulty = 20000000
#: 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
#: namecoin integration to "namecoind".
# 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
# namecoin integration to "namecoind".
namecoinDefaultRpcPort = "8336"
# If changed, these values will cause particularly unexpected behavior:
# 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.
# Don't change them!
#: The amount of work that should be performed (and demanded) per byte
#: of the payload.
# The amount of work that should be performed (and demanded) per byte of the payload.
networkDefaultProofOfWorkNonceTrialsPerByte = 1000
#: 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
#: target.
# 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
# target.
networkDefaultPayloadLengthExtraBytes = 1000

View File

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

View File

@ -1,19 +1,13 @@
"""
Fallback expressions help PyBitmessage modules to run without some external
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.
.. todo:: hello world
"""
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:
hashlib.new('ripemd160')
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 struct import pack
import helper_random
import highlevelcrypto
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):
"""
Generate and return payload obj.
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 and return payload obj."""
if (stealthLevel == 2): # Generate privacy-enhanced payload
# Generate a dummy privkey and derive the pubkey
dummyPubKeyHex = highlevelcrypto.privToPub(
hexlify(helper_random.randomBytes(32)))
@ -35,7 +29,7 @@ def genAckPayload(streamNumber=1, stealthLevel=0):
acktype = 2 # message
version = 1
elif stealthLevel == 1: # Basic privacy payload (random getpubkey)
elif (stealthLevel == 1): # Basic privacy payload (random getpubkey)
ackdata = helper_random.randomBytes(32)
acktype = 0 # getpubkey
version = 4

View File

@ -1,19 +1,10 @@
"""
Calculates bitcoin and testnet address from pubkey
"""
import hashlib
from debug import logger
from pyelliptic import arithmetic
# This function expects that pubkey begin with \x04
def calculateBitcoinAddressFromPubkey(pubkey):
"""Calculate bitcoin address from given pubkey (65 bytes long hex string)"""
if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
return "error"
ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256')
@ -33,11 +24,8 @@ def calculateBitcoinAddressFromPubkey(pubkey):
def calculateTestnetAddressFromPubkey(pubkey):
"""This function expects that pubkey begin with the testnet prefix"""
if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
return "error"
ripe = hashlib.new('ripemd160')
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
import queues
def insert(t):
"""Perform an insert into the "inbox" table"""
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t)
# shouldn't emit changedInboxUnread and displayNewInboxMessage
# at the same time
@ -13,13 +12,11 @@ def insert(t):
def trash(msgid):
"""Mark a message in the `inbox` as `trash`"""
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)
queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid))
def isMessageAlreadyInInbox(sigHash):
"""Check for previous instances of this message"""
queryReturn = sqlQuery(
'''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash)
return queryReturn[0][0] != 0

View File

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

View File

@ -2,9 +2,7 @@
import os
import random
from pyelliptic.openssl import OpenSSL
NoneType = type(None)
@ -58,6 +56,7 @@ def randomrandrange(x, y=None):
"""
if isinstance(y, NoneType):
return random.randrange(x) # nosec
else:
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:
from PyQt4 import QtGui
@ -8,17 +8,13 @@ try:
except ImportError:
haveQt = False
def search_translate(context, text):
"""Translation wrapper"""
def search_translate (context, text):
if haveQt:
return QtGui.QApplication.translate(context, text)
else:
return text.lower()
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
def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False):
if what is not None and what != "":
what = "%" + what + "%"
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)
if unreadOnly:
sqlStatementParts.append("read = 0")
if sqlStatementParts:
if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent":
sqlStatementBase += " ORDER BY lastactiontime"
return sqlQuery(sqlStatementBase, sqlArguments)
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
def check_match(toAddress, fromAddress, subject, message, where = None, what = None):
if what is not None and what != "":
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")):
if what.lower() not in toAddress.lower():

View File

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

View File

@ -1,39 +1,17 @@
"""
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`.
"""Helper Sql performs sql operations."""
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 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()
"""the queue for results"""
sqlLock = threading.Lock()
def sqlQuery(sqlStatement, *args):
"""
Query sqlite and return results
:param str sqlStatement: SQL statement string
:param list args: SQL query parameters
:rtype: list
"""
"""SQLLITE execute statement and return query."""
sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement)
@ -50,7 +28,6 @@ def sqlQuery(sqlStatement, *args):
def sqlExecuteChunked(sqlStatement, idCount, *args):
"""Execute chunked SQL statement to avoid argument limit"""
# SQLITE_MAX_VARIABLE_NUMBER,
# unfortunately getting/setting isn't exposed to python
sqlExecuteChunked.chunkSize = 999
@ -81,7 +58,6 @@ def sqlExecuteChunked(sqlStatement, idCount, *args):
def sqlExecute(sqlStatement, *args):
"""Execute SQL statement (optionally with arguments)"""
sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement)
@ -94,15 +70,13 @@ def sqlExecute(sqlStatement, *args):
sqlLock.release()
return rowcount
def sqlStoredProcedure(procName):
"""Schedule procName to be run"""
sqlLock.acquire()
sqlSubmitQueue.put(procName)
sqlLock.release()
class SqlBulkExecute(object):
class SqlBulkExecute:
"""This is used when you have to execute the same statement in a cycle."""
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
from __future__ import print_function
import logging
import ConfigParser
import os
import platform
import sys
import time
from distutils.version import StrictVersion
import defaults
@ -16,19 +19,28 @@ import paths
import state
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 config files to stay in the application data folder.
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():
"""Load the config"""
config = BMConfigParser()
@ -38,14 +50,14 @@ def loadConfig():
needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile:
logger.info(
print(
'Loading config files from directory specified'
' on startup: %s', state.appdata)
' on startup: %s' % state.appdata)
else:
config.read(paths.lookupExeFolder() + 'keys.dat')
try:
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
state.appdata = paths.lookupExeFolder()
except:
@ -56,8 +68,7 @@ def loadConfig():
needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile:
logger.info(
'Loading existing config files from %s', state.appdata)
print('Loading existing config files from', state.appdata)
if needToCreateKeysFile:
@ -112,10 +123,9 @@ def loadConfig():
# Just use the same directory as the program and forget about
# the appdata folder
state.appdata = ''
logger.info(
'Creating new config files in same directory as program.')
print('Creating new config files in same directory as program.')
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):
os.makedirs(state.appdata)
if not sys.platform.startswith('win'):
@ -124,6 +134,8 @@ def loadConfig():
else:
updateConfig()
_loadTrustedPeer()
def updateConfig():
"""Save the config"""
@ -265,7 +277,7 @@ def updateConfig():
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
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
# whatever the user selects.
@ -288,26 +300,3 @@ def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
return False
except Exception:
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.
.. 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>`_
src/highlevelcrypto.py
======================
"""
from binascii import hexlify
@ -16,13 +12,12 @@ from pyelliptic import arithmetic as a
def makeCryptor(privkey):
"""Return a private `.pyelliptic.ECC` instance"""
"""Return a private pyelliptic.ECC() instance"""
private_key = a.changebase(privkey, 16, 256, minlen=32)
public_key = pointMult(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:]
cryptor = pyelliptic.ECC(
curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
return cryptor
@ -34,7 +29,7 @@ def hexToPubkey(pubkey):
def makePubCryptor(pubkey):
"""Return a public `.pyelliptic.ECC` instance"""
"""Return a public pyelliptic.ECC() instance"""
pubkey_bin = hexToPubkey(pubkey)
return pyelliptic.ECC(curve='secp256k1', pubkey=pubkey_bin)
@ -48,8 +43,7 @@ def privToPub(privkey):
def encrypt(msg, hexPubkey):
"""Encrypts message with hex public key"""
return pyelliptic.ECC(curve='secp256k1').encrypt(
msg, hexToPubkey(hexPubkey))
return pyelliptic.ECC(curve='secp256k1').encrypt(msg, hexToPubkey(hexPubkey))
def decrypt(msg, hexPrivkey):
@ -58,38 +52,36 @@ def decrypt(msg, hexPrivkey):
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)
def sign(msg, hexPrivkey):
"""
Signs with hex private key using SHA1 or SHA256 depending on
"digestalg" setting
"""
digestAlg = BMConfigParser().safeGet(
'bitmessagesettings', 'digestalg', 'sha1')
"""Signs with hex private key"""
# pyelliptic is upgrading from SHA1 to SHA256 for signing. We must
# upgrade PyBitmessage gracefully.
# https://github.com/yann2192/pyelliptic/pull/33
# More discussion: https://github.com/yann2192/pyelliptic/issues/32
digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1')
if digestAlg == "sha1":
# SHA1, this will eventually be deprecated
return makeCryptor(hexPrivkey).sign(
msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
elif digestAlg == "sha256":
# SHA256. Eventually this will become the default
return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256)
else:
raise ValueError("Unknown digest algorithm %s" % digestAlg)
raise ValueError("Unknown digest algorithm %s" % (digestAlg))
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
# let us check the signature using both SHA1 and SHA256 and if one
# of them passes then we will be satisfied. Eventually this can
# be simplified and we'll only check with SHA256.
try:
# old SHA1 algorithm.
sigVerifyPassed = makePubCryptor(hexPubkey).verify(
sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
sigVerifyPassed = makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
except:
sigVerifyPassed = False
if sigVerifyPassed:
@ -97,8 +89,7 @@ def verify(msg, sig, hexPubkey):
return True
# The signature check using SHA1 failed. Let us try it with SHA256.
try:
return makePubCryptor(hexPubkey).verify(
sig, msg, digest_alg=OpenSSL.EVP_sha256)
return makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.EVP_sha256)
except:
return False
@ -109,14 +100,13 @@ def pointMult(secret):
Evidently, this type of error can occur very rarely:
>>> File "highlevelcrypto.py", line 54, in pointMult
>>> group = OpenSSL.EC_KEY_get0_group(k)
>>> WindowsError: exception: access violation reading 0x0000000000000008
File "highlevelcrypto.py", line 54, in pointMult
group = OpenSSL.EC_KEY_get0_group(k)
WindowsError: exception: access violation reading 0x0000000000000008
"""
while True:
try:
k = OpenSSL.EC_KEY_new_by_curve_name(
OpenSSL.get_curve('secp256k1'))
k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
priv_key = OpenSSL.BN_bin2bn(secret, 32, None)
group = OpenSSL.EC_KEY_get0_group(k)
pub_key = OpenSSL.EC_POINT_new(group)

View File

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

View File

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

View File

@ -1,13 +1,13 @@
"""
Localization
"""
import logging
import os
import time
from bmconfigparser import BMConfigParser
logger = logging.getLogger('default')
#logger = logging.getLogger(__name__)
logger = logging.getLogger('file_only')
DEFAULT_ENCODING = 'ISO8859-1'
@ -50,7 +50,7 @@ except:
if BMConfigParser().has_option('bitmessagesettings', 'timeformat'):
time_format = BMConfigParser().get('bitmessagesettings', 'timeformat')
# Test the format string
#Test the format string
try:
time.strftime(time_format)
except:
@ -59,52 +59,48 @@ if BMConfigParser().has_option('bitmessagesettings', 'timeformat'):
else:
time_format = DEFAULT_TIME_FORMAT
# It seems some systems lie about the encoding they use so we perform
# comprehensive decoding tests
#It seems some systems lie about the encoding they use so we perform
#comprehensive decoding tests
if time_format != DEFAULT_TIME_FORMAT:
try:
# Check day names
#Check day names
for i in xrange(7):
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):
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, 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)
except:
logger.exception('Could not decode locale formatted timestamp')
time_format = DEFAULT_TIME_FORMAT
encoding = DEFAULT_ENCODING
def setlocale(category, newlocale):
"""Set the locale"""
locale.setlocale(category, newlocale)
# 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
os.environ["LC_ALL"] = newlocale
def formatTimestamp(timestamp=None, as_unicode=True):
"""Return a formatted timestamp"""
# For some reason some timestamps are strings so we need to sanitize.
def formatTimestamp(timestamp = None, as_unicode = True):
#For some reason some timestamps are strings so we need to sanitize.
if timestamp is not None and not isinstance(timestamp, int):
try:
timestamp = int(timestamp)
except:
timestamp = None
# timestamp can't be less than 0.
#timestamp can't be less than 0.
if timestamp is not None and timestamp < 0:
timestamp = None
if timestamp is None:
timestring = time.strftime(time_format)
else:
# In case timestamp is too far in the future
#In case timestamp is too far in the future
try:
timestring = time.strftime(time_format, time.localtime(timestamp))
except ValueError:
@ -114,21 +110,17 @@ def formatTimestamp(timestamp=None, as_unicode=True):
return unicode(timestring, encoding)
return timestring
def getTranslationLanguage():
"""Return the user's language choice"""
userlocale = BMConfigParser().safeGet(
'bitmessagesettings', 'userlocale', 'system')
return userlocale if userlocale and userlocale != 'system' else language
userlocale = None
if BMConfigParser().has_option('bitmessagesettings', 'userlocale'):
userlocale = BMConfigParser().get('bitmessagesettings', 'userlocale')
if userlocale in [None, '', 'system']:
return language
return userlocale
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:
return windowsLanguageMap[posixLocale]
if "." in posixLocale:

View File

@ -1,6 +1,6 @@
"""This module is for thread start."""
import state
from bitmessagemain import main
import state
if __name__ == '__main__':
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 os import listdir, path
from os import path, listdir
from string import lower
from debug import logger
import messagetypes
import paths
logger = logging.getLogger('default')
class MsgBase(object): # pylint: disable=too-few-public-methods
"""Base class for message types"""
def __init__(self):
class MsgBase(object):
def encode(self):
self.data = {"": lower(type(self).__name__)}
def constructObject(data):
"""Constructing an object"""
whitelist = ["message"]
if data[""] not in whitelist:
return None
@ -37,7 +32,6 @@ def constructObject(data):
else:
return returnObj
if paths.frozen is not None:
import messagetypes.message
import messagetypes.vote

View File

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

View File

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

View File

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

View File

@ -1,7 +1,31 @@
"""
Namecoin queries
"""
# 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 httplib
@ -10,11 +34,11 @@ import os
import socket
import sys
from addresses import decodeAddress
from debug import logger
import defaults
import tr # translate
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
from debug import logger
configSection = "bitmessagesettings"
@ -234,7 +258,7 @@ class namecoinConnection(object):
resp = self.con.getresponse()
result = resp.read()
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:
logger.info("HTTP receive error")
except:
@ -264,7 +288,7 @@ class namecoinConnection(object):
return result
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():

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

View File

@ -1,20 +1,23 @@
"""
Announce myself (node address)
src/network/announcethread.py
=================================
"""
import time
import state
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.udp import UDPSocket
from node import Peer
from threads import StoppableThread
import state
class AnnounceThread(StoppableThread):
"""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):
lastSelfAnnounced = 0
@ -35,9 +38,6 @@ class AnnounceThread(StoppableThread):
for stream in state.streamsInWhichIAmParticipating:
addr = (
stream,
Peer(
'127.0.0.1',
BMConfigParser().safeGetInt(
'bitmessagesettings', 'port')),
state.Peer('127.0.0.1', BMConfigParser().safeGetInt("bitmessagesettings", "port")),
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 -*-
# Id: asyncore.py,v 2.51 2000/09/07 22:29:26 rushing Exp
# Author: Sam Rushing <rushing@nightmare.com>
# pylint: disable=too-many-branches,too-many-lines,global-statement
# pylint: disable=redefined-builtin,no-self-use
# pylint: disable=too-many-statements,too-many-branches,no-self-use,too-many-lines,attribute-defined-outside-init
# 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 select
import socket
@ -13,9 +58,8 @@ import sys
import time
import warnings
from errno import (
EADDRINUSE, EAGAIN, EALREADY, EBADF, ECONNABORTED, ECONNREFUSED,
ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EINVAL, EISCONN, ENETUNREACH,
ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
EADDRINUSE, EAGAIN, EALREADY, EBADF, ECONNABORTED, ECONNREFUSED, ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR,
EINVAL, EISCONN, ENETUNREACH, ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
)
from threading import current_thread
@ -63,8 +107,7 @@ def _strerror(err):
class ExitNow(Exception):
"""We don't use directly but may be necessary as we replace
asyncore due to some library raising or expecting it"""
"""We don't use directly but may be necessary as we replace asyncore due to some library raising or expecting it"""
pass
@ -109,8 +152,7 @@ def write(obj):
def set_rates(download, upload):
"""Set throttling rates"""
global maxDownloadRate, maxUploadRate, downloadBucket
global uploadBucket, downloadTimestamp, uploadTimestamp
global maxDownloadRate, maxUploadRate, downloadBucket, uploadBucket, downloadTimestamp, uploadTimestamp
maxDownloadRate = float(download) * 1024
maxUploadRate = float(upload) * 1024
@ -140,8 +182,7 @@ def update_received(download=0):
currentTimestamp = time.time()
receivedBytes += download
if maxDownloadRate > 0:
bucketIncrease = \
maxDownloadRate * (currentTimestamp - downloadTimestamp)
bucketIncrease = maxDownloadRate * (currentTimestamp - downloadTimestamp)
downloadBucket += bucketIncrease
if downloadBucket > maxDownloadRate:
downloadBucket = int(maxDownloadRate)
@ -201,6 +242,7 @@ def readwrite(obj, flags):
def select_poller(timeout=0.0, map=None):
"""A poller which uses select(), available on most platforms."""
# pylint: disable=redefined-builtin
if map is None:
map = socket_map
@ -256,6 +298,7 @@ def select_poller(timeout=0.0, map=None):
def poll_poller(timeout=0.0, map=None):
"""A poller which uses poll(), available on most UNIXen."""
# pylint: disable=redefined-builtin
if map is None:
map = socket_map
@ -313,6 +356,7 @@ poll2 = poll3 = poll_poller
def epoll_poller(timeout=0.0, map=None):
"""A poller which uses epoll(), supported on Linux 2.5.44 and newer."""
# pylint: disable=redefined-builtin
if map is None:
map = socket_map
@ -368,7 +412,7 @@ def epoll_poller(timeout=0.0, map=None):
def kqueue_poller(timeout=0.0, map=None):
"""A poller which uses kqueue(), BSD specific."""
# pylint: disable=no-member,too-many-statements
# pylint: disable=redefined-builtin,no-member
if map is None:
map = socket_map
@ -396,20 +440,14 @@ def kqueue_poller(timeout=0.0, map=None):
poller_flags |= select.KQ_EV_ENABLE
else:
poller_flags |= select.KQ_EV_DISABLE
updates.append(
select.kevent(
fd, filter=select.KQ_FILTER_READ,
flags=poller_flags))
updates.append(select.kevent(fd, filter=select.KQ_FILTER_READ, flags=poller_flags))
if kq_filter & 2 != obj.poller_filter & 2:
poller_flags = select.KQ_EV_ADD
if kq_filter & 2:
poller_flags |= select.KQ_EV_ENABLE
else:
poller_flags |= select.KQ_EV_DISABLE
updates.append(
select.kevent(
fd, filter=select.KQ_FILTER_WRITE,
flags=poller_flags))
updates.append(select.kevent(fd, filter=select.KQ_FILTER_WRITE, flags=poller_flags))
obj.poller_filter = kq_filter
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):
"""Poll in a loop, until count or timeout is reached"""
# pylint: disable=redefined-builtin
if map is None:
map = socket_map
@ -481,9 +520,9 @@ def loop(timeout=30.0, use_poll=False, map=None, count=None, poller=None):
count = count - 1
class dispatcher(object):
class dispatcher:
"""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
connected = False
@ -498,6 +537,7 @@ class dispatcher(object):
minTx = 1500
def __init__(self, sock=None, map=None):
# pylint: disable=redefined-builtin
if map is None:
self._map = socket_map
else:
@ -546,7 +586,8 @@ class dispatcher(object):
def add_channel(self, map=None):
"""Add a channel"""
# pylint: disable=attribute-defined-outside-init
# pylint: disable=redefined-builtin
if map is None:
map = self._map
map[self._fileno] = self
@ -555,6 +596,8 @@ class dispatcher(object):
def del_channel(self, map=None):
"""Delete a channel"""
# pylint: disable=redefined-builtin
fd = self._fileno
if map is None:
map = self._map
@ -562,14 +605,12 @@ class dispatcher(object):
del map[fd]
if self._fileno:
try:
kqueue_poller.pollster.control([select.kevent(
fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0)
except(AttributeError, KeyError, TypeError, IOError, OSError):
kqueue_poller.pollster.control([select.kevent(fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0)
except (AttributeError, KeyError, TypeError, IOError, OSError):
pass
try:
kqueue_poller.pollster.control([select.kevent(
fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0)
except(AttributeError, KeyError, TypeError, IOError, OSError):
kqueue_poller.pollster.control([select.kevent(fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0)
except (AttributeError, KeyError, TypeError, IOError, OSError):
pass
try:
epoll_poller.pollster.unregister(fd)
@ -586,10 +627,8 @@ class dispatcher(object):
self.poller_filter = 0
self.poller_registered = False
def create_socket(
self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
def create_socket(self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
"""Create a socket"""
# pylint: disable=attribute-defined-outside-init
self.family_and_type = family, socket_type
sock = socket.socket(family, socket_type)
sock.setblocking(0)
@ -597,16 +636,20 @@ class dispatcher(object):
def set_socket(self, sock, map=None):
"""Set socket"""
# pylint: disable=redefined-builtin
self.socket = sock
self._fileno = sock.fileno()
self.add_channel(map)
def set_reuse_addr(self):
"""try to re-use a server port if possible"""
try:
self.socket.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, self.socket.getsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1
socket.SOL_SOCKET, socket.SO_REUSEADDR,
self.socket.getsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR) | 1
)
except socket.error:
pass
@ -661,16 +704,13 @@ class dispatcher(object):
raise socket.error(err, errorcode[err])
def accept(self):
"""Accept incoming connections.
Returns either an address pair or None."""
"""Accept incoming connections. Returns either an address pair or None."""
try:
conn, addr = self.socket.accept()
except TypeError:
return None
except socket.error as why:
if why.args[0] in (
EWOULDBLOCK, WSAEWOULDBLOCK, ECONNABORTED,
EAGAIN, ENOTCONN):
if why.args[0] in (EWOULDBLOCK, WSAEWOULDBLOCK, ECONNABORTED, EAGAIN, ENOTCONN):
return None
else:
raise
@ -729,12 +769,11 @@ class dispatcher(object):
try:
retattr = getattr(self.socket, attr)
except AttributeError:
raise AttributeError(
"%s instance has no attribute '%s'"
raise AttributeError("%s instance has no attribute '%s'"
% (self.__class__.__name__, attr))
else:
msg = "%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s"\
" instead" % {'me': self.__class__.__name__, 'attr': attr}
msg = "%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s " \
"instead" % {'me': self.__class__.__name__, 'attr': attr}
warnings.warn(msg, DeprecationWarning, stacklevel=2)
return retattr
@ -816,8 +855,13 @@ class dispatcher(object):
self.log_info(
'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr, t, v, tbinfo),
'error')
self_repr,
t,
v,
tbinfo
),
'error'
)
self.handle_close()
def handle_accept(self):
@ -858,8 +902,11 @@ class dispatcher_with_send(dispatcher):
adds simple buffered output capability, useful for simple clients.
[for more sophisticated usage use asynchat.async_chat]
"""
# pylint: disable=redefined-builtin
def __init__(self, sock=None, map=None):
# pylint: disable=redefined-builtin
dispatcher.__init__(self, sock, map)
self.out_buffer = b''
@ -894,8 +941,7 @@ def compact_traceback():
"""Return a compact traceback"""
t, v, tb = sys.exc_info()
tbinfo = []
# Must have a traceback
if not tb:
if not tb: # Must have a traceback
raise AssertionError("traceback does not exist")
while tb:
tbinfo.append((
@ -915,6 +961,7 @@ def compact_traceback():
def close_all(map=None, ignore_all=False):
"""Close all connections"""
# pylint: disable=redefined-builtin
if map is None:
map = socket_map
@ -951,13 +998,13 @@ def close_all(map=None, ignore_all=False):
if os.name == 'posix':
import fcntl
class file_wrapper: # pylint: disable=old-style-class
class file_wrapper:
"""
Here we override just enough to make a file look
like a socket for the purposes of asyncore.
Here we override just enough to make a file look like a socket for the purposes of asyncore.
The passed fd is automatically os.dup()'d
"""
# pylint: disable=old-style-class
def __init__(self, fd):
self.fd = os.dup(fd)
@ -972,11 +1019,12 @@ if os.name == 'posix':
def getsockopt(self, level, optname, buflen=None):
"""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):
return 0
raise NotImplementedError(
"Only asyncore specific behaviour implemented.")
raise NotImplementedError("Only asyncore specific behaviour "
"implemented.")
read = recv
write = send
@ -993,6 +1041,8 @@ if os.name == 'posix':
"""A dispatcher for file_wrapper objects"""
def __init__(self, fd, map=None):
# pylint: disable=redefined-builtin
dispatcher.__init__(self, None, map)
self.connected = True
try:

View File

@ -1,27 +1,26 @@
"""
BMObject and it's exceptions.
src/network/bmobject.py
======================
"""
import logging
import time
import protocol
import state
from addresses import calculateInventoryHash
from debug import logger
from inventory import Inventory
from network.dandelion import Dandelion
logger = logging.getLogger('default')
class BMObjectInsufficientPOWError(Exception):
"""Exception indicating the object
doesn't have sufficient proof of work."""
"""Exception indicating the object doesn't have sufficient proof of work."""
errorCodes = ("Insufficient proof of work")
class BMObjectInvalidDataError(Exception):
"""Exception indicating the data being parsed
does not match the specification."""
"""Exception indicating the data being parsed does not match the specification."""
errorCodes = ("Data invalid")
@ -31,8 +30,7 @@ class BMObjectExpiredError(Exception):
class BMObjectUnwantedStreamError(Exception):
"""Exception indicating the object is in a stream
we didn't advertise as being interested in."""
"""Exception indicating the object is in a stream we didn't advertise as being interested in."""
errorCodes = ("Object in unwanted stream")
@ -46,8 +44,9 @@ class BMObjectAlreadyHaveError(Exception):
errorCodes = ("Already have this object")
class BMObject(object): # pylint: disable=too-many-instance-attributes
class BMObject(object):
"""Bitmessage Object as a class."""
# pylint: disable=too-many-instance-attributes
# max TTL, 28 days and 3 hours
maxTTL = 28 * 24 * 60 * 60 + 10800
@ -82,36 +81,31 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
raise BMObjectInsufficientPOWError()
def checkEOLSanity(self):
"""Check if object's lifetime
isn't ridiculously far in the past or future."""
"""Check if object's lifetime isn't ridiculously far in the past or future."""
# EOL sanity check
if self.expiresTime - int(time.time()) > BMObject.maxTTL:
logger.info(
'This object\'s End of Life time is too far in the future.'
' Ignoring it. Time is %i', self.expiresTime)
'This object\'s End of Life time is too far in the future. Ignoring it. Time is %i',
self.expiresTime)
# .. todo:: remove from download queue
raise BMObjectExpiredError()
if self.expiresTime - int(time.time()) < BMObject.minTTL:
logger.info(
'This object\'s End of Life time was too long ago.'
' Ignoring the object. Time is %i', self.expiresTime)
'This object\'s End of Life time was too long ago. Ignoring the object. Time is %i',
self.expiresTime)
# .. todo:: remove from download queue
raise BMObjectExpiredError()
def checkStream(self):
"""Check if object's stream matches streams we are interested in"""
if self.streamNumber not in state.streamsInWhichIAmParticipating:
logger.debug(
'The streamNumber %i isn\'t one we are interested in.',
self.streamNumber)
logger.debug('The streamNumber %i isn\'t one we are interested in.', self.streamNumber)
raise BMObjectUnwantedStreamError()
def checkAlreadyHave(self):
"""
Check if we already have the object
(so that we don't duplicate it in inventory
or advertise it unnecessarily)
Check if we already have the object (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 Dandelion().hasHash(self.inventoryHash):
@ -120,8 +114,7 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
raise BMObjectAlreadyHaveError()
def checkObjectByType(self):
"""Call a object type specific check
(objects can have additional checks based on their types)"""
"""Call a object type specific check (objects can have additional checks based on their types)"""
if self.objectType == protocol.OBJECT_GETPUBKEY:
self.checkGetpubkey()
elif self.objectType == protocol.OBJECT_PUBKEY:
@ -132,21 +125,20 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
self.checkBroadcast()
# other objects don't require other types of tests
def checkMessage(self): # pylint: disable=no-self-use
def checkMessage(self):
""""Message" object type checks."""
# pylint: disable=no-self-use
return
def checkGetpubkey(self):
""""Getpubkey" object type checks."""
if len(self.data) < 42:
logger.info(
'getpubkey message doesn\'t contain enough data. Ignoring.')
logger.info('getpubkey message doesn\'t contain enough data. Ignoring.')
raise BMObjectInvalidError()
def checkPubkey(self):
""""Pubkey" object type checks."""
# sanity check
if len(self.data) < 146 or len(self.data) > 440:
if len(self.data) < 146 or len(self.data) > 440: # sanity check
logger.info('pubkey object too short or too long. Ignoring.')
raise BMObjectInvalidError()
@ -154,9 +146,8 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
""""Broadcast" object type checks."""
if len(self.data) < 180:
logger.debug(
'The payload length of this broadcast'
' packet is unreasonably low. Someone is probably'
' trying funny business. Ignoring message.')
'The payload length of this broadcast packet is unreasonably low.'
' Someone is probably trying funny business. Ignoring message.')
raise BMObjectInvalidError()
# 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 hashlib
import logging
import socket
import struct
import time
@ -16,26 +16,20 @@ import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from debug import logger
from inventory import Inventory
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.bmobject import (
BMObject, BMObjectInsufficientPOWError, BMObjectInvalidDataError,
BMObjectExpiredError, BMObjectUnwantedStreamError,
BMObjectInvalidError, BMObjectAlreadyHaveError)
from network.node import Node
from network.proxy import ProxyError
from node import Node, Peer
from objectracker import ObjectTracker, missingObjects
from queues import invQueue, objectProcessorQueue, portCheckerQueue
from objectracker import missingObjects, ObjectTracker
from queues import objectProcessorQueue, portCheckerQueue, invQueue, addrQueue
from randomtrackingdict import RandomTrackingDict
logger = logging.getLogger('default')
class BMProtoError(ProxyError):
"""A Bitmessage Protocol Base Error"""
@ -55,17 +49,26 @@ class BMProtoExcessiveDataError(BMProtoError):
class BMProto(AdvancedDispatcher, ObjectTracker):
"""A parser for the Bitmessage Protocol"""
# 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
def __init__(self, address=None, sock=None):
# pylint: disable=unused-argument, super-init-not-called
def __init__(self, address=None, sock=None): # pylint: disable=unused-argument, super-init-not-called
AdvancedDispatcher.__init__(self, sock)
self.isOutbound = False
# packet/connection from a local IP
self.local = False
self.pendingUpload = RandomTrackingDict()
# canonical identifier of network group
self.network_group = None
def bm_proto_reset(self):
"""Reset the bitmessage object parser"""
@ -93,7 +96,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.close_reason = "Bad magic"
self.set_state("close")
return False
if self.payloadLength > MAX_MESSAGE_SIZE:
if self.payloadLength > BMProto.maxMessageSize:
self.invalid = True
self.set_state(
"bm_command",
@ -162,8 +165,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def decode_payload_varint(self):
"""Decode a varint from the payload"""
value, offset = addresses.decodeVarint(
self.payload[self.payloadOffset:])
value, offset = addresses.decodeVarint(self.payload[self.payloadOffset:])
self.payloadOffset += offset
return value
@ -185,8 +187,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
return Node(services, host, port)
# pylint: disable=too-many-branches, too-many-statements
def decode_payload_content(self, pattern="v"):
def decode_payload_content(self, pattern="v"): # pylint: disable=too-many-branches, too-many-statements
"""
Decode the payload depending on pattern:
@ -202,8 +204,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
, = end of array
"""
# pylint: disable=inconsistent-return-statements
def decode_simple(self, char="v"):
def decode_simple(self, char="v"): # pylint: disable=inconsistent-return-statements
"""Decode the payload using one char pattern"""
if char == "v":
return self.decode_payload_varint()
@ -313,11 +314,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def bm_command_error(self):
"""Decode an error message and log it"""
err_values = self.decode_payload_content("vvlsls")
fatalStatus = err_values[0]
# banTime = err_values[1]
# inventoryVector = err_values[2]
errorText = err_values[3]
fatalStatus, banTime, inventoryVector, errorText = \
self.decode_payload_content("vvlsls")
logger.error(
'%s:%i error: %i, %s', self.destination.host,
self.destination.port, fatalStatus, errorText)
@ -341,7 +339,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def _command_inv(self, dandelion=False):
items = self.decode_payload_content("l32s")
if len(items) > MAX_OBJECT_COUNT:
if len(items) > BMProto.maxObjectCount:
logger.error(
'Too many items in %sinv message!', 'd' if dandelion else '')
raise BMProtoExcessiveDataError()
@ -376,7 +374,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
nonce, expiresTime, objectType, version, streamNumber,
self.payload, self.payloadOffset)
if len(self.payload) - self.payloadOffset > MAX_OBJECT_PAYLOAD_SIZE:
if len(self.payload) - self.payloadOffset > BMProto.maxObjectPayloadSize:
logger.info(
'The payload length of this object is too large (%d bytes).'
' Ignoring it.', len(self.payload) - self.payloadOffset)
@ -412,10 +410,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
except KeyError:
pass
if self.object.inventoryHash in Inventory() and Dandelion().hasHash(
self.object.inventoryHash):
Dandelion().removeHash(
self.object.inventoryHash, "cycle detection")
if self.object.inventoryHash in Inventory() and Dandelion().hasHash(self.object.inventoryHash):
Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
Inventory()[self.object.inventoryHash] = (
self.object.objectType, self.object.streamNumber,
@ -434,46 +430,39 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
def bm_command_addr(self):
"""Incoming addresses, process them"""
# pylint: disable=redefined-outer-name
addresses = self._decode_addr()
for seenTime, stream, _, ip, port in addresses:
addresses = self._decode_addr() # pylint: disable=redefined-outer-name
for i in addresses:
seenTime, stream, services, ip, port = i
decodedIP = protocol.checkIPAddress(str(ip))
if stream not in state.streamsInWhichIAmParticipating:
continue
if (
decodedIP and time.time() - seenTime > 0 and
seenTime > time.time() - ADDRESS_ALIVE and
seenTime > time.time() - BMProto.addressAlive and
port > 0
):
peer = Peer(decodedIP, port)
peer = state.Peer(decodedIP, port)
try:
if knownnodes.knownNodes[stream][peer]["lastseen"] > \
seenTime:
if knownnodes.knownNodes[stream][peer]["lastseen"] > seenTime:
continue
except KeyError:
pass
if len(knownnodes.knownNodes[stream]) < \
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
if len(knownnodes.knownNodes[stream]) < BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
with knownnodes.knownNodesLock:
try:
knownnodes.knownNodes[stream][peer]["lastseen"] = \
seenTime
knownnodes.knownNodes[stream][peer]["lastseen"] = seenTime
except (TypeError, KeyError):
knownnodes.knownNodes[stream][peer] = {
"lastseen": seenTime,
"rating": 0,
"self": False,
}
# since we don't track peers outside of knownnodes,
# only spread if in knownnodes to prevent flood
# DISABLED TO WORKAROUND FLOOD/LEAK
# addrQueue.put((stream, peer, seenTime,
# self.destination))
addrQueue.put((stream, peer, self.destination))
return True
def bm_command_portcheck(self):
"""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
def bm_command_ping(self):
@ -519,7 +508,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.timeOffset = self.timestamp - int(time.time())
logger.debug('remoteProtocolVersion: %i', self.remoteProtocolVersion)
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(
'remote node incoming address: %s:%i',
@ -549,8 +538,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
length=self.payloadLength, expectBytes=0)
return False
# pylint: disable=too-many-return-statements
def peerValidityChecks(self):
def peerValidityChecks(self): # pylint: disable=too-many-return-statements
"""Check the validity of the peer"""
if self.remoteProtocolVersion < 3:
self.append_write_buf(protocol.assembleErrorMessage(
@ -560,16 +548,16 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
'Closing connection to old protocol version %s, node: %s',
self.remoteProtocolVersion, self.destination)
return False
if self.timeOffset > MAX_TIME_OFFSET:
if self.timeOffset > BMProto.maxTimeOffset:
self.append_write_buf(protocol.assembleErrorMessage(
errorText="Your time is too far in the future"
" compared to mine. Closing connection.", fatal=2))
errorText="Your time is too far in the future compared to mine."
" Closing connection.", fatal=2))
logger.info(
"%s's time is too far in the future (%s seconds)."
" Closing connection to it.", self.destination, self.timeOffset)
BMProto.timeOffsetWrongCount += 1
return False
elif self.timeOffset < -MAX_TIME_OFFSET:
elif self.timeOffset < -BMProto.maxTimeOffset:
self.append_write_buf(protocol.assembleErrorMessage(
errorText="Your time is too far in the past compared to mine."
" Closing connection.", fatal=2))
@ -585,8 +573,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
errorText="We don't have shared stream interests."
" Closing connection.", fatal=2))
logger.debug(
'Closed connection to %s because there is no overlapping'
' interest in streams.', self.destination)
'Closed connection to %s because there is no overlapping interest'
' in streams.', self.destination)
return False
if self.destination in connectionpool.BMConnectionPool().inboundConnections:
try:
@ -595,8 +583,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
errorText="Too many connections from your IP."
" Closing connection.", fatal=2))
logger.debug(
'Closed connection to %s because we are already'
' connected to that IP.', self.destination)
'Closed connection to %s because we are already connected'
' to that IP.', self.destination)
return False
except:
pass
@ -604,14 +592,12 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
# incoming from a peer we're connected to as outbound,
# or server full report the same error to counter deanonymisation
if (
Peer(self.destination.host, self.peerNode.port)
in connectionpool.BMConnectionPool().inboundConnections
or len(connectionpool.BMConnectionPool().inboundConnections)
+ len(connectionpool.BMConnectionPool().outboundConnections)
> BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxtotalconnections')
+ BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxbootstrapconnections')
state.Peer(self.destination.host, self.peerNode.port) in
connectionpool.BMConnectionPool().inboundConnections or
len(connectionpool.BMConnectionPool().inboundConnections) +
len(connectionpool.BMConnectionPool().outboundConnections) >
BMConfigParser().safeGetInt("bitmessagesettings", "maxtotalconnections") +
BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections")
):
self.append_write_buf(protocol.assembleErrorMessage(
errorText="Server full, please try again later.", fatal=2))
@ -631,10 +617,36 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
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
def stopDownloadingObject(hashId, forwardAnyway=False):
"""Stop downloading an object"""
for connection in connectionpool.BMConnectionPool().connections():
for connection in (
connectionpool.BMConnectionPool().inboundConnections.values() +
connectionpool.BMConnectionPool().outboundConnections.values()
):
try:
del connection.objectsNewToMe[hashId]
except KeyError:
@ -675,7 +687,7 @@ class BMStringParser(BMProto):
"""
def __init__(self):
super(BMStringParser, self).__init__()
self.destination = Peer('127.0.0.1', 8444)
self.destination = state.Peer('127.0.0.1', 8444)
self.payload = None
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 knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from debug import logger
from queues import Queue, portCheckerQueue
logger = logging.getLogger('default')
def getDiscoveredPeer():
"""Get a peer from the local peer discovery list"""
try:
peer = random.choice(state.discoveredPeers.keys())
except (IndexError, KeyError):
@ -28,11 +21,10 @@ def getDiscoveredPeer():
def chooseConnection(stream):
"""Returns an appropriate connection"""
haveOnion = BMConfigParser().safeGet(
"bitmessagesettings", "socksproxytype")[0:5] == 'SOCKS'
onionOnly = BMConfigParser().safeGetBoolean(
"bitmessagesettings", "onionservicesonly")
if state.trustedPeer:
return state.trustedPeer
try:
retval = portCheckerQueue.get(False)
portCheckerQueue.task_done()
@ -46,23 +38,15 @@ def chooseConnection(stream):
for _ in range(50):
peer = random.choice(knownnodes.knownNodes[stream].keys())
try:
peer_info = knownnodes.knownNodes[stream][peer]
if peer_info.get('self'):
continue
rating = peer_info["rating"]
rating = knownnodes.knownNodes[stream][peer]['rating']
except TypeError:
logger.warning('Error in %s', peer)
rating = 0
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
if peer.host.endswith('.onion') and rating > 0:
rating = 1
# TODO: need better check
elif not peer.host.startswith('bootstrap'):
else:
encodedAddr = protocol.encodeHost(peer.host)
# don't connect to local IPs when using SOCKS
if not protocol.checkIPAddress(encodedAddr, False):

View File

@ -1,49 +1,32 @@
"""
`BMConnectionPool` class definition
src/network/connectionpool.py
==================================
"""
import errno
import logging
import re
import socket
import sys
import time
import asyncore_pollchoose as asyncore
import helper_bootstrap
import helper_random
import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from connectionchooser import chooseConnection
from node import Peer
from debug import logger
from proxy import Proxy
from singleton import Singleton
from tcp import (
bootstrap, Socks4aBMConnection, Socks5BMConnection,
TCPConnection, TCPServer)
TCPServer, Socks5BMConnection, Socks4aBMConnection, TCPConnection)
from udp import UDPSocket
logger = logging.getLogger('default')
@Singleton
# pylint: disable=too-many-instance-attributes
class BMConnectionPool(object):
"""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):
asyncore.set_rates(
BMConfigParser().safeGetInt(
@ -56,33 +39,9 @@ class BMConnectionPool(object):
self.listeningSockets = {}
self.udpSockets = {}
self.streams = []
self._lastSpawned = 0
self._spawnWait = 2
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]
self.lastSpawned = 0
self.spawnWait = 2
self.bootstrapped = False
def connectToStream(self, streamNumber):
"""Connect to a bitmessage stream"""
@ -113,7 +72,10 @@ class BMConnectionPool(object):
def isAlreadyConnected(self, nodeid):
"""Check if we're already connected to this peer"""
for i in self.connections():
for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
try:
if nodeid == i.nodeid:
return True
@ -139,7 +101,7 @@ class BMConnectionPool(object):
if isinstance(connection, UDPSocket):
del self.udpSockets[connection.listening.host]
elif isinstance(connection, TCPServer):
del self.listeningSockets[Peer(
del self.listeningSockets[state.Peer(
connection.destination.host, connection.destination.port)]
elif connection.isOutbound:
try:
@ -165,11 +127,10 @@ class BMConnectionPool(object):
"bitmessagesettings", "onionbindip")
else:
host = '127.0.0.1'
if (
BMConfigParser().safeGetBoolean("bitmessagesettings", "sockslisten")
or BMConfigParser().safeGet("bitmessagesettings", "socksproxytype")
== "none"
):
if (BMConfigParser().safeGetBoolean(
"bitmessagesettings", "sockslisten") or
BMConfigParser().safeGet(
"bitmessagesettings", "socksproxytype") == "none"):
# python doesn't like bind + INADDR_ANY?
# host = socket.INADDR_ANY
host = BMConfigParser().get("network", "bind")
@ -199,37 +160,8 @@ class BMConnectionPool(object):
udpSocket = UDPSocket(host=bind, announcing=True)
self.udpSockets[udpSocket.listening.host] = udpSocket
def startBootstrappers(self):
"""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
def loop(self): # pylint: disable=too-many-branches, too-many-statements
"""Main Connectionpool's loop"""
# pylint: disable=too-many-locals
# defaults to empty loop if outbound connections are maxed
spawnConnections = False
acceptConnections = True
@ -243,22 +175,19 @@ class BMConnectionPool(object):
'bitmessagesettings', 'socksproxytype', '')
onionsocksproxytype = BMConfigParser().safeGet(
'bitmessagesettings', 'onionsocksproxytype', '')
if (
socksproxytype[:5] == 'SOCKS'
and not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'sockslisten')
and '.onion' not in BMConfigParser().safeGet(
'bitmessagesettings', 'onionhostname', '')
):
if (socksproxytype[:5] == 'SOCKS' and
not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'sockslisten') and
'.onion' not in BMConfigParser().safeGet(
'bitmessagesettings', 'onionhostname', '')):
acceptConnections = False
# pylint: disable=too-many-nested-blocks
if spawnConnections:
if not knownnodes.knownNodesActual:
self.startBootstrappers()
knownnodes.knownNodesActual = True
if not self._bootstrapped:
self._bootstrapped = True
helper_bootstrap.dns()
if not self.bootstrapped:
self.bootstrapped = True
Proxy.proxy = (
BMConfigParser().safeGet(
'bitmessagesettings', 'sockshostname'),
@ -287,7 +216,7 @@ class BMConnectionPool(object):
for i in range(
state.maximumNumberOfHalfOpenConnections - pending):
try:
chosen = self.trustedPeer or chooseConnection(
chosen = chooseConnection(
helper_random.randomchoice(self.streams))
except ValueError:
continue
@ -298,22 +227,10 @@ class BMConnectionPool(object):
# don't connect to self
if chosen in state.ownAddresses:
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:
if chosen.host.endswith(".onion") and Proxy.onion_proxy:
if (chosen.host.endswith(".onion") and
Proxy.onion_proxy is not None):
if onionsocksproxytype == "SOCKS5":
self.addConnection(Socks5BMConnection(chosen))
elif onionsocksproxytype == "SOCKS4a":
@ -328,9 +245,12 @@ class BMConnectionPool(object):
if e.errno == errno.ENETUNREACH:
continue
self._lastSpawned = time.time()
self.lastSpawned = time.time()
else:
for i in self.connections():
for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
# FIXME: rating will be increased after next connection
i.handle_close()
@ -340,7 +260,7 @@ class BMConnectionPool(object):
self.startListening()
else:
for bind in re.sub(
r'[^\w.]+', ' ',
'[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
BMConfigParser().safeGet('network', 'bind')
).split():
self.startListening(bind)
@ -350,7 +270,7 @@ class BMConnectionPool(object):
self.startUDPSocket()
else:
for bind in re.sub(
r'[^\w.]+', ' ',
'[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
BMConfigParser().safeGet('network', 'bind')
).split():
self.startUDPSocket(bind)
@ -368,13 +288,16 @@ class BMConnectionPool(object):
i.accepting = i.connecting = i.connected = False
logger.info('Stopped udp sockets.')
loopTime = float(self._spawnWait)
if self._lastSpawned < time.time() - self._spawnWait:
loopTime = float(self.spawnWait)
if self.lastSpawned < time.time() - self.spawnWait:
loopTime = 2.0
asyncore.loop(timeout=loopTime, count=1000)
reaper = []
for i in self.connections():
for i in (
self.inboundConnections.values() +
self.outboundConnections.values()
):
minTx = time.time() - 20
if i.fullyEstablished:
minTx -= 300 - 20
@ -386,8 +309,10 @@ class BMConnectionPool(object):
time.time() - i.lastTx)
i.set_state("close")
for i in (
self.connections()
+ self.listeningSockets.values() + self.udpSockets.values()
self.inboundConnections.values() +
self.outboundConnections.values() +
self.listeningSockets.values() +
self.udpSockets.values()
):
if not (i.accepting or i.connecting or i.connected):
reaper.append(i)

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