本文整理汇总了Python中BitTorrent.RawServer_twisted.RawServer.stop_listening_udp方法的典型用法代码示例。如果您正苦于以下问题:Python RawServer.stop_listening_udp方法的具体用法?Python RawServer.stop_listening_udp怎么用?Python RawServer.stop_listening_udp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitTorrent.RawServer_twisted.RawServer
的用法示例。
在下文中一共展示了RawServer.stop_listening_udp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from BitTorrent.RawServer_twisted import RawServer [as 别名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import stop_listening_udp [as 别名]
class KhashmirBase:
_Node = KNodeBase
def __init__(self, host, port, data_dir, rawserver=None, max_ul_rate=1024, checkpoint=True, errfunc=None, rlcount=foo, config={'pause':False, 'max_rate_period':20}):
if rawserver:
self.rawserver = rawserver
else:
self.flag = Event()
d = dict([(x[0],x[1]) for x in common_options + rare_options])
self.rawserver = RawServer(self.flag, d)
self.max_ul_rate = max_ul_rate
self.socket = None
self.config = config
self.setup(host, port, data_dir, rlcount, checkpoint)
def setup(self, host, port, data_dir, rlcount, checkpoint=True):
self.host = host
self.port = port
self.ddir = data_dir
self.store = KStore()
self.pingcache = {}
self.socket = self.rawserver.create_udpsocket(self.port, self.host, False)
self.udp = krpc.hostbroker(self, (self.host, self.port), self.socket, self.rawserver.add_task, self.max_ul_rate, self.config, rlcount)
self._load()
self.rawserver.start_listening_udp(self.socket, self.udp)
self.last = time()
KeyExpirer(self.store, self.rawserver.add_task)
self.refreshTable(force=1)
if checkpoint:
self.rawserver.add_task(30, self.findCloseNodes, lambda a: a, True)
self.rawserver.add_task(60, self.checkpoint, 1)
def Node(self):
n = self._Node(self.udp.connectionForAddr)
n.table = self
return n
def __del__(self):
if self.socket is not None:
self.rawserver.stop_listening_udp(self.socket)
self.socket.close()
def _load(self):
do_load = False
try:
s = open(os.path.join(self.ddir, "routing_table"), 'r').read()
dict = bdecode(s)
except:
id = newID()
else:
id = dict['id']
do_load = True
self.node = self._Node(self.udp.connectionForAddr).init(id, self.host, self.port)
self.table = KTable(self.node)
if do_load:
self._loadRoutingTable(dict['rt'])
def checkpoint(self, auto=0):
d = {}
d['id'] = self.node.id
d['rt'] = self._dumpRoutingTable()
try:
f = open(os.path.join(self.ddir, "routing_table"), 'wb')
f.write(bencode(d))
f.close()
except Exception, e:
#XXX real error here
print ">>> unable to dump routing table!", str(e)
pass
if auto:
self.rawserver.add_task(randrange(int(const.CHECKPOINT_INTERVAL * .9),
int(const.CHECKPOINT_INTERVAL * 1.1)),
self.checkpoint, 1)