本文整理汇总了Python中crypto2crypto.CryptoTransportLayer.join_network方法的典型用法代码示例。如果您正苦于以下问题:Python CryptoTransportLayer.join_network方法的具体用法?Python CryptoTransportLayer.join_network怎么用?Python CryptoTransportLayer.join_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crypto2crypto.CryptoTransportLayer
的用法示例。
在下文中一共展示了CryptoTransportLayer.join_network方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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
示例2: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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
示例3: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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
示例4: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
示例5: GatewayApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
示例6: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
示例7: GatewayApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
示例8: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
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)
def get_transport(self):
return self.transport
示例9: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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)
示例10: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import join_network [as 别名]
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()