def bootstrap(self, fail=None, peers=[]): ''' Bootstraps the peer into the (P2P) network. It calls the specific method 'doBootstrap' to handle overlay specific steps. ''' node = None try: node = peers.pop(0) except IndexError: print ' *\033[91m Bootstrapping failed:\033[0m cannot reach any introducer node.' return if fail is None: print '-+- Bootstrapping into the network -+-' else: print >> stderr, ' * Bootstrapping with this peer has failed' print ' | trying with %s, port %s, kind %s and protocol %s' % ( node['address'], node['port'], node['kind'], node['protocol'] ) try: wind = WindManager.findWind( kind=node['kind'], protocol=node['protocol']) except NoSuchAWindError: return self.bootstrap(peers=peers) try: d = wind.factory.connect(node['address'], node['port']) d.addCallback(self.doBootstrap, peers=peers) d.addErrback(self.bootstrap, peers=peers) except AttributeError as e: print ' * Bootstrapping with %s (%s:%s) protocol %s has failed' % ( node['address'], node['port'], node['kind'], node['protocol'] ) print ' Can\'t find a suitable wind for this bootstrap node.' return
def sayHello(self, peer): w = None for c in peer.getConnections(): try: w = WindManager.findWind(c[2], c[3]) except NoSuchAWindError: pass else: break else: print >> stderr, ( " * Couldn't find a wind for contacting %s" % peer.getName()) raise NoSuchAWindError, 'No wind for contacting ' + peer.getName() return w.factory.connect( c[0], c[1] # Address / Port ).addCallback( peer.setTransport ).addCallback( self.sendHello)
).addCallback( lambda m: True ).addErrback( self.introRecvdErrback, message=message) else: node = message.getElement('node') peer = CyclonPeer(node.getAttribute('name')) peer.addConnectionsFromXML(node.childNodes) winds = [ ] for c in peer.getConnections(): try: w = WindManager.findWind(c[2], c[3]) except NoSuchAWindError: continue winds.append((w,c)) if len(Cyclon.peerList) > 0: introduced = Cyclon.peerList.getRandomPeer() else: introduced = Cyclon.myself self.introductoryConnection(None, peer, introduced, winds) def introreplyReceived(self, (transport, message)): try: node = message.getElement('node')