def _init_local(self): from p2p import commands from lib import net_misc from lib import misc from system import tmpfile from system import run_upnpc from raid import eccmap from userid import my_id my_id.init() if settings.enableWebStream(): from logs import weblog weblog.init(settings.getWebStreamPort()) if settings.enableWebTraffic(): from logs import webtraffic webtraffic.init(port=settings.getWebTrafficPort()) misc.init() commands.init() tmpfile.init(settings.getTempDir()) net_misc.init() settings.update_proxy_settings() run_upnpc.init() eccmap.init() if sys.argv.count("--twisted"): from twisted.python import log as twisted_log twisted_log.startLogging(MyTwistedOutputLog(), setStdout=0) # import twisted.python.failure as twisted_failure # twisted_failure.startDebugMode() # twisted_log.defaultObserver.stop() if settings.getDebugLevel() > 10: defer.setDebugging(True)
def _init_local(self): from p2p import commands from lib import net_misc from lib import misc from system import tmpfile from system import run_upnpc from raid import eccmap from userid import my_id from crypt import my_keys my_id.init() if settings.enableWebStream(): from logs import weblog weblog.init(settings.getWebStreamPort()) if settings.enableWebTraffic(): from logs import webtraffic webtraffic.init(port=settings.getWebTrafficPort()) misc.init() commands.init() tmpfile.init(settings.getTempDir()) net_misc.init() settings.update_proxy_settings() run_upnpc.init() eccmap.init() my_keys.init() if sys.argv.count('--twisted'): from twisted.python import log as twisted_log twisted_log.startLogging(MyTwistedOutputLog(), setStdout=0) # import twisted.python.failure as twisted_failure # twisted_failure.startDebugMode() # twisted_log.defaultObserver.stop() if settings.getDebugLevel() > 10: defer.setDebugging(True)
def main(): lg.life_begins() bpio.init() settings.init() misc.init() my_id.init() identitycache.init() from crypt import key key.InitMyKey() (options, args) = parseCommandLine() settings.override('transport.transport-tcp.transport-tcp-port', options.tcpport) settings.override('transport.transport-udp.transport-udp-port', options.udpport) settings.override('network.network-dht-port', options.dhtport) lg.set_debug_level(options.debug) tmpfile.init() if True: import lib.udp lib.udp.listen(options.udpport) import dht.dht_service dht.dht_service.init(options.dhtport) reactor.addSystemEventTrigger('before', 'shutdown', shutdown) # @UndefinedVariable init() start() globals()['num_in'] = 0 def _in(a, b, c, d): lg.out(2, 'INBOX %d : %r' % (globals()['num_in'], a)) globals()['num_in'] += 1 return False callback.insert_inbox_callback(0, _in) if len(args) > 0: globals()['num_out'] = 0 def _s(): p = signed.Packet(commands.Data(), my_id.getLocalID(), my_id.getLocalID(), my_id.getLocalID(), bpio.ReadBinaryFile(args[1]), args[0]) outbox(p, wide=True) lg.out(2, 'OUTBOX %d : %r' % (globals()['num_out'], p)) globals()['num_out'] += 1 old_state_changed = transport('udp').state_changed def new_state_changed(oldstate, newstate, event, *args, **kwargs): old_state_changed(oldstate, newstate, event, *args, **kwargs) if newstate == 'LISTENING': reactor.callLater(1, _s) # @UndefinedVariable transport('udp').state_changed = new_state_changed # t = task.LoopingCall(_s) # reactor.callLater(5, t.start, 60, True) # reactor.callLater(2, t.stop) reactor.run() # @UndefinedVariable settings.shutdown()
def _init_local(self): from p2p import commands from lib import net_misc from lib import misc from system import tmpfile from system import run_upnpc from raid import eccmap from contacts import identitydb from crypt import my_keys from userid import id_url from userid import my_id id_url.init() identitydb.init() my_id.init() if settings.enableWebStream(): try: from logs import weblog weblog.init(settings.getWebStreamPort()) except: lg.exc() if settings.enableWebTraffic(): try: from logs import webtraffic webtraffic.init(port=settings.getWebTrafficPort()) except: lg.exc() misc.init() commands.init() tmpfile.init(settings.getTempDir()) net_misc.init() settings.update_proxy_settings() run_upnpc.init() eccmap.init() my_keys.init() # if sys.argv.count('--twisted'): # from twisted.python import log as twisted_log # twisted_log.startLogging(MyTwistedOutputLog(), setStdout=0) # import twisted.python.failure as twisted_failure # twisted_failure.startDebugMode() # twisted_log.defaultObserver.stop() # if settings.getDebugLevel() > 10: # defer.setDebugging(True) if settings.enableMemoryProfile(): try: from guppy import hpy # @UnresolvedImport hp = hpy() hp.setrelheap() if _Debug: lg.out(_DebugLevel, 'hp.heap():\n'+str(hp.heap())) lg.out(_DebugLevel, 'hp.heap().byrcs:\n'+str(hp.heap().byrcs)) lg.out(_DebugLevel, 'hp.heap().byvia:\n'+str(hp.heap().byvia)) except: if _Debug: lg.out(_DebugLevel, "guppy package is not installed") if _Debug: lg.dbg(_DebugLevel, 'all local modules are initialized, ready to start the engine')
def init_local(UI=""): """ Run `init()` method in most important modules. """ global UImode UImode = UI dhnio.Dprint(2, "dhninit.init_local") import lib.settings as settings import lib.misc as misc misc.init() misc.UpdateSettings() settings_patch() import lib.commands as commands commands.init() if sys.argv.count("--twisted"): class MyTwistedOutputLog: softspace = 0 def read(self): pass def write(self, s): dhnio.Dprint(0, s.strip()) def flush(self): pass def close(self): pass from twisted.python import log as twisted_log twisted_log.startLogging(MyTwistedOutputLog(), setStdout=0) # import twisted.python.failure as twisted_failure # twisted_failure.startDebugMode() # twisted_log.defaultObserver.stop() from twisted.internet import defer defer.setDebugging(True) if settings.enableWebStream(): misc.StartWebStream() # if settings.enableWebTraffic(): # misc.StartWebTraffic() if settings.enableMemoryProfile(): try: from guppy import hpy hp = hpy() hp.setrelheap() dhnio.Dprint(2, "hp.heap():\n" + str(hp.heap())) dhnio.Dprint(2, "hp.heap().byrcs:\n" + str(hp.heap().byrcs)) dhnio.Dprint(2, "hp.heap().byvia:\n" + str(hp.heap().byvia)) import guppy.heapy.RM except: dhnio.Dprint(2, "dhninit.init_local guppy package is not installed") import lib.tmpfile as tmpfile tmpfile.init(settings.getTempDir()) import lib.dhnnet as dhnnet dhnnet.init() settings.update_proxy_settings() import run_upnpc run_upnpc.init() import lib.eccmap as eccmap eccmap.init() import lib.dhncrypto as dhncrypto import lib.identity as identity import webcontrol import lib.automats as automats webcontrol.GetGlobalState = automats.get_global_state automats.SetGlobalStateNotifyFunc(webcontrol.OnGlobalStateChanged) import lib.automat as automat automat.SetStateChangedCallback(webcontrol.OnSingleStateChanged) import dhnupdate dhnupdate.SetNewVersionNotifyFunc(webcontrol.OnGlobalVersionReceived) start_logs_rotate()
def main(): lg.life_begins() bpio.init() settings.init() misc.init() my_id.init() identitycache.init() from crypt import key key.InitMyKey() (options, args) = parseCommandLine() settings.override("transport.transport-tcp.transport-tcp-port", options.tcpport) settings.override("transport.transport-udp.transport-udp-port", options.udpport) settings.override("network.network-dht-port", options.dhtport) lg.set_debug_level(options.debug) tmpfile.init() if True: import lib.udp lib.udp.listen(options.udpport) import dht.dht_service dht.dht_service.init(options.dhtport) reactor.addSystemEventTrigger("before", "shutdown", shutdown) init() start() globals()["num_in"] = 0 def _in(a, b, c, d): lg.out(2, "INBOX %d : %r" % (globals()["num_in"], a)) globals()["num_in"] += 1 return True callback.insert_inbox_callback(-1, _in) if len(args) > 0: globals()["num_out"] = 0 def _s(): p = signed.Packet( commands.Data(), my_id.getLocalID(), my_id.getLocalID(), my_id.getLocalID(), bpio.ReadBinaryFile(args[1]), args[0], ) outbox(p, wide=True) lg.out(2, "OUTBOX %d : %r" % (globals()["num_out"], p)) globals()["num_out"] += 1 old_state_changed = transport("udp").state_changed def new_state_changed(oldstate, newstate, event, arg): old_state_changed(oldstate, newstate, event, arg) if newstate == "LISTENING": reactor.callLater(1, _s) transport("udp").state_changed = new_state_changed # t = task.LoopingCall(_s) # reactor.callLater(5, t.start, 60, True) # reactor.callLater(2, t.stop) reactor.run()