Directory maintenance

- rearrange obsolete build scripts
- rearrange working build scripts
- add build / devel scripts I use
- add existing development tests (bloom filter, message encoding, thread
  interrupts)
- add directory descriptions
This commit is contained in:
Peter Šurda 2016-12-01 16:45:04 +01:00
parent 7ca6576dfc
commit 3033520995
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
37 changed files with 226 additions and 0 deletions

2
build/README.md Normal file
View File

@ -0,0 +1,2 @@
This directory contains scripts that are helpful for developers when building
or maintaining PyBitmessage.

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

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"

22
build/updatetranslations.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
if [ ! -f "$1" ]; then
echo "$1 not found, please specify the file name for source"
exit
fi
srcdir=`mktemp -d`
unzip "$1" -d $srcdir
for i in $srcdir/*ts; do
o=`basename $i|cut -b3-`
o="${o,,}"
o="${o//@/_}"
echo "$i -> $o"
mv "$i" "$HOME/src/PyBitmessage/src/translations/$o"
done
rm -rf -- $srcdir
lrelease-qt4 "$HOME/src/PyBitmessage/src/translations/bitmessage.pro"

3
dev/README.md Normal file
View File

@ -0,0 +1,3 @@
This directory contains code for future features, but it's not integrated into
PyBitmessage and may not work at all. Developers can look at it if they are
interested.

60
dev/bloomfiltertest.py Normal file
View File

@ -0,0 +1,60 @@
from math import ceil
from os import stat, getenv, path
from pybloom import BloomFilter as BloomFilter1
from pybloomfilter import BloomFilter as BloomFilter2
import sqlite3
from time import time
# Ubuntu: apt-get install python-pybloomfiltermmap
conn = sqlite3.connect(path.join(getenv("HOME"), '.config/PyBitmessage/messages.dat'))
conn.text_factory = str
cur = conn.cursor()
rawlen = 0
itemcount = 0
cur.execute('''SELECT COUNT(hash) FROM inventory''')
for row in cur.fetchall():
itemcount = row[0]
filtersize = 1000 * (int(itemcount / 1000) + 1)
errorrate = 1.0 / 1000.0
bf1 = BloomFilter1(capacity=filtersize, error_rate=errorrate)
bf2 = BloomFilter2(capacity=filtersize, error_rate=errorrate)
item = '''SELECT hash FROM inventory'''
cur.execute(item, '')
bf1time = 0
bf2time = 0
for row in cur.fetchall():
rawlen += len(row[0])
try:
times = [time()]
bf1.add(row[0])
times.append(time())
bf2.add(row[0])
times.append(time())
bf1time += times[1] - times[0]
bf2time += times[2] - times[1]
except IndexError:
pass
#f = open("/home/shurdeek/tmp/bloom.dat", "wb")
#sb1.tofile(f)
#f.close()
print "Item count: %i" % (itemcount)
print "Raw length: %i" % (rawlen)
print "Bloom filter 1 length: %i, reduction to: %.2f%%" % \
(bf1.bitarray.buffer_info()[1],
100.0 * bf1.bitarray.buffer_info()[1] / rawlen)
print "Bloom filter 1 capacity: %i and error rate: %.3f%%" % (bf1.capacity, 100.0 * bf1.error_rate)
print "Bloom filter 1 took %.2fs" % (bf1time)
print "Bloom filter 2 length: %i, reduction to: %.3f%%" % \
(bf2.num_bits / 8,
100.0 * bf2.num_bits / 8 / rawlen)
print "Bloom filter 2 capacity: %i and error rate: %.3f%%" % (bf2.capacity, 100.0 * bf2.error_rate)
print "Bloom filter 2 took %.2fs" % (bf2time)

27
dev/msgtest.py Normal file
View File

@ -0,0 +1,27 @@
import importlib
from os import listdir, path
from pprint import pprint
import sys
import traceback
data = {"": "message", "subject": "subject", "body": "body"}
#data = {"": "vote", "msgid": "msgid"}
#data = {"fsck": 1}
import messagetypes
if __name__ == '__main__':
try:
msgType = data[""]
except KeyError:
print "Message type missing"
sys.exit(1)
else:
print "Message type: %s" % (msgType)
msgObj = messagetypes.constructObject(data)
if msgObj is None:
sys.exit(1)
try:
msgObj.process()
except:
pprint(sys.exc_info())

49
dev/powinterrupttest.py Normal file
View File

@ -0,0 +1,49 @@
import ctypes
import hashlib
from multiprocessing import current_process
import os
import signal
from struct import unpack, pack
from threading import current_thread
shutdown = 0
def signal_handler(signal, frame):
global shutdown
print "Got signal %i in %s/%s" % (signal, current_process().name, current_thread().name)
if current_process().name != "MainProcess":
raise StopIteration("Interrupted")
if current_thread().name != "MainThread":
return
shutdown = 1
def _doCPoW(target, initialHash):
# global shutdown
h = initialHash
m = target
out_h = ctypes.pointer(ctypes.create_string_buffer(h, 64))
out_m = ctypes.c_ulonglong(m)
print "C PoW start"
for c in range(0, 200000):
print "Iter: %i" % (c)
nonce = bmpow(out_h, out_m)
if shutdown:
break
trialValue, = unpack('>Q', hashlib.sha512(hashlib.sha512(pack('>Q', nonce) + initialHash).digest()).digest()[0:8])
if shutdown != 0:
raise StopIteration("Interrupted")
print "C PoW done"
return [trialValue, nonce]
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
bso = ctypes.CDLL(os.path.join("bitmsghash", "bitmsghash.so"))
bmpow = bso.BitmessagePOW
bmpow.restype = ctypes.c_ulonglong
_doCPoW(2**44, "")

36
packages/README.md Normal file
View File

@ -0,0 +1,36 @@
The `generate.sh` script is obsolete, but is included for historical reasons.
Maintained packages can be obtained:
Windows:
========
https://github.com/Bitmessage/PyBitmessage/releases
Works on Windows XP or higher.
OSX:
====
https://github.com/Bitmessage/PyBitmessage/releases
Wors on OSX 10.7.5 or higher
Arch linux:
===========
Releases matching PyBitmessage releases:
https://aur.archlinux.org/packages/pybitmessage-git/
Development snapshot equivalent to the v0.6 git branch:
https://aur.archlinux.org/packages/pybitmessage-dev-git/
FreeBSD:
========
Use the FreeBSD ports.