本文整理汇总了Python中kademlia.network.Server.loadState方法的典型用法代码示例。如果您正苦于以下问题:Python Server.loadState方法的具体用法?Python Server.loadState怎么用?Python Server.loadState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kademlia.network.Server
的用法示例。
在下文中一共展示了Server.loadState方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
def __init__(self, config, bootstrapNeighbors):
if os.path.isfile(config['dht.state.cache']):
self.kserver = Server.loadState(config['dht.state.cache'])
else:
self.kserver = Server()
self.kserver.bootstrap(bootstrapNeighbors)
self.kserver.saveStateRegularly(config['dht.state.cache'], 60)
示例2: connect
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
def connect(self, port):
if(self._app_deployer):
from twisted.application import service, internet
from twisted.python.log import ILogObserver
from twisted.internet import reactor, task
import sys, os
sys.path.append(os.path.dirname(__file__))
from kademlia.network import Server
from kademlia import log
application = service.Application("kademlia")
application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)
if os.path.isfile('cache.pickle'):
kserver = Server.loadState('cache.pickle')
else:
kserver = Server()
kserver.bootstrap([("127.0.0.1", port)])
kserver.saveStateRegularly('cache.pickle', 10)
server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)
else:
self._node.listen(port)
self._node.bootstrap([("127.0.0.1",port)]).addCallback(self.bootStrapDone)
示例3: FileServer
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import tornado.platform.twisted
tornado.platform.twisted.install()
import tornado.ioloop
import tornado.web
import hashlib
from os.path import join, getsize, exists
import mutagen
import pickle
import time
from twisted.internet import reactor
from kademlia.network import Server
if os.path.isfile('self.cache.pickle'):
kserver = Server.loadState('self.cache.pickle')
else:
kserver = Server()
kserver.bootstrap([("185.97.32.250", 8468)])
kserver.saveStateRegularly('self.cache.pickle', 10)
kserver.listen(8468)
class FileServer(tornado.web.RequestHandler):
def initialize(self, cache):
self.cache=cache
def get(self, arg):
filename = self.cache[arg]
with open(filename,"rb") as fp:
self.set_header("Content-Type", "audio/mpeg")
self.set_header('content-length',os.stat(fp.fileno()).st_size)
示例4: setDone
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
print "Key result:", result
reactor.stop()
def setDone(result, server):
server.get("110").addCallback(done)
def bootstrapDone(found, server):
print "*** Putting a value"
server.set("110", fileread()).addCallback(setDone, server)
#resourceDiscovery()
if os.path.isfile('cache.pickle'):
print "*** @ if block"
#kserver = Server()
kserver = Server.loadState('cache.pickle')
kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
else:
print "*** @ else block"
kserver = Server()
kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
kserver.saveStateRegularly('cache.pickle', 10)
server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)
示例5: Server
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
from twisted.application import service, internet
from twisted.python.log import ILogObserver
from twisted.internet import reactor, task
import sys, os
#sys.path.append(os.path.dirname(__file__))
from kademlia.network import Server
from kademlia import log
application = service.Application("tau")
application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)
kad_cache = 'cache.pickle'
if os.path.isfile(kad_cache):
kserver = Server.loadState(kad_cache)
else:
kserver = Server()
kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly(kad_cache, 10)
server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)
reactor.run()
示例6: Server
# 需要导入模块: from kademlia.network import Server [as 别名]
# 或者: from kademlia.network.Server import loadState [as 别名]
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from twisted.internet import reactor
from kademlia.network import Server
if os.path.isfile("cache.pickle"):
kserver = Server.loadState("cache.pickle")
else:
kserver = Server()
kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly("cache.pickle", 10)
kserver.listen(8468)
reactor.run()