Exemplo n.º 1
0
 def startDht(self):
     '''
     Start Dht node (for discovery)
     '''
     config = dht.DhtConfig()
     config.setBootstrapMode(False)  # Server
     self.dht = dht.DhtRunner()
     self.dhtPort = get_random_port()
     self.dht.run(port=self.dhtPort, ipv4=self.hostAddress, config=config)
Exemplo n.º 2
0
 def start(self):
     '''
     Start the database: connect to the root dht
     '''
     if self.root != None:
         pair = re.split(":",
                         self.root)  # Root host, probably run by control
         bootHost = str(pair[0])
         bootPort = int(pair[1])
     else:
         bootHost = const.discoDhtHost  # Default host,
         bootPort = const.discoDhtPort
     try:
         self.logger.info("launching dht")
         config = dht.DhtConfig()
         config.setBootstrapMode(True)
         self.dht = dht.DhtRunner()
         self.dhtPort = get_random_port()
         self.dht.run(port=self.dhtPort,
                      config=config)  # Run on a random, free port
     except Exception:
         raise DatabaseError("dht.start: %s" % sys.exc_info()[0])
     if bootHost and bootPort:
         try:
             self.dht.bootstrap(str(bootHost), str(bootPort))
         except Exception:
             raise DatabaseError("dht.bootstrap: %s" % sys.exc_info()[0])
     # Create and start peer monitor
     self.peerMon = DhtPeerMon(self.context, self.hostAddress,
                               self.riapsHome, self.dht, self.dhtPort)
     self.peerMon.setup()
     self.peerMon.start()
     time.sleep(0.1)
     self.cleanupRegDb(
     )  # If something in the backup db, discard from the dht
     self.republisherThread.start()  # Start republisher
Exemplo n.º 3
0
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <https://www.gnu.org/licenses/>.

import opendht as dht
import time
import asyncio

config = dht.DhtConfig()
config.setRateLimit(-1, -1)

ping_node = dht.DhtRunner()
ping_node.run(config=config)
#ping_node.enableLogging()
#ping_node.bootstrap("bootstrap.ring.cx", "4222")

pong_node = dht.DhtRunner()
pong_node.run(config=config)
#pong_node.enableLogging()
pong_node.ping(ping_node.getBound())

loc_ping = dht.InfoHash.get("toto99")
loc_pong = dht.InfoHash.get(str(loc_ping))