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


Python Host.bootstrap方法代码示例

本文整理汇总了Python中host.Host.bootstrap方法的典型用法代码示例。如果您正苦于以下问题:Python Host.bootstrap方法的具体用法?Python Host.bootstrap怎么用?Python Host.bootstrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在host.Host的用法示例。


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

示例1: __init__

# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import bootstrap [as 别名]
 def __init__(self, firstHost = None, port = None, name = "temp", ip = None, testmode = False):
     
     self.name = name # set peer name
     self.inSocket = None # Socket für eingehende Verbindungen
     self.hosts = {} # Dict. der bekannten Hosts
     self.knownPeers = {} # Dict (ip:port) : name
     self.msgParts = {}
     
     # set own ip if you already know it
     if ip != None:
         self.ip = ip
     else:
         self.ip = "null"
     
     # open socket
     self.inSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     if port == None:
         # bind on random port
         self.inSocket.bind(('', 0))
     else:
         # bind on given port
         self.inSocket.bind(('', int(port)))
         
     self.port = int(self.inSocket.getsockname()[1]) # port where peer listens on
     logging.info("Listening on port " + str(self.port))
         
     self.history = message.History(const.HISTORY_SAVEDMSGSLIMIT, const.HISTORY_SAVEDHASHESLIMIT)
     
     self.gui = gui.gui(self)
     
     # lock for hostlist (not needed atm)
     # self.hostlock = threading.RLock()
     
     # start receiveLoop
     self.rThread = threading.Thread(target=self.startRecvLoop)
     self.rThread.daemon = True
     self.rThread.start()
     
     # start sendLoop
     if testmode == True:
         #if testmode is true, sendLoop will drop random parts of msgs
         self.sThread = threading.Thread(target=self.sendLoop, args=(True,))
         self.sThread.daemon = True
         self.sThread.start()
     else:
         self.sThread = threading.Thread(target=self.sendLoop, args=(False,))
         self.sThread.daemon = True
         self.sThread.start()
         
     
     # start maintenance Loop
     self.counter = 0
     self.mThread = threading.Thread(target=self.maintenanceLoop)
     self.mThread.daemon = True
     self.mThread.start()
     
     # send HELO to first host if you know one
     if firstHost != None:
         self.key = None
         (hostIP, hostPort) = firstHost
         h = Host(self, hostIP, hostPort)
         h.bootstrap = True
         
         # wait until you're connected to the network
         while self.key == None:
             time.sleep(0.5)
             
         #Initial Request for some more hosts from firstHost
         key = h.constructKey(hostIP, hostPort)
         logging.debug("Initial Request for some peers from " + key)
         self.requestHosts(key, const.MIN_PEERLIMIT) # and get some more hosts
         
         #Initial Request for History
         logging.debug("Initial Request for History from " + key)
         self.getHistory(key, initial=True)
     else:
         self.key = Host.constructKey(self.ip, self.port)
         logging.info("You created a new Hachat-network. Your key is " + self.key)
     
     if testmode == True:
         self.generateMsgParts(10, 3000) #generates Randome Text-Msgs
     
     #start gui
     self.gui.run()                
开发者ID:t2d,项目名称:hachat,代码行数:86,代码来源:peer.py


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