当前位置: 首页>>代码示例>>Python>>正文


Python crypto2crypto.CryptoTransportLayer类代码示例

本文整理汇总了Python中crypto2crypto.CryptoTransportLayer的典型用法代码示例。如果您正苦于以下问题:Python CryptoTransportLayer类的具体用法?Python CryptoTransportLayer怎么用?Python CryptoTransportLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CryptoTransportLayer类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MarketApplication

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
开发者ID:christopherdebeer,项目名称:OpenBazaar,代码行数:30,代码来源:tornadoloop.py

示例2: MarketApplication

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
开发者ID:kujenga,项目名称:OpenBazaar,代码行数:59,代码来源:tornadoloop.py

示例3: MarketApplication

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
开发者ID:incorpusyehtee,项目名称:OpenBazaar,代码行数:50,代码来源:tornadoloop.py

示例4: MarketApplication

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)
开发者ID:AntonioReyes,项目名称:darkmarket,代码行数:15,代码来源:tornadoloop.py

示例5: GatewayApplication

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)
开发者ID:andyfreer,项目名称:gateway,代码行数:48,代码来源:gateway.py

示例6: update_listings_index

    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)
开发者ID:Macarse,项目名称:OpenBazaar,代码行数:32,代码来源:market.py

示例7: __init__

    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)
开发者ID:xjybentusi,项目名称:OpenBazaar,代码行数:28,代码来源:tornadoloop.py

示例8: __init__

    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)
开发者ID:kawalgrover,项目名称:OpenBazaar,代码行数:32,代码来源:tornadoloop.py

示例9: __init__

    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)
开发者ID:kujenga,项目名称:OpenBazaar,代码行数:29,代码来源:tornadoloop.py

示例10: MarketApplication

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)
开发者ID:dankozlowski,项目名称:OpenBazaar,代码行数:18,代码来源:tornadoloop.py

示例11: GatewayApplication

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)
开发者ID:CodersBrothers,项目名称:gateway,代码行数:39,代码来源:gateway.py

示例12: __init__

    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)
开发者ID:alejochang,项目名称:OpenBazaar,代码行数:38,代码来源:tornadoloop.py

示例13: MarketApplication

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)
开发者ID:alejochang,项目名称:OpenBazaar,代码行数:96,代码来源:tornadoloop.py

示例14: MarketApplication

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()
开发者ID:anduck,项目名称:OpenBazaar,代码行数:80,代码来源:tornadoloop.py


注:本文中的crypto2crypto.CryptoTransportLayer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。