Beispiel #1
0
 def __init__(self, config, bootstrapNeighbors):
     if os.path.isfile(config['dht.state.cache']):
         self.kserver = Server.loadState(config['dht.state.cache'])
     else:
         self.kserver = Server()
         self.kserver.bootstrap(bootstrapNeighbors)
         self.kserver.saveStateRegularly(config['dht.state.cache'], 60)
Beispiel #2
0
    def connect(self, port):
        
        if(self._app_deployer):
            from twisted.application import service, internet
            from twisted.python.log import ILogObserver
            from twisted.internet import reactor, task

            import sys, os
            sys.path.append(os.path.dirname(__file__))
            from kademlia.network import Server
            from kademlia import log

            application = service.Application("kademlia")
            application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)

            if os.path.isfile('cache.pickle'):
                kserver = Server.loadState('cache.pickle')
            else:
                kserver = Server()
                kserver.bootstrap([("127.0.0.1", port)])
                kserver.saveStateRegularly('cache.pickle', 10)
                
            server = internet.UDPServer(8468, kserver.protocol)
            server.setServiceParent(application)    
        else:
            self._node.listen(port)
            self._node.bootstrap([("127.0.0.1",port)]).addCallback(self.bootStrapDone)
Beispiel #3
0
	def __init__(self, *args):
		self.ip = args[0]
		self.port = args[1]

		application = service.Application("kademlia")
		application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)

		if os.path.isfile('cache.pickle'):
		    kserver = Server.loadState('cache.pickle')
		else:
		    kserver = Server()
		    kserver.bootstrap([(self.ip, self.port)])
		kserver.saveStateRegularly('cache.pickle', 10)

		server = internet.UDPServer(self.port, kserver.protocol)
		server.setServiceParent(application)
		
		self.log = logging.getLogger(resource_filename(__name__, __file__))
Beispiel #4
0
                    '--log',
                    dest='log',
                    type=str,
                    action='store',
                    default=False,
                    help='Specify a log file to output to. Default is stdout.')
args = parser.parse_args()

# Logging and fun stuff like that
if args.log:
    # NOTE: This works, however I am unsure if the logging function will close the file descriptor when the server finishes.
    l = open(args.log, "a")
    log.startLogging(l)
else:
    log.startLogging(sys.stdout)

print("Setting up listening server")
server = Server()
server.listen(args.port)

# This is a backup
if os.path.isfile(backup):
    server.loadState(backup)

# Saves to a backup every 5 minutes
#TODO: This should be changed to create the directory and file instead
if os.path.exists(backup):
    server.saveStateRegularly(backup, 300)

reactor.run()
Beispiel #5
0
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import tornado.platform.twisted
tornado.platform.twisted.install()
import tornado.ioloop
import tornado.web
import hashlib
from os.path import join, getsize, exists
import mutagen
import pickle
import time
from twisted.internet import reactor
from kademlia.network import Server

if os.path.isfile('self.cache.pickle'):
    kserver = Server.loadState('self.cache.pickle')
else:
    kserver = Server()
    kserver.bootstrap([("185.97.32.250", 8468)])
kserver.saveStateRegularly('self.cache.pickle', 10)
kserver.listen(8468)

class FileServer(tornado.web.RequestHandler):
    def initialize(self, cache):
        self.cache=cache

    def get(self, arg):
        filename = self.cache[arg]
        with open(filename,"rb") as fp:
            self.set_header("Content-Type", "audio/mpeg")
            self.set_header('content-length',os.stat(fp.fileno()).st_size)
Beispiel #6
0
    print "Key result:", result
    reactor.stop()

def setDone(result, server):
    server.get("110").addCallback(done)

def bootstrapDone(found, server):
    print "*** Putting a value"
    server.set("110", fileread()).addCallback(setDone, server)
 
#resourceDiscovery()

if os.path.isfile('cache.pickle'):
    print "*** @ if block"
    #kserver = Server()
    kserver = Server.loadState('cache.pickle')
    kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
else:
    print "*** @ else block"
    kserver = Server()
    kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
kserver.saveStateRegularly('cache.pickle', 10)

server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)





Beispiel #7
0
def done(result):
    print "Key result:", result
    reactor.stop()


def setDone(result, server):
    server.get("110").addCallback(done)


def bootstrapDone(found, server):
    print "*** Putting a value"
    server.set("110", fileread()).addCallback(setDone, server)


#resourceDiscovery()

if os.path.isfile('cache.pickle'):
    print "*** @ if block"
    #kserver = Server()
    kserver = Server.loadState('cache.pickle')
    kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
else:
    print "*** @ else block"
    kserver = Server()
    kserver.bootstrap([("10.0.0.1", 8468)]).addCallback(bootstrapDone, kserver)
kserver.saveStateRegularly('cache.pickle', 10)

server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)
Beispiel #8
0
from twisted.application import service, internet
from twisted.python.log import ILogObserver
from twisted.internet import reactor, task

import sys, os
#sys.path.append(os.path.dirname(__file__))
from kademlia.network import Server
from kademlia import log

application = service.Application("tau")
application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)

kad_cache = 'cache.pickle'
if os.path.isfile(kad_cache):
    kserver = Server.loadState(kad_cache)
else:
    kserver = Server()
    kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly(kad_cache, 10)

server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)


reactor.run()
Beispiel #9
0
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from twisted.internet import reactor
from kademlia.network import Server

if os.path.isfile("cache.pickle"):
    kserver = Server.loadState("cache.pickle")
else:
    kserver = Server()
    kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly("cache.pickle", 10)
kserver.listen(8468)
reactor.run()
Beispiel #10
0
from twisted.application import service, internet
from twisted.python.log import ILogObserver
from twisted.internet import reactor, task

import sys, os
#sys.path.append(os.path.dirname(__file__))
from kademlia.network import Server
from kademlia import log

application = service.Application("tau")
application.setComponent(ILogObserver,
                         log.FileLogObserver(sys.stdout, log.INFO).emit)

kad_cache = 'cache.pickle'
if os.path.isfile(kad_cache):
    kserver = Server.loadState(kad_cache)
else:
    kserver = Server()
    kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly(kad_cache, 10)

server = internet.UDPServer(8468, kserver.protocol)
server.setServiceParent(application)

reactor.run()