Beispiel #1
0
    def __init__(self, store_file, my_market_ip, my_market_port, my_node_port,
                 my_node_file, seed_uri, market_id):

        self.transport = CryptoTransportLayer(my_market_ip, my_market_port,
                                              market_id, store_file)
        self.transport.join_network(seed_uri)

        data_store = SQLiteDataStore(
        )  # creates in-memory database, should be persistent
        known_nodes = self.known_entangled_nodes(my_node_file, seed_uri,
                                                 my_node_port)
        # initializes node with specified port and an in-memory SQLite database
        self.node = entangled.node.EntangledNode(udpPort=my_node_port,
                                                 dataStore=data_store)

        self.node.joinNetwork(known_nodes)

        self.market = Market(self.transport, self.node, store_file)

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, node=self.market))]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
class MarketApplication(tornado.web.Application):

    def __init__(self, market_ip, market_port, seed_uri, market_id, 
                    bm_user=None, bm_pass=None, bm_port=None):

        self.transport = CryptoTransportLayer(market_ip,
                                               market_port,
                                               market_id,
                                               bm_user,
                                               bm_pass,
                                               bm_port)

        self.transport.join_network(seed_uri)

        self.market = Market(self.transport)

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.dht._transport
Beispiel #3
0
class MarketApplication(tornado.web.Application):
    def __init__(self, store_file, my_market_ip, my_market_port, my_node_port,
                 my_node_file, seed_uri, market_id):

        self.transport = CryptoTransportLayer(my_market_ip, my_market_port,
                                              market_id, store_file)
        self.transport.join_network(seed_uri)

        data_store = SQLiteDataStore(
        )  # creates in-memory database, should be persistent
        known_nodes = self.known_entangled_nodes(my_node_file, seed_uri,
                                                 my_node_port)
        # initializes node with specified port and an in-memory SQLite database
        self.node = entangled.node.EntangledNode(udpPort=my_node_port,
                                                 dataStore=data_store)

        self.node.joinNetwork(known_nodes)

        self.market = Market(self.transport, self.node, store_file)

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, node=self.market))]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.transport

    # creates list of known node tuples either from node_file or the seed_uri
    def known_entangled_nodes(self, node_file, seed_uri, node_port):
        if node_file == None:
            if seed_uri == None:
                # need either node_file or seed_uri
                knownNodes = []
            else:
                # finds IP addresses in the seed_uri
                seed_ip = re.search(
                    r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}",
                    seed_uri)
                if seed_ip == None:
                    # if no IP address present, finds a text URL address
                    seed_ip = re.search(r"[a-z]*\.[a-z]*\.[a-z]*", suri)
                knownNodes = [(seed_ip.group(0), 47771)]
        else:
            knownNodes = []
            f = open(node_file, 'r')
            lines = f.readlines()
            f.close()
            for line in lines:
                ipAddress, udpPort = line.split()
                knownNodes.append((ipAddress, int(udpPort)))
        print("known_nodes for Entangled: " +
              " ".join(str(n) for n in knownNodes))
        return knownNodes
Beispiel #4
0
class MarketApplication(tornado.web.Application):

    def __init__(self, store_file, my_market_ip, my_market_port, my_node_port, my_node_file, seed_uri, market_id):

        self.transport = CryptoTransportLayer(my_market_ip,
                                              my_market_port,
                                              market_id,
                                              store_file)
        self.transport.join_network(seed_uri)

        data_store = SQLiteDataStore() # creates in-memory database, should be persistent
        known_nodes = self.known_entangled_nodes(my_node_file,seed_uri,my_node_port)
        # initializes node with specified port and an in-memory SQLite database
        self.node = entangled.node.EntangledNode(udpPort=my_node_port, dataStore=data_store)

        self.node.joinNetwork(known_nodes)

        
        self.market = Market(self.transport,self.node,store_file)
        
        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
             dict(transport=self.transport, node=self.market))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
        

    def get_transport(self):
        return self.transport

    # creates list of known node tuples either from node_file or the seed_uri
    def known_entangled_nodes(self,node_file,seed_uri,node_port):
        if node_file == None:
            if seed_uri == None:
                # need either node_file or seed_uri
                knownNodes = []
            else:
                # finds IP addresses in the seed_uri
                seed_ip = re.search(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}",seed_uri)
                if seed_ip == None:
                    # if no IP address present, finds a text URL address
                    seed_ip = re.search(r"[a-z]*\.[a-z]*\.[a-z]*",suri)
                knownNodes = [(seed_ip.group(0), 47771)]
        else:
            knownNodes = []
            f = open(node_file, 'r')
            lines = f.readlines()
            f.close()
            for line in lines:
                ipAddress, udpPort = line.split()
                knownNodes.append((ipAddress, int(udpPort)))
        print("known_nodes for Entangled: "+" ".join(str(n) for n in knownNodes));
        return knownNodes
Beispiel #5
0
class GatewayApplication(tornado.web.Application):
    def __init__(self, service):
        settings = dict(debug=True)
        settings.update(options.as_dict())
        # legacy support
        if config.get('legacy-url', False):
            if ws_legacy_enabled:
                self.ws_client = LegacyClient("wss://" +
                                              config.get('legacy-url'))
            else:
                print "legacy-url is configured but autobahn not installed"
                self.ws_client = False
        client = obelisk.ObeliskOfLightClient(service)
        self.obelisk_handler = obelisk_handler.ObeliskHandler(
            client, self.ws_client)
        self.brc_handler = broadcast.BroadcastHandler()
        self.p2p = CryptoTransportLayer(config.get('p2p-port', 8889),
                                        config.get('external-ip', '127.0.0.1'),
                                        config.get('internal-ip', None))
        self.p2p.join_network(config.get('seeds', []))
        self.json_chan_handler = jsonchan.JsonChanHandler(self.p2p)
        self.ticker_handler = ticker.TickerHandler()

        handlers = [
            # /block/<block hash>
            (r"/block/([^/]*)(?:/)?", rest_handlers.BlockHeaderHandler),

            # /block/<block hash>/transactions
            (r"/block/([^/]*)/transactions(?:/)?",
             rest_handlers.BlockTransactionsHandler),

            # /tx/
            (r"/tx(?:/)?", rest_handlers.TransactionPoolHandler),

            # /tx/<txid>
            (r"/tx/([^/]*)(?:/)?", rest_handlers.TransactionHandler),

            # /address/<address>
            (r"/address/([^/]*)(?:/)?", rest_handlers.AddressHistoryHandler),

            # /height
            (r"/height(?:/)?", rest_handlers.HeightHandler),

            # /height
            (r"/status(?:/)?", status.StatusHandler, {
                "app": self
            }),

            # /
            (r"/", QuerySocketHandler)
        ]

        tornado.web.Application.__init__(self, handlers, **settings)
class MarketApplication(tornado.web.Application):

    def __init__(self, market_ip, market_port, market_id=1,
                    bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                    seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip,
                                               market_port,
                                               market_id,
                                               db,
                                               bm_user,
                                               bm_pass,
                                               bm_port,
                                               seed_mode,
                                               dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport._dht._refreshNode()
            self.market.republish_contracts()

        if seed_mode == 0:
            self.transport.join_network(seed_peers, post_joined)
            ioloop.PeriodicCallback(self.transport.join_network, 60000)
        else:
            self.transport.join_network([], post_joined)
            ioloop.PeriodicCallback(self.transport.join_network, 60000)

        Thread(target=reactor.run, args=(False,)).start()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)




    def get_transport(self):
        return self.transport
Beispiel #7
0
class MarketApplication(tornado.web.Application):

    def __init__(self, market_ip, market_port, market_id=1,
                    bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                    seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip,
                                               market_port,
                                               market_id,
                                               db,
                                               bm_user,
                                               bm_pass,
                                               bm_port,
                                               seed_mode,
                                               dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport._dht._refreshNode()
            self.market.republish_contracts()

        if seed_mode == 0:
            self.transport.join_network(seed_peers, post_joined)
            ioloop.PeriodicCallback(self.transport.join_network, 60000)
        else:
            self.transport.join_network([], post_joined)
            ioloop.PeriodicCallback(self.transport.join_network, 60000)

        Thread(target=reactor.run, args=(False,)).start()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)




    def get_transport(self):
        return self.transport
Beispiel #8
0
class MarketApplication(tornado.web.Application):

    def __init__(self):
        settings = dict(debug=True)
        self.transport = CryptoTransportLayer(12345)
        self.transport.join_network()
        #self.protocol_handler = ProtocolHandler(self.transport)
        self.market = Market(self.transport)
        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler, dict(transport=self.transport, node=self.market))
        ]
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #9
0
class GatewayApplication(tornado.web.Application):

    def __init__(self, service):
        settings = dict(debug=True)
        settings.update(options.as_dict())
        # legacy support
        if config.get('legacy-url', False):
            if ws_legacy_enabled:
                self.ws_client = LegacyClient("wss://"+config.get('legacy-url'))
            else:
                print "legacy-url is configured but autobahn not installed"
                self.ws_client = False
        client = obelisk.ObeliskOfLightClient(service)
        self.obelisk_handler = obelisk_handler.ObeliskHandler(client, self.ws_client)
        self.brc_handler = broadcast.BroadcastHandler()
        self.p2p = CryptoTransportLayer(config.get('p2p-port', 8889), config.get('external-ip', '127.0.0.1'), config.get('internal-ip', None))
        self.p2p.join_network(config.get('seeds', []))
        self.json_chan_handler = jsonchan.JsonChanHandler(self.p2p)
        self.ticker_handler = ticker.TickerHandler()

        handlers = [
            # /block/<block hash>
            (r"/block/([^/]*)(?:/)?", rest_handlers.BlockHeaderHandler),

            # /block/<block hash>/transactions
            (r"/block/([^/]*)/transactions(?:/)?",
                rest_handlers.BlockTransactionsHandler),

            # /tx/
            (r"/tx(?:/)?", rest_handlers.TransactionPoolHandler),

            # /tx/<txid>
            (r"/tx/([^/]*)(?:/)?", rest_handlers.TransactionHandler),

            # /address/<address>
            (r"/address/([^/]*)(?:/)?", rest_handlers.AddressHistoryHandler),

            # /height
            (r"/height(?:/)?", rest_handlers.HeightHandler),

            # /height
            (r"/status(?:/)?", status.StatusHandler, {"app": self}),

            # /
            (r"/", QuerySocketHandler)
        ]

        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #10
0
    def __init__(self, market_ip, market_port, market_id=1,
                    bm_user=None, bm_pass=None, bm_port=None, seed_mode=0, dev_mode=False):

        self.transport = CryptoTransportLayer(market_ip,
                                               market_port,
                                               market_id,
                                               bm_user,
                                               bm_pass,
                                               bm_port,
                                               seed_mode,
                                               dev_mode)

        if seed_mode == 0:
            self.transport.join_network(dev_mode=dev_mode)

        self.market = Market(self.transport)

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #11
0
    def __init__(self, market_ip, market_port, market_id=1,
                    bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                    seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)
        self.transport = CryptoTransportLayer(market_ip,
                                               market_port,
                                               market_id,
                                               db,
                                               bm_user,
                                               bm_pass,
                                               bm_port,
                                               seed_mode,
                                               dev_mode)

        if seed_mode == 0:
            self.transport.join_network(seed_peers)

        self.market = Market(self.transport, db)
        self.market.republish_contracts()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #12
0
    def __init__(self, store_file, my_market_ip, my_market_port, my_node_port, my_node_file, seed_uri, market_id):

        self.transport = CryptoTransportLayer(my_market_ip,
                                              my_market_port,
                                              market_id,
                                              store_file)
        self.transport.join_network(seed_uri)

        data_store = SQLiteDataStore() # creates in-memory database, should be persistent
        known_nodes = self.known_entangled_nodes(my_node_file,seed_uri,my_node_port)
        # initializes node with specified port and an in-memory SQLite database
        self.node = entangled.node.EntangledNode(udpPort=my_node_port, dataStore=data_store)

        self.node.joinNetwork(known_nodes)

        
        self.market = Market(self.transport,self.node,store_file)
        
        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
             dict(transport=self.transport, node=self.market))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #13
0
    def update_listings_index(self):

        # Store to marketplace listing index
        contract_index_key = hashlib.sha1('contracts-%s' %
                                          self.transport.guid).hexdigest()
        hashvalue = hashlib.new('ripemd160')
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self.db.selectEntries("contracts",
                                              "market_id = '%s'" %
                                              self.transport.market_id.replace("'", "''"))
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id['key'])

        self.log.debug('My Contracts: %s' % my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({'guid': self.transport.guid,
                           'contracts': my_contracts})
        signature = CryptoTransportLayer.makeCryptor(self.transport.settings['secret']).sign(data_string).encode('hex')

        value = {'signature': signature,
                 'data': {'guid': self.transport.guid,
                          'contracts': my_contracts}}

        # Pass off to thread to keep GUI snappy
        self.transport.dht.iterativeStore(self.transport,
                                            contract_index_key,
                                            value, self.transport.guid)
Beispiel #14
0
    def __init__(self, store_file, my_market_ip, my_market_port, seed_uri):

        self.transport = CryptoTransportLayer(my_market_ip, my_market_port,
                                              store_file)
        self.transport.join_network(seed_uri)
        self.market = Market(self.transport)

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, node=self.market))]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #15
0
class MarketApplication(tornado.web.Application):

    def __init__(self, store_file, my_market_ip, my_market_port, seed_uri):
    
        self.transport = CryptoTransportLayer(my_market_ip, my_market_port, store_file)
        self.transport.join_network(seed_uri)
        self.market = Market(self.transport)        
        
        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler, dict(transport=self.transport, node=self.market))
        ]
        
    	# TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #16
0
    def __init__(self):

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)

        self.transport = CryptoTransportLayer(12345)
        self.transport.join_network()
        #self.protocol_handler = ProtocolHandler(self.transport)
        self.market = Market(self.transport)

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, node=self.market))]

        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #17
0
    def __init__(self, service):

        settings = dict(debug=True)
        settings.update(options.as_dict())
        client = obelisk.ObeliskOfLightClient(service)
        self.obelisk_handler = obelisk_handler.ObeliskHandler(client)
        self.brc_handler = broadcast.BroadcastHandler()
        self.p2p = CryptoTransportLayer(config.get('p2p-port', 8889), config.get('external-ip', '127.0.0.1'))
        self.p2p.join_network(config.get('seeds', []))
        self.json_chan_handler = jsonchan.JsonChanHandler(self.p2p)
        self.ticker_handler = ticker.TickerHandler()

        handlers = [
            # /block/<block hash>
            (r"/block/([^/]*)(?:/)?", rest_handlers.BlockHeaderHandler),

            # /block/<block hash>/transactions
            (r"/block/([^/]*)/transactions(?:/)?",
                rest_handlers.BlockTransactionsHandler),

            # /tx/
            (r"/tx(?:/)?", rest_handlers.TransactionPoolHandler),

            # /tx/<txid>
            (r"/tx/([^/]*)(?:/)?", rest_handlers.TransactionHandler),

            # /address/<address>
            (r"/address/([^/]*)(?:/)?", rest_handlers.AddressHistoryHandler),

            # /height
            (r"/height(?:/)?", rest_handlers.HeightHandler),

            # /height
            (r"/status(?:/)?", status.StatusHandler, {"app": self}),

            # /
            (r"/", QuerySocketHandler)
        ]

        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #18
0
class MarketApplication(tornado.web.Application):
    def __init__(self, market_ip, market_port, seed_uri, market_id):

        self.transport = CryptoTransportLayer(market_ip, market_port,
                                              market_id)
        self.transport.join_network(seed_uri)

        self.market = Market(self.transport)

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, market=self.market))]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.dht._transport
Beispiel #19
0
class GatewayApplication(tornado.web.Application):

    def __init__(self, service):

        settings = dict(debug=True)
        settings.update(options.as_dict())
        client = obelisk.ObeliskOfLightClient(service)
        self.obelisk_handler = obelisk_handler.ObeliskHandler(client)
        self.brc_handler = broadcast.BroadcastHandler()
        self.p2p = CryptoTransportLayer(config.get('p2p-port', 8889), config.get('external-ip', '127.0.0.1'))
        self.p2p.join_network(config.get('seeds', []))
        self.json_chan_handler = jsonchan.JsonChanHandler(self.p2p)
        self.ticker_handler = ticker.TickerHandler()

        handlers = [
            # /block/<block hash>
            (r"/block/([^/]*)(?:/)?", rest_handlers.BlockHeaderHandler),

            # /block/<block hash>/transactions
            (r"/block/([^/]*)/transactions(?:/)?",
                rest_handlers.BlockTransactionsHandler),

            # /tx/
            (r"/tx(?:/)?", rest_handlers.TransactionPoolHandler),

            # /tx/<txid>
            (r"/tx/([^/]*)(?:/)?", rest_handlers.TransactionHandler),

            # /address/<address>
            (r"/address/([^/]*)(?:/)?", rest_handlers.AddressHistoryHandler),

            # /height
            (r"/height(?:/)?", rest_handlers.HeightHandler),

            # /
            (r"/", QuerySocketHandler)
        ]

        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #20
0
    def update_listings_index(self):

        # Store to marketplace listing index
        contract_index_key = hashlib.sha1('contracts-%s' %
                                          self._transport._guid).hexdigest()
        hashvalue = hashlib.new('ripemd160')
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self._db.selectEntries(
            "contracts", "market_id = '%s'" % self._transport._market_id)
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id['key'])

        self._log.debug('My Contracts: %s' % my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({
            'guid': self._transport._guid,
            'contracts': my_contracts
        })
        signature = CryptoTransportLayer.makeCryptor(
            self._transport.settings['secret']).sign(data_string).encode('hex')

        value = {
            'signature': signature,
            'data': {
                'guid': self._transport._guid,
                'contracts': my_contracts
            }
        }

        # Pass off to thread to keep GUI snappy
        self._transport._dht.iterativeStore(self._transport,
                                            contract_index_key, value,
                                            self._transport._guid)
Beispiel #21
0
    def __init__(self, market_ip, market_port, market_id=1,
                 bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                 seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip,
                                              market_port,
                                              market_id,
                                              db,
                                              bm_user,
                                              bm_pass,
                                              bm_port,
                                              seed_mode,
                                              dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport.dht._refreshNode()
            self.market.republish_contracts()

        peers = seed_peers if seed_mode == 0 else []
        self.transport.join_network(peers)

        Thread(target=reactor.run, args=(False,)).start()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", OpenBazaarStaticHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market_application=self, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #22
0
class MarketApplication(tornado.web.Application):
    def __init__(self, market_ip, market_port, market_id=1,
                 bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                 seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip,
                                              market_port,
                                              market_id,
                                              db,
                                              bm_user,
                                              bm_pass,
                                              bm_port,
                                              seed_mode,
                                              dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport.dht._refreshNode()
            self.market.republish_contracts()

        peers = seed_peers if seed_mode == 0 else []
        self.transport.join_network(peers)

        Thread(target=reactor.run, args=(False,)).start()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", OpenBazaarStaticHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market_application=self, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.transport

    def setup_upnp_port_mappings(self, http_port, p2p_port):
        upnp.PortMapper.DEBUG = False
        print "Setting up UPnP Port Map Entry..."
        # TODO: Add some setting whether or not to use UPnP
        # if Settings.get(Settings.USE_UPNP_PORT_MAPPINGS):
        self.upnp_mapper = upnp.PortMapper()
        # TODO: Add some setting whether or not to clean all previous port
        # mappings left behind by us
        # if Settings.get(Settings.CLEAN_UPNP_PORT_MAPPINGS_ON_START):
        #    upnp_mapper.cleanMyMappings()

        # for now let's always clean mappings every time.
        self.upnp_mapper.clean_my_mappings()
        # result_http_port_mapping = self.upnp_mapper.add_port_mapping(http_port,
        #                                                             http_port)
        # print ("UPnP HTTP Port Map configuration done (%s -> %s) => %s" %
        #        (str(http_port), str(http_port), str(result_http_port_mapping)))

        result_tcp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
                                                                   p2p_port)
        print ("UPnP TCP P2P Port Map configuration done (%s -> %s) => %s" %
               (str(p2p_port), str(p2p_port), str(result_tcp_p2p_mapping)))

        result_udp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
                                                                   p2p_port,
                                                                   'UDP')
        print ("UPnP UDP P2P Port Map configuration done (%s -> %s) => %s" %
               (str(p2p_port), str(p2p_port), str(result_udp_p2p_mapping)))

        # return result_http_port_mapping and \
        return result_tcp_p2p_mapping and \
               result_udp_p2p_mapping

    def cleanup_upnp_port_mapping(self):
        try:
            if self.upnp_mapper is not None:
                print "Cleaning UPnP Port Mapping -> ", \
                    self.upnp_mapper.clean_my_mappings()
        except AttributeError:
            print "[openbazaar] MarketApplication.clean_upnp_port_mapping() failed!"
            pass

    def shutdown(self, x=None, y=None):
        print "MarketApplication.shutdown!"
        locallogger = logging.getLogger('[%s] %s' % (self.market.market_id, 'root'))
        locallogger.info("Received TERMINATE, exiting...")

        # application.get_transport().broadcast_goodbye()
        self.cleanup_upnp_port_mapping()
        tornado.ioloop.IOLoop.instance().stop()

        self.transport.shutdown()
        os._exit(0)
Beispiel #23
0
class MarketApplication(tornado.web.Application):
    def __init__(self, market_ip, market_port, market_id=1,
                 bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
                 seed_mode=0, dev_mode=False, db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip,
                                              market_port,
                                              market_id,
                                              db,
                                              bm_user,
                                              bm_pass,
                                              bm_port,
                                              seed_mode,
                                              dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport._dht._refreshNode()
            self.market.republish_contracts()

        peers = seed_peers if seed_mode == 0 else []
        self.transport.join_network(peers)

        Thread(target=reactor.run, args=(False,)).start()

        handlers = [
            (r"/", MainHandler),
            (r"/main", MainHandler),
            (r"/html/(.*)", tornado.web.StaticFileHandler, {'path': './html'}),
            (r"/ws", WebSocketHandler,
                dict(transport=self.transport, market=self.market, db=db))
        ]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.transport

    def setup_upnp_port_mappings(self, http_port, p2p_port):
        upnp.PortMapper.DEBUG = False
        print "Setting up UPnP Port Map Entry..."
        # TODO: Add some setting whether or not to use UPnP
        # if Settings.get(Settings.USE_UPNP_PORT_MAPPINGS):
        self.upnp_mapper = upnp.PortMapper()
        # TODO: Add some setting whether or not to clean all previous port
        # mappings left behind by us
        # if Settings.get(Settings.CLEAN_UPNP_PORT_MAPPINGS_ON_START):
        #    upnp_mapper.cleanMyMappings()

        # for now let's always clean mappings every time.
        self.upnp_mapper.clean_my_mappings()
        # result_http_port_mapping = self.upnp_mapper.add_port_mapping(http_port,
        #                                                             http_port)
        # print ("UPnP HTTP Port Map configuration done (%s -> %s) => %s" %
        #        (str(http_port), str(http_port), str(result_http_port_mapping)))

        result_tcp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
                                                                   p2p_port)
        print ("UPnP TCP P2P Port Map configuration done (%s -> %s) => %s" %
               (str(p2p_port), str(p2p_port), str(result_tcp_p2p_mapping)))

        result_udp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
                                                                   p2p_port,
                                                                   'UDP')
        print ("UPnP UDP P2P Port Map configuration done (%s -> %s) => %s" %
               (str(p2p_port), str(p2p_port), str(result_udp_p2p_mapping)))

        # return result_http_port_mapping and \
        return result_tcp_p2p_mapping and \
               result_udp_p2p_mapping

    def cleanup_upnp_port_mapping(self):
        if self.upnp_mapper is not None:
            print "Cleaning UPnP Port Mapping -> ", \
                self.upnp_mapper.clean_my_mappings()
Beispiel #24
0
class MarketApplication(tornado.web.Application):
    def __init__(self,
                 market_ip,
                 market_port,
                 market_id=1,
                 bm_user=None,
                 bm_pass=None,
                 bm_port=None,
                 seed_peers=[],
                 seed_mode=0,
                 dev_mode=False,
                 db_path='db/ob.db'):

        db = Obdb(db_path)

        self.transport = CryptoTransportLayer(market_ip, market_port,
                                              market_id, db, bm_user, bm_pass,
                                              bm_port, seed_mode, dev_mode)

        self.market = Market(self.transport, db)

        def post_joined():
            self.transport._dht._refreshNode()
            self.market.republish_contracts()

        peers = seed_peers if seed_mode == 0 else []
        self.transport.join_network(peers)

        Thread(target=reactor.run, args=(False, )).start()

        handlers = [(r"/", MainHandler), (r"/main", MainHandler),
                    (r"/html/(.*)", tornado.web.StaticFileHandler, {
                        'path': './html'
                    }),
                    (r"/ws", WebSocketHandler,
                     dict(transport=self.transport, market=self.market,
                          db=db))]

        # TODO: Move debug settings to configuration location
        settings = dict(debug=True)
        tornado.web.Application.__init__(self, handlers, **settings)

    def get_transport(self):
        return self.transport

    def setup_upnp_port_mappings(self, http_port, p2p_port):
        upnp.PortMapper.DEBUG = False
        print "Setting up UPnP Port Map Entry..."
        # TODO: Add some setting whether or not to use UPnP
        # if Settings.get(Settings.USE_UPNP_PORT_MAPPINGS):
        self.upnp_mapper = upnp.PortMapper()
        # TODO: Add some setting whether or not to clean all previous port
        # mappings left behind by us
        # if Settings.get(Settings.CLEAN_UPNP_PORT_MAPPINGS_ON_START):
        #    upnp_mapper.cleanMyMappings()

        # for now let's always clean mappings every time.
        self.upnp_mapper.clean_my_mappings()
        result_http_port_mapping = self.upnp_mapper.add_port_mapping(
            http_port, http_port)
        print("UPnP HTTP Port Map configuration done (%s -> %s) => %s" %
              (str(http_port), str(http_port), str(result_http_port_mapping)))

        result_tcp_p2p_mapping = self.upnp_mapper.add_port_mapping(
            p2p_port, p2p_port)
        print("UPnP TCP P2P Port Map configuration done (%s -> %s) => %s" %
              (str(p2p_port), str(p2p_port), str(result_tcp_p2p_mapping)))

        result_udp_p2p_mapping = self.upnp_mapper.add_port_mapping(
            p2p_port, p2p_port, 'UDP')
        print("UPnP UDP P2P Port Map configuration done (%s -> %s) => %s" %
              (str(p2p_port), str(p2p_port), str(result_udp_p2p_mapping)))

        return result_http_port_mapping and \
            result_tcp_p2p_mapping and \
            result_udp_p2p_mapping

    def cleanup_upnp_port_mapping(self):
        if self.upnp_mapper is not None:
            print "Cleaning UPnP Port Mapping -> ", \
                self.upnp_mapper.clean_my_mappings()