Beispiel #1
0
    def announce(self, infohash, peerid):
        discovery_logger.info("announcing: %s", infohash)

        # old
        #service_name = "_BitTorrent-%s._tcp.local." % infohash
        #service_type = service_name

        service_name = "%s._%s" % (peerid, infohash)
        service_type = "_bittorrent._tcp.local."

        browser = Zeroconf.ServiceBrowser(self.server, service_type, self)

        service = Zeroconf.ServiceInfo(
            service_type,
            "%s.%s" % (service_name, service_type),
            address=None,  # to be filled in later
            port=self.port,
            weight=0,
            priority=0,
            properties={})
        service.browser = browser
        service.registered = False
        self.services.append(service)

        df = get_deferred_host_ip()
        df.addCallback(self._announce2, service)
        return service
    def announce(self, infohash, peerid):
        discovery_logger.info("announcing: %s", infohash)

        # old
        #service_name = "_BitTorrent-%s._tcp.local." % infohash
        #service_type = service_name
        
        service_name = "%s._%s" % (peerid, infohash)
        service_type = "_bittorrent._tcp.local."
        
        browser = Zeroconf.ServiceBrowser(self.server, service_type, self)

        service = Zeroconf.ServiceInfo(service_type,
                                       "%s.%s" % (service_name, service_type),
                                       address = None, # to be filled in later
                                       port = self.port,
                                       weight = 0, priority = 0,
                                       properties = {}
                                      )
        service.browser = browser
        service.registered = False
        self.services.append(service)
        
        df = get_deferred_host_ip()
        df.addCallback(self._announce2, service)
        return service
Beispiel #3
0
    def begin_discovery(self):
        # bind to an available port, and join the multicast group
        df = get_deferred_host_ip()
        yield df
        hostip = df.getResult()

        for p in xrange(self.upnp_addr[1], self.upnp_addr[1] + 50):
            try:
                # Original RawServer cannot do this!
                s = self.rawserver.create_multicastsocket(p, hostip)
                self.transport = s
                self.rawserver.start_listening_multicast(s, self)
                df = s.listening_port.joinGroup(self.upnp_addr[0],
                                                socket.INADDR_ANY)
                yield df
                result = df.getResult()
                # blargh
                if twisted.copyright.version >= '2.4.0':
                    success = None
                    # ACKKKK..K. Prevents "Unhandled error in Deferred"
                    if df._debugInfo is not None:
                        df._debugInfo.failResult = None
                else:
                    success = 1
                if result is success:
                    break
                elif isinstance(result, twisted.python.failure.Failure):
                    # HACK.  If the failure contains a 'No such device' error
                    # then we abort the discovery because this error denotes
                    # that the peer is not connected to the network.
                    if hasattr( result.value, "__getitem__" ) and \
                       result.value[2] == 19:
                        yield 0  # abort discovery.
                else:
                    # I suppose keep trying on different ports, but why would
                    # joinGroup fail?
                    self.transport = None
                    x = s.listening_port.stopListening()
                    if isinstance(x, defer.Deferred):
                        yield x
                        x.getResult()
            except socket.error, e:
                # may look weird, but spin the event loop once on failure
                yield defer.succeed(True)
Beispiel #4
0
 def begin_discovery(self):
     # bind to an available port, and join the multicast group
     df = get_deferred_host_ip()
     yield df
     hostip = df.getResult()
     
     for p in xrange(self.upnp_addr[1], self.upnp_addr[1]+50):
         try:
             # Original RawServer cannot do this!
             s = self.rawserver.create_multicastsocket(p, hostip)
             self.transport = s
             self.rawserver.start_listening_multicast(s, self)
             df = s.listening_port.joinGroup(self.upnp_addr[0],
                                             socket.INADDR_ANY)
             yield df
             result = df.getResult()
             # blargh
             if twisted.copyright.version >= '2.4.0':
                 success = None
                 # ACKKKK..K. Prevents "Unhandled error in Deferred"
                 if df._debugInfo is not None:
                     df._debugInfo.failResult = None
             else:
                 success = 1
             if result is success:
                 break
             elif isinstance(result, twisted.python.failure.Failure):
                 # HACK.  If the failure contains a 'No such device' error
                 # then we abort the discovery because this error denotes
                 # that the peer is not connected to the network.
                 if hasattr( result.value, "__getitem__" ) and \
                    result.value[2] == 19:
                     yield 0   # abort discovery.      
             else:
                 # I suppose keep trying on different ports, but why would
                 # joinGroup fail?
                 self.transport = None
                 x = s.listening_port.stopListening()
                 if isinstance(x, defer.Deferred):
                     yield x
                     x.getResult()
         except socket.error, e:
             # may look weird, but spin the event loop once on failure
             yield defer.succeed(True)