diff --git a/Tribler/community/doubleentry/community.py b/Tribler/community/doubleentry/community.py index 6d1cd7d2e65..96bdec4c576 100644 --- a/Tribler/community/doubleentry/community.py +++ b/Tribler/community/doubleentry/community.py @@ -251,6 +251,8 @@ def validate_signature(public_key_binary, payload, signature): # Invalid public key. return False + def get_key(self): + return self._ec class DoubleEntrySettings(object): """ diff --git a/Tribler/community/doubleentry/experiments.py b/Tribler/community/doubleentry/experiments.py new file mode 100644 index 00000000000..2c9b1a370d1 --- /dev/null +++ b/Tribler/community/doubleentry/experiments.py @@ -0,0 +1,39 @@ +from Tribler.dispersy.crypto import ECCrypto + +__author__ = 'norberhuis' +""" +File containing experiments +""" + + +class NumericalExample: + + def __init__(self, double_entry_community): + self._community = double_entry_community + + def perform_experiment(self): + self.save_key_to_file(self._community.get_key()) + + message = self._community.create_signature_request_message() + + self.save_payload_to_file(message.payload.timestamp) + self.save_signature_to_file(message.payload.signature_requester) + + @staticmethod + def save_key_to_file(ec): + pem = ECCrypto().key_to_pem(ec) + f = open("key.pem", 'w') + f.write(pem) + f.close() + + @staticmethod + def save_payload_to_file(payload): + f = open("payload", 'w') + f.write(payload) + f.close() + + @staticmethod + def save_signature_to_file(signature): + f = open("signature", 'w') + f.write(signature) + f.close() diff --git a/Tribler/community/doubleentry/main.py b/Tribler/community/doubleentry/main.py index 0ea00f11d9f..17deabe7571 100644 --- a/Tribler/community/doubleentry/main.py +++ b/Tribler/community/doubleentry/main.py @@ -14,6 +14,8 @@ from Tribler.community.doubleentry.community import DoubleEntryCommunity from Tribler.community.doubleentry.community import DoubleEntrySettings +from Tribler.community.doubleentry.experiments import NumericalExample + from twisted.internet.threads import blockingCallFromThread from twisted.internet.stdio import StandardIO from twisted.protocols.basic import LineReceiver @@ -25,13 +27,13 @@ # Class that handles boot strapping the DoubleEntry Community. class DoubleEntry(object): """ - Class that handles boot strapping the DoubleEntry Community when running a single community instance without Tribler. + Class that handles boot strapping the DoubleEntry Community + when running a single community instance without Tribler. """ def __init__(self): """ Setup this class to be able to run the community with the run method. - :return: """ self.community = None self._member = None @@ -80,6 +82,9 @@ def start_community(): blockingCallFromThread(reactor, start_community) + def get_community(self): + return self.community + def signature_request(self): """ Instruct the community to send out a signature request. @@ -94,16 +99,18 @@ class CommandHandler(LineReceiver): from os import linesep delimiter = linesep - def __init__(self, doubleentry): - self.doubleentry = doubleentry + def __init__(self, double_entry): + self.double_entry = double_entry def connectionMade(self): self.transport.write('>>> ') - def lineReceived(self, line): if line == 'r': - self.doubleentry.signature_request() + self.double_entry.signature_request() + elif line == 'n': + experiment = NumericalExample(self.double_entry.get_community()) + experiment.perform_experiment() self.transport.write('>>> ')