kademlia/server.tac

22 lines
683 B
Python
Raw Normal View History

2014-01-04 20:27:45 +01:00
from twisted.application import service, internet
2014-01-14 01:49:16 +01:00
from twisted.python.log import ILogObserver
2014-01-14 03:44:44 +01:00
from twisted.internet import reactor, task
2014-01-14 01:49:16 +01:00
2014-01-15 00:21:40 +01:00
import sys, os
2014-01-04 20:27:45 +01:00
sys.path.append(os.path.dirname(__file__))
from kademlia.network import Server
2014-01-14 01:49:16 +01:00
from kademlia import log
2014-01-04 20:27:45 +01:00
2014-01-15 00:21:40 +01:00
application = service.Application("kademlia")
application.setComponent(ILogObserver, log.FileLogObserver(sys.stdout, log.INFO).emit)
2014-01-14 03:44:44 +01:00
if os.path.isfile('cache.pickle'):
kserver = Server.loadState('cache.pickle')
2014-01-14 03:44:44 +01:00
else:
kserver = Server()
2014-01-15 00:21:40 +01:00
kserver.bootstrap([("1.2.3.4", 8468)])
kserver.saveStateRegularly('cache.pickle', 10)
2014-01-14 03:44:44 +01:00
server = internet.UDPServer(8468, kserver.protocol)
2014-01-04 20:27:45 +01:00
server.setServiceParent(application)