Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/test different params #59

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# IDE junk files
.idea/*
*.pyc
*~
#*#
tmp*
ec2/logs/*
ec2/logs_old/*
ec2/hosts
*_keys
*.keys

# Unit test / coverage reports
.cache
logs/
*__pycache__*
.coverage
.coverage.*
coverage.xml
htmlcov/
.pytest_cache

# Sphinx documentation
docs/_build/
*.pyc
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV B 16

RUN apt-get update && apt-get -y install bison flex libgmp-dev libmpc-dev

RUN wget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
RUN wget --no-check-certificate https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
RUN tar -xvf pbc-0.5.14.tar.gz
RUN cd pbc-0.5.14 && ./configure && make && make install

Expand Down
11 changes: 11 additions & 0 deletions honeybadgerbft/core/honeybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def broadcast_receiver_loop(recv_func, recv_queues):
broadcast_receiver(recv_func, recv_queues)




class HoneyBadgerBFT():
r"""HoneyBadgerBFT object used to run the protocol.

Expand Down Expand Up @@ -89,6 +91,9 @@ def submit_tx(self, tx):
print('submit_tx', self.pid, tx)
self.transaction_buffer.append(tx)

def _prepare_transaction_buffer(self):
pass

def run(self):
"""Run the HoneyBadgerBFT protocol."""

Expand Down Expand Up @@ -121,6 +126,7 @@ def _recv():
self._per_round_recv[r] = Queue()

# Select all the transactions (TODO: actual random selection)
self._prepare_transaction_buffer()
tx_to_send = self.transaction_buffer[:self.B]

# TODO: Wait a bit if transaction buffer is not full
Expand Down Expand Up @@ -249,3 +255,8 @@ def tpke_bcast(o):
_input.get,
acs_in=my_rbc_input.put_nowait, acs_out=acs.get,
tpke_bcast=tpke_bcast, tpke_recv=tpke_recv.get)


class ImprovedHoneyBadgerBFT(HoneyBadgerBFT):
def _prepare_transaction_buffer(self):
self.transaction_buffer = sorted(self.transaction_buffer, key=len, reverse=(self.pid%2 == 1))
Binary file added our_srcs/__pycache__/consts.cpython-37.pyc
Binary file not shown.
Binary file added our_srcs/__pycache__/utils.cpython-37.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions our_srcs/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from honeybadgerbft.core.honeybadger import HoneyBadgerBFT, ImprovedHoneyBadgerBFT

LOG_DIR = './logs'


LOG_PATH = LOG_DIR + '/honeybadger_test_{}_{}_{}_{}_{}_{}.log'
LOGGER_NAME = 'honeybadger_test_logger'
NUM_OF_NODE_OPTIONS = [4, 6]
NUM_OF_IDENTICAL_INPUTS_OPTIONS = [0, 2, 4]
NUM_OF_INPUTS_IN_ITERATION = 3
INPUT_SIZES = [2, 1024, 1024*1024]
DEFAULT_NUM_OF_NODES = NUM_OF_NODE_OPTIONS[-1]
DEFAULT_NUM_OF_IDENTICAL_INPUTS_OPTIONS = NUM_OF_IDENTICAL_INPUTS_OPTIONS[-1]
DEFAULT_INPUT_SIZE = INPUT_SIZES[-1]
HONEYBADGERS = [("Regular Honeybadger", HoneyBadgerBFT), ("Parity Honeybadger", ImprovedHoneyBadgerBFT)]
85 changes: 85 additions & 0 deletions our_srcs/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import logging
from our_srcs.consts import *
import datetime
import random
import math

from honeybadgerbft.crypto.threshsig.boldyreva import dealer
from honeybadgerbft.crypto.threshenc import tpke
import gevent
from gevent.event import Event
from gevent.queue import Queue


def setup_logging():
if not os.path.isdir(LOG_DIR):
os.mkdir(LOG_DIR)


logger = logging.getLogger(LOGGER_NAME)
logger.setLevel(logging.DEBUG)

formatter = logging.Formatter('(%(asctime)s) %(levelname)s: %(message)s', datefmt='%H:%M:%S')

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

cur_time = datetime.datetime.now()
fi = logging.FileHandler(LOG_PATH.format(cur_time.year, cur_time.month, cur_time.day, cur_time.hour,
cur_time.minute, cur_time.second))
fi.setLevel(logging.DEBUG)
fi.setFormatter(formatter)

logger.addHandler(ch)
logger.addHandler(fi)

def setup_honeybadgers(honeybadger_class, N):
sid = 'sidA'
# Generate threshold sig keys
sPK, sSKs = dealer(N, 2, seed=None)
# Generate threshold enc keys
ePK, eSKs = tpke.dealer(N, 2)

rnd = random.Random(None)
#print 'SEED:', seed
router_seed = rnd.random()
sends, recvs = simple_router(N, seed=router_seed)

badgers = [None] * N
threads = [None] * N
for i in range(N):
badgers[i] = HB(sid, i, 1, N, 1,
sPK, sSKs[i], ePK, eSKs[i],
sends[i], recvs[i])
threads[i] = gevent.spawn(badgers[i].run)

def simple_router(N, maxdelay=0.005, seed=None):
"""Builds a set of connected channels, with random delay

:return: (receives, sends)
"""
rnd = random.Random(seed)
#if seed is not None: print 'ROUTER SEED: %f' % (seed,)

queues = [Queue() for _ in range(N)]
_threads = []

def makeSend(i):
def _send(j, o):
delay = rnd.random() * maxdelay
delay *= math.log(len(o)) * 7.5
gevent.spawn_later(delay, queues[j].put_nowait, (i,o))
return _send

def makeRecv(j):
def _recv():
(i,o) = queues[j].get()
#print 'RECV %8s [%2d -> %2d]' % (o[0], i, j)
return (i,o)
return _recv

return ([makeSend(i) for i in range(N)],
[makeRecv(j) for j in range(N)])


Empty file removed test/__init__.py
Empty file.
Loading