Beispiel #1
0
    def setUp(self):
        datastore.create_database(":memory:")
        self.test_hash = "87e0555568bf5c7e4debd6645fc3f41e88df6ca8"
        self.test_hash2 = "97e0555568bf5c7e4debd6645fc3f41e88df6ca8"
        self.test_file = "Contents of test.txt"
        self.test_file2 = "Contents of test2.txt"

        self.sp = Profile()
        self.sp.name = "Test User"
        self.sp.encryption_key = "Key"
        self.sp.location = CountryCode.Value('UNITED_STATES')

        self.serialized_listings = Listings()
        self.lm = self.serialized_listings.ListingMetadata()
        self.lm.contract_hash = self.test_hash
        self.lm.title = "TEST CONTRACT TITLE"
        self.lm.price = 0
        self.lm.currency_code = "USD"
        self.lm.nsfw = False
        self.lm.origin = CountryCode.Value('ALL')

        self.hm = datastore.HashMap()
        self.hm.delete_all()

        self.ps = datastore.ProfileStore()
        self.ls = datastore.ListingsStore()
        self.ks = datastore.KeyStore()
    def setUp(self):
        datastore.create_database("test.db")
        datastore.DATABASE = "test.db"
        self.test_hash = "87e0555568bf5c7e4debd6645fc3f41e88df6ca8"
        self.test_hash2 = "97e0555568bf5c7e4debd6645fc3f41e88df6ca8"
        self.test_file = "Contents of test.txt"
        self.test_file2 = "Contents of test2.txt"

        self.sp = Profile()
        self.key = Profile().PublicKey()
        self.key.public_key = "Key"
        self.key.signature = "Sig"
        self.sp.name = "Test User"
        self.sp.encryption_key.MergeFrom(self.key)
        self.sp.location = CountryCode.Value('UNITED_STATES')

        self.serialized_listings = Listings()
        self.lm = self.serialized_listings.ListingMetadata()
        self.lm.contract_hash = self.test_hash
        self.lm.title = "TEST CONTRACT TITLE"
        self.lm.price = 0
        self.lm.currency_code = "USD"
        self.lm.nsfw = False
        self.lm.origin = CountryCode.Value('ALL')

        self.u = Following.User()
        self.u.guid = '0000000000000000000000000000000000'
        self.u.signed_pubkey = 'signed_pubkey'

        self.m = Metadata()
        self.m.name = 'Test User'
        self.m.handle = '@TestUser'
        self.m.avatar_hash = ''
        self.m.nsfw = False
        self.u.metadata.MergeFrom(self.m)

        self.f = Followers.Follower()
        self.f.guid = '0000000000000000000000000000000001'
        self.f.following = ''
        self.f.signed_pubkey = ''
        self.f.metadata.MergeFrom(self.m)

        self.hm = datastore.HashMap()
        self.hm.delete_all()

        self.ps = datastore.ProfileStore()
        self.ls = datastore.ListingsStore()
        self.ks = datastore.KeyStore()
        self.fd = datastore.FollowData()
        self.ms = datastore.MessageStore()
        self.ns = datastore.NotificationStore()
        self.vs = datastore.VendorStore()
    def setUp(self):
        datastore.create_database("test.db")
        datastore.DATABASE = "test.db"
        self.public_ip = '123.45.67.89'
        self.port = 12345
        self.own_addr = (self.public_ip, self.port)
        self.addr1 = ('132.54.76.98', 54321)
        self.addr2 = ('231.76.45.89', 15243)

        self.clock = task.Clock()
        connection.REACTOR.callLater = self.clock.callLater

        self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
        self.handler_mock = mock.Mock(spec_set=connection.Handler)
        self.con = connection.Connection(
            self.proto_mock,
            self.handler_mock,
            self.own_addr,
            self.addr1
        )

        valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
        self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
        verify_key = self.signing_key.verify_key
        signed_pubkey = self.signing_key.sign(str(verify_key))
        h = nacl.hash.sha512(signed_pubkey)
        self.storage = ForgetfulStorage()
        self.node = Node(unhexlify(h[:40]), self.public_ip, self.port, signed_pubkey, True)
        self.protocol = KademliaProtocol(self.node, self.storage, 20)

        self.wire_protocol = OpenBazaarProtocol(self.own_addr)
        self.wire_protocol.register_processor(self.protocol)

        self.protocol.connect_multiplexer(self.wire_protocol)
        self.handler = self.wire_protocol.ConnHandler([self.protocol], self.wire_protocol)
        self.handler.connection = self.con

        transport = mock.Mock(spec_set=udp.Port)
        ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
        transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
        self.wire_protocol.makeConnection(transport)
    def setUp(self):
        datastore.create_database("test.db")
        datastore.DATABASE = "test.db"
        self.public_ip = '123.45.67.89'
        self.port = 12345
        self.own_addr = (self.public_ip, self.port)
        self.addr1 = ('132.54.76.98', 54321)
        self.addr2 = ('231.76.45.89', 15243)

        self.clock = task.Clock()
        connection.REACTOR.callLater = self.clock.callLater

        self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
        self.handler_mock = mock.Mock(spec_set=connection.Handler)
        self.con = connection.Connection(self.proto_mock, self.handler_mock,
                                         self.own_addr, self.addr1)

        valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
        self.signing_key = nacl.signing.SigningKey(
            valid_key, encoder=nacl.encoding.HexEncoder)
        verify_key = self.signing_key.verify_key
        signed_pubkey = self.signing_key.sign(str(verify_key))
        h = nacl.hash.sha512(signed_pubkey)
        self.storage = ForgetfulStorage()
        self.node = Node(unhexlify(h[:40]), self.public_ip, self.port,
                         signed_pubkey, True)
        self.protocol = KademliaProtocol(self.node, self.storage, 20)

        self.wire_protocol = OpenBazaarProtocol(self.own_addr)
        self.wire_protocol.register_processor(self.protocol)

        self.protocol.connect_multiplexer(self.wire_protocol)
        self.handler = self.wire_protocol.ConnHandler([self.protocol],
                                                      self.wire_protocol)
        self.handler.connection = self.con

        transport = mock.Mock(spec_set=udp.Port)
        ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
        transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
        self.wire_protocol.makeConnection(transport)
Beispiel #5
0
logFile = logfile.LogFile.fromFullPath(DATA_FOLDER + "debug.log")
log.addObserver(log.FileLogObserver(logFile).emit)
log.startLogging(sys.stdout)

# stun
print "Finding NAT Type.."
response = stun.get_ip_info(stun_host='seed.openbazaar.org',
                            stun_port=3478,
                            source_port=0)
print "%s on %s:%s" % (response[0], response[1], response[2])
ip_address = response[1]
port = response[2]

# database
if not os.path.isfile(DATABASE):
    create_database()

# key generation
keys = KeyChain()


def on_bootstrap_complete(resp):
    mlistener = MessageListenerImpl(ws_factory)
    mserver.get_messages(mlistener)
    mserver.protocol.add_listener(mlistener)
    nlistener = NotificationListenerImpl(ws_factory)
    mserver.protocol.add_listener(nlistener)


protocol = OpenBazaarProtocol((ip_address, port))
# logging
logFile = logfile.LogFile.fromFullPath(DATA_FOLDER + "debug.log")
log.addObserver(log.FileLogObserver(logFile).emit)
log.startLogging(sys.stdout)

# stun
print "Finding NAT Type.."
response = stun.get_ip_info(stun_host="stun.l.google.com", source_port=18467, stun_port=19302)
print "%s on %s:%s" % (response[0], response[1], response[2])
ip_address = response[1]
port = response[2]

# database
if not os.path.isfile(DATABASE):
    create_database()

# key generation
keys = KeyChain()

def on_bootstrap_complete(resp):
    mlistener = MessageListenerImpl(ws_factory)
    mserver.get_messages(mlistener)
    mserver.protocol.add_listener(mlistener)
    nlistener = NotificationListenerImpl(ws_factory)
    mserver.protocol.add_listener(nlistener)

protocol = OpenBazaarProtocol((ip_address, port))

# kademlia
node = Node(keys.guid, ip_address, port, signed_pubkey=keys.guid_signed_pubkey)