예제 #1
0
def publish(name, desc, path, port):
    global server, localip
    if not server:
        ip = getip()
        if ip.startswith('127.'):
            # if we have no internet connection, this can happen.
            return
        localip = socket.inet_aton(ip)
        server = Zeroconf.Zeroconf(ip)

    hostname = socket.gethostname().split('.')[0]
    host = hostname + ".local"
    name = "%s-%s" % (hostname, name)

    # advertise to browsers
    svc = Zeroconf.ServiceInfo('_http._tcp.local.',
                               name + '._http._tcp.local.',
                               server = host,
                               port = port,
                               properties = {'description': desc,
                                             'path': "/" + path},
                               address = localip, weight = 0, priority = 0)
    server.registerService(svc)

    # advertise to Mercurial clients
    svc = Zeroconf.ServiceInfo('_hg._tcp.local.',
                               name + '._hg._tcp.local.',
                               server = host,
                               port = port,
                               properties = {'description': desc,
                                             'path': "/" + path},
                               address = localip, weight = 0, priority = 0)
    server.registerService(svc)
예제 #2
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
예제 #3
0
 def init_autodiscovery(self):
     """
     Inicializa el descubrimiento automático de los servidores TagFS.
     """
     self._zeroconf = Zeroconf.Zeroconf(self._daemon.hostname)
     zeroconf_service_name = '{n}.{t}'.format(n=self._pyro_uri, t=ZEROCONF_SERVICE_TYPE)
     self._zeroconf_service = Zeroconf.ServiceInfo(ZEROCONF_SERVICE_TYPE, zeroconf_service_name, 
                                                   socket.inet_aton(self._daemon.hostname),
                                                   self._daemon.port, 0, 0, {})
     self._zeroconf.registerService(self._zeroconf_service)
예제 #4
0
    def run(self):	
	
        self.localhostname = split(socket.gethostname(),'.')[0]+'.local.'
	try:
	        self.localip = socket.gethostbyname(self.localhostname)
	        self.zeroconf = Zeroconf.Zeroconf(self.localip)
	except:
		return
	self.active = True

        toRegister = self.services()
        for i in toRegister:
            service = Zeroconf.ServiceInfo(
	    i["type"]+".local.",
            i["name"]+"."+i["type"]+".local.",
	    socket.inet_aton(self.localip),
	    i["port"],
	    0,
	    0,
	    i["properties"],
	    self.localhostname)
	    self.zeroconf.registerService(service)
예제 #5
0
	def addService(self, zeroconf, type, name):
		"""Listener method called when new zeroconf service is detected."""
		if self.__closed:
			return #do NOT add service if closed
		self.allHosts.append(name)
		ServiceResolver(zeroconf, Zeroconf.ServiceInfo(type, name), self, 3000)