def setUp(self): try: bpio.rmdir_recursive('/tmp/.bitdust_tmp') except Exception: pass lg.set_debug_level(30) settings.init(base_dir='/tmp/.bitdust_tmp') try: os.makedirs('/tmp/.bitdust_tmp/metadata') except: pass automat.OpenLogFile('/tmp/.bitdust_tmp/logs/automats.log') self.my_current_key = None fout = open('/tmp/_some_priv_key', 'w') fout.write(_some_priv_key) fout.close() fout = open(settings.LocalIdentityFilename(), 'w') fout.write(_some_identity_xml) fout.close() self.assertTrue(key.LoadMyKey(keyfilename='/tmp/_some_priv_key')) self.assertTrue(my_id.loadLocalIdentity()) my_id.init() try: os.makedirs('/tmp/.bitdust_tmp/logs') except: pass local_fs.WriteTextFile('/tmp/.bitdust_tmp/logs/parallelp.log', '') tmpfile.init(temp_dir_path='/tmp/.bitdust_tmp/temp/') os.makedirs( '/tmp/.bitdust_tmp/backups/[email protected]_8084/1/F1234') try: bpio.rmdir_recursive('/tmp/_some_folder', ignore_errors=True) except: pass os.makedirs('/tmp/_some_folder')
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 main(): lg.set_debug_level(18) lg.life_begins() from crypt import key key.InitMyKey() from contacts import identitycache identitycache.init() from system import tmpfile tmpfile.init() from services import driver required_services = [ 'service_http_connections', 'service_http_transport', 'service_gateway', 'service_network', ] available_services_dir = os.path.join(bpio.getExecutableDir(), 'services') for filename in os.listdir(available_services_dir): if not filename.endswith('.py') and not filename.endswith( '.pyo') and not filename.endswith('.pyc'): continue if not filename.startswith('service_'): continue name = str(filename[:filename.rfind('.')]) if name in required_services: continue driver.disabled_services().add(name) driver.init() driver.enabled_services().clear() driver.enabled_services().add('service_http_transport') driver.enabled_services().add('service_http_connections') driver.enabled_services().add('service_gateway') driver.enabled_services().add('service_network') driver.start() # options = { 'idurl': my_id.getIDURL(),} # options['host'] = nameurl.GetName(my_id.getIDURL())+'@'+'somehost.org' # options['dht_port'] = int(settings.getDHTPort()) # options['udp_port'] = int(settings.getUDPPort()) # udp.listen(int(settings.getUDPPort())) # dht_service.init(settings.getDHTPort()) # dht_service.connect() # udp_node.A('go-online', options) reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown) gateway.init() gateway.start() def _ok_to_send(transport, oldstate, newstate): if newstate != 'LISTENING': return # [filename] [peer idurl] if len(sys.argv) >= 3: pass # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize()) # def _try_reconnect(): # sess = udp_session.get_by_peer_id(sys.argv[2]) # reconnect = False # if not sess: # reconnect = True # print 'sessions', udp_session.sessions_by_peer_id().keys() # print map(lambda s: s.peer_id, udp_session.sessions().values()) # else: # if sess.state != 'CONNECTED': # print 'state: ', sess.state # reconnect = True # if reconnect: # print 'reconnect', sess # udp_session.add_pending_outbox_file( # sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) # udp_node.A('connect', sys.argv[2]) # reactor.callLater(0.5, _try_reconnect) # # def _try_connect(): # if udp_node.A().state == 'LISTEN': # print 'connect' # gateway.stop_packets_timeout_loop() # udp_session.add_pending_outbox_file( # sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) # udp_node.A('connect', sys.argv[2]) # reactor.callLater(5, _try_reconnect) # else: # reactor.callLater(1, _try_connect) # # _try_connect() # # def _send(c): # from transport.udp import udp_stream # for idurl in sys.argv[2:]: # print '_send', udp_stream.streams().keys() # p = signed.Packet(commands.Data(), # my_id.getIDURL(), # my_id.getIDURL(), # 'packet%d' % c, # bpio.ReadBinaryFile(sys.argv[1]), # idurl) # gateway.outbox(p) # if c > 1: # reactor.callLater(0.01, _send, c - 1) # reactor.callLater(0, _send, 15) gateway.add_transport_state_changed_callback(_ok_to_send) reactor.run()
def main(): lg.set_debug_level(18) lg.life_begins() from crypt import key key.InitMyKey() from contacts import identitycache identitycache.init() from system import tmpfile tmpfile.init() from services import driver driver.disabled_services().add('service_tcp_connections') driver.disabled_services().add('service_p2p_hookups') driver.disabled_services().add('service_nodes_lookup') driver.disabled_services().add('service_identity_propagate') driver.disabled_services().add('service_ip_port_responder') driver.init() driver.enabled_services().clear() driver.enabled_services().add('service_udp_transport') driver.enabled_services().add('service_udp_datagrams') driver.enabled_services().add('service_my_ip_port') driver.enabled_services().add('service_gateway') driver.enabled_services().add('service_entangled_dht') driver.enabled_services().add('service_network') driver.start() # options = { 'idurl': my_id.getLocalID(),} # options['host'] = nameurl.GetName(my_id.getLocalID())+'@'+'somehost.org' # options['dht_port'] = int(settings.getDHTPort()) # options['udp_port'] = int(settings.getUDPPort()) # udp.listen(int(settings.getUDPPort())) # dht_service.init(settings.getDHTPort()) # dht_service.connect() # udp_node.A('go-online', options) reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown) gateway.init() gateway.start() def _ok_to_send(transport, oldstate, newstate): if newstate != 'LISTENING': return # [filename] [peer idurl] if len(sys.argv) >= 3: # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize()) def _try_reconnect(): sess = udp_session.get_by_peer_id(sys.argv[2]) reconnect = False if not sess: reconnect = True print('sessions', list(udp_session.sessions_by_peer_id().keys())) print([ s.peer_id for s in list(udp_session.sessions().values()) ]) else: if sess.state != 'CONNECTED': print('state: ', sess.state) reconnect = True if reconnect: print('reconnect', sess) udp_session.add_pending_outbox_file( sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) udp_node.A('connect', sys.argv[2]) reactor.callLater(0.5, _try_reconnect) def _try_connect(): if udp_node.A().state == 'LISTEN': print('connect') gateway.stop_packets_timeout_loop() udp_session.add_pending_outbox_file( sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) udp_node.A('connect', sys.argv[2]) reactor.callLater(5, _try_reconnect) else: reactor.callLater(1, _try_connect) # _try_connect() def _send(c): from transport.udp import udp_stream for idurl in sys.argv[2:]: print('_send', list(udp_stream.streams().keys())) p = signed.Packet(commands.Data(), my_id.getLocalID(), my_id.getLocalID(), 'packet%d' % c, bpio.ReadBinaryFile(sys.argv[1]), idurl) gateway.outbox(p) if c > 1: reactor.callLater(0.01, _send, c - 1) reactor.callLater(0, _send, 15) gateway.add_transport_state_changed_callback(_ok_to_send) reactor.run()
def main(): lg.set_debug_level(18) lg.life_begins() from crypt import key key.InitMyKey() from contacts import identitycache identitycache.init() from system import tmpfile tmpfile.init() from services import driver driver.disabled_services().add('service_tcp_connections') driver.disabled_services().add('service_p2p_hookups') driver.disabled_services().add('service_nodes_lookup') driver.disabled_services().add('service_identity_propagate') driver.disabled_services().add('service_ip_port_responder') driver.init() driver.enabled_services().clear() driver.enabled_services().add('service_udp_transport') driver.enabled_services().add('service_udp_datagrams') driver.enabled_services().add('service_my_ip_port') driver.enabled_services().add('service_gateway') driver.enabled_services().add('service_entangled_dht') driver.enabled_services().add('service_network') driver.start() # options = { 'idurl': my_id.getLocalID(),} # options['host'] = nameurl.GetName(my_id.getLocalID())+'@'+'somehost.org' # options['dht_port'] = int(settings.getDHTPort()) # options['udp_port'] = int(settings.getUDPPort()) # udp.listen(int(settings.getUDPPort())) # dht_service.init(settings.getDHTPort()) # dht_service.connect() # udp_node.A('go-online', options) reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown) gateway.init() gateway.start() def _ok_to_send(transport, oldstate, newstate): if newstate != 'LISTENING': return # [filename] [peer idurl] if len(sys.argv) >= 3: # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize()) def _try_reconnect(): sess = udp_session.get_by_peer_id(sys.argv[2]) reconnect = False if not sess: reconnect = True print 'sessions', udp_session.sessions_by_peer_id().keys() print map(lambda s: s.peer_id, udp_session.sessions().values()) else: if sess.state != 'CONNECTED': print 'state: ', sess.state reconnect = True if reconnect: print 'reconnect', sess udp_session.add_pending_outbox_file( sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) udp_node.A('connect', sys.argv[2]) reactor.callLater(0.5, _try_reconnect) def _try_connect(): if udp_node.A().state == 'LISTEN': print 'connect' gateway.stop_packets_timeout_loop() udp_session.add_pending_outbox_file( sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False) udp_node.A('connect', sys.argv[2]) reactor.callLater(5, _try_reconnect) else: reactor.callLater(1, _try_connect) # _try_connect() def _send(c): from transport.udp import udp_stream for idurl in sys.argv[2:]: print '_send', udp_stream.streams().keys() p = signed.Packet(commands.Data(), my_id.getLocalID(), my_id.getLocalID(), 'packet%d' % c, bpio.ReadBinaryFile(sys.argv[1]), idurl) gateway.outbox(p) if c > 1: reactor.callLater(0.01, _send, c - 1) reactor.callLater(0, _send, 15) gateway.add_transport_state_changed_callback(_ok_to_send) reactor.run()
import pprint pprint.pprint(backup_fs.fsID()) pprint.pprint(backup_fs.fs()) print backup_fs.GetByID('0') # pprint.pprint(backup_fs.WalkByID('0/0/2/19/F20140106100849AM')) # for pathID, localPath, item in backup_fs.IterateIDs(): # print pathID, misc.unicode_to_str_safe(localPath) # backup_fs.TraverseByIDSorted(lambda x, y, z: sys.stdout.write('%s %s\n' % (x,misc.unicode_to_str_safe(y)))) def test2(): """ For tests. """ # reactor.callLater(1, StartDirRecursive, 'c:/temp') reactor.run() #------------------------------------------------------------------------------ if __name__ == "__main__": bpio.init() lg.set_debug_level(20) settings.init() tmpfile.init(settings.getTempDir()) contactsdb.init() eccmap.init() key.InitMyKey() init() test()
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()
# print backup_fs.sizebackups() import pprint pprint.pprint(backup_fs.fsID()) pprint.pprint(backup_fs.fs()) print backup_fs.GetByID('0') # pprint.pprint(backup_fs.WalkByID('0/0/2/19/F20140106100849AM')) # for pathID, localPath, item in backup_fs.IterateIDs(): # print pathID, misc.unicode_to_str_safe(localPath) # backup_fs.TraverseByIDSorted(lambda x, y, z: sys.stdout.write('%s %s\n' % (x,misc.unicode_to_str_safe(y)))) def test2(): """ For tests. """ # reactor.callLater(1, StartDirRecursive, 'c:/temp') reactor.run() #------------------------------------------------------------------------------ if __name__ == "__main__": bpio.init() lg.set_debug_level(20) settings.init() tmpfile.init(settings.getTempDir()) contactsdb.init() eccmap.init() key.InitMyKey() init() test()