def start(self, iface='', network=None, bootstrap=None, cb=None, name=None):
        if bootstrap is None:
            bootstrap = []
        name_dir = os.path.join(self.cert_conf["CA_default"]["runtimes_dir"], name)
        filename = os.listdir(os.path.join(name_dir, "mine"))
        st_cert = open(os.path.join(name_dir, "mine", filename[0]), 'rt').read()
        cert_part = st_cert.split(certificate.BEGIN_LINE)
        certstr = "{}{}".format(certificate.BEGIN_LINE, cert_part[1])

        try:
            cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                                  certstr)
        except:
            raise
        # Derive DHT node id
        key = cert.digest("sha256")
        newkey = key.replace(":", "")
        bytekey = newkey.decode("hex")

        if network is None:
            network = _conf.get_in_order("dht_network_filter", "ALL")

        self.dht_server = ServerApp(AppendServer, bytekey[-20:])
        ip, port = self.dht_server.start(iface=iface)

        dlist = []
        dlist.append(self.dht_server.bootstrap(bootstrap))

        self._ssdps = SSDPServiceDiscovery(iface, cert=certstr)
        dlist += self._ssdps.start()

        logger("Register service %s %s:%s" % (network, ip, port))
        self._ssdps.register_service(network, ip, port)

        logger("Set client filter %s" % (network))
        self._ssdps.set_client_filter(network)

        start_cb = defer.Deferred()

        def bootstrap_proxy(addrs):
            def started(args):
                logger("DHT Started %s" % (args))
                if not self._started:
                    reactor.callLater(.2, start_cb.callback, True)
                if cb:
                    reactor.callLater(.2, cb, True)
                self._started = True

            def failed(args):
                logger((args) % "DHT failed to bootstrap %s")
                #reactor.callLater(.5, bootstrap_proxy, addrs)

            logger("Trying to bootstrap with %s" % (repr(addrs)))
            d = self.dht_server.bootstrap(addrs)
            d.addCallback(started)
            d.addErrback(failed)

        def start_msearch(args):
            logger("** msearch %s args: %s" % (self, repr(args)))
            reactor.callLater(0,
                                self._ssdps.start_search,
                                bootstrap_proxy,
                                stop=False)

        # Wait until servers all listen
        dl = defer.DeferredList(dlist)
        dl.addBoth(start_msearch)
        # Only for logging
        self.dht_server.kserver.protocol.sourceNode.port = port
        self.dht_server.kserver.protocol.sourceNode.ip = "0.0.0.0"
        #FIXME handle inside ServerApp
        self.dht_server.kserver.name = name
        self.dht_server.kserver.protocol.name = name
        self.dht_server.kserver.protocol.storeOwnCert(certstr)
        self.dht_server.kserver.protocol.setPrivateKey()

        return start_cb
dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/runtime/south/plugins/storage/twistedimpl/securedht/dht_server.py/AutoDHTServer.start/swapped operands of `%`