Пример #1
0
    def _send_new_identity(self):
        """
        Send created identity to the identity server to register it.

        TODO: need to close transport and gateway after that
        """
        lg.out(4, 'id_registrator._send_new_identity ')
        from transport import gateway
        from transport import network_transport
        from transport.tcp import tcp_interface
        gateway.init()
        interface = tcp_interface.GateInterface()
        transport = network_transport.NetworkTransport('tcp', interface)
        transport.automat('init', gateway.listener())
        transport.automat('start')
        gateway.start()
        sendfilename = settings.LocalIdentityFilename() + '.new'
        dlist = []
        for idurl in self.new_identity.sources:
            self.free_idurls.remove(idurl)
            _, host, _, _ = nameurl.UrlParse(idurl)
            _, tcpport = known_servers.by_host().get(
                host, (settings.IdentityWebPort(), settings.IdentityServerPort()))
            srvhost = '%s:%d' % (host, tcpport)
            dlist.append(gateway.send_file_single(
                idurl, 'tcp', srvhost, sendfilename, 'Identity'))
        assert len(self.free_idurls) == 0
        return DeferredList(dlist)
Пример #2
0
 def _send_new_identity(self):
     """
     Send created identity to the identity server to register it.
     TODO: need to close transport and gateway after that
     """
     lg.out(4, 'id_registrator._send_new_identity ')
     from transport import gateway
     from transport import network_transport
     from transport.tcp import tcp_interface
     gateway.init()
     interface = tcp_interface.GateInterface()
     transport = network_transport.NetworkTransport('tcp', interface)
     transport.automat('init', gateway.listener())
     transport.automat('start')
     gateway.start()
     sendfilename = settings.LocalIdentityFilename() + '.new'
     dlist = []
     for idurl in self.new_identity.sources:
         self.free_idurls.remove(strng.to_bin(idurl))
         _, host, _, _ = nameurl.UrlParse(idurl)
         _, tcpport = known_servers.by_host().get(
             host,
             (settings.IdentityWebPort(), settings.IdentityServerPort()))
         srvhost = net_misc.pack_address((
             host,
             tcpport,
         ))
         dlist.append(
             gateway.send_file_single(idurl, 'tcp', srvhost, sendfilename,
                                      'Identity'))
     # assert len(self.free_idurls) == 0
     return DeferredList(dlist, fireOnOneCallback=True)
 def start(self):
     from twisted.internet import reactor  # @UnresolvedImport
     from twisted.internet.defer import Deferred
     from logs import lg
     from transport.proxy import proxy_interface
     from transport import network_transport
     from transport import gateway
     from services import driver
     from main import events
     from main.config import conf
     if len(self._available_transports()) == 0:
         lg.warn('no transports available')
         return False
     events.add_subscriber(self._on_dht_layer_connected,
                           'dht-layer-connected')
     self._check_reset_original_identity()
     self.starting_deferred = Deferred()
     self.transport = network_transport.NetworkTransport(
         'proxy', proxy_interface.GateInterface())
     conf().addConfigNotifier('services/proxy-transport/enabled',
                              self._on_enabled_disabled)
     conf().addConfigNotifier('services/proxy-transport/sending-enabled',
                              self._on_sending_enabled_disabled)
     conf().addConfigNotifier('services/proxy-transport/receiving-enabled',
                              self._on_receiving_enabled_disabled)
     if driver.is_on('service_entangled_dht'):
         self._do_join_proxy_routers_dht_layer()
     else:
         self.transport.automat(
             'init', (gateway.listener(), self._on_transport_state_changed))
         reactor.callLater(0, self.transport.automat,
                           'start')  # @UndefinedVariable
     return self.starting_deferred
 def start(self):
     from twisted.internet import reactor
     from twisted.internet.defer import Deferred
     from logs import lg
     from transport.proxy import proxy_interface
     from transport import network_transport
     from transport import gateway
     from main.config import conf
     if len(self._available_transports()) == 0:
         lg.warn('no transports available')
         return False
     self._check_update_original_identity()
     self.starting_deferred = Deferred()
     self.interface = proxy_interface.GateInterface()
     self.transport = network_transport.NetworkTransport(
         'proxy', self.interface)
     self.transport.automat(
         'init', (gateway.listener(), self._on_transport_state_changed))
     reactor.callLater(0, self.transport.automat, 'start')
     conf().addCallback('services/proxy-transport/enabled',
                        self._on_enabled_disabled)
     conf().addCallback('services/proxy-transport/sending-enabled',
                        self._on_sending_enabled_disabled)
     conf().addCallback('services/proxy-transport/receiving-enabled',
                        self._on_receiving_enabled_disabled)
     return self.starting_deferred
Пример #5
0
 def start(self):
     from twisted.internet import reactor  # @UnresolvedImport
     from twisted.internet.defer import Deferred
     from logs import lg
     from transport.proxy import proxy_interface
     from transport import network_transport
     from transport import gateway
     from main.config import conf
     if len(self._available_transports()) == 0:
         lg.warn('no transports available')
         return False
     self._check_reset_original_identity()
     self.starting_deferred = Deferred()
     self.transport = network_transport.NetworkTransport(
         'proxy', proxy_interface.GateInterface())
     self.transport.automat(
         'init', (gateway.listener(), self._on_transport_state_changed))
     reactor.callLater(0, self.transport.automat, 'start')
     conf().addCallback('services/proxy-transport/enabled',
                        self._on_enabled_disabled)
     conf().addCallback('services/proxy-transport/sending-enabled',
                        self._on_sending_enabled_disabled)
     conf().addCallback('services/proxy-transport/receiving-enabled',
                        self._on_receiving_enabled_disabled)
     return self.starting_deferred
 def _on_proxy_routers_dht_layer_connect_failed(self, err):
     from logs import lg
     from transport import gateway
     lg.err('failed to connect to DHT layer: %r' % err)
     if self.starting_deferred and not self.starting_deferred.called:
         self.transport.automat(
             'init', (gateway.listener(), self._on_transport_state_changed))
         reactor.callLater(0, self.transport.automat,
                           'start')  # @UndefinedVariable
Пример #7
0
 def start(self):
     from twisted.internet import reactor  # @UnresolvedImport
     from twisted.internet.defer import Deferred
     from transport.http import http_interface
     from transport import network_transport
     from transport import gateway
     from main.config import conf
     self.starting_deferred = Deferred()
     self.transport = network_transport.NetworkTransport(
         'http', http_interface.GateInterface())
     self.transport.automat(
         'init', (gateway.listener(), self._on_transport_state_changed))
     reactor.callLater(0, self.transport.automat, 'start')
     conf().addCallback('services/http-transport/enabled',
                        self._on_enabled_disabled)
     conf().addCallback('services/http-transport/receiving-enabled',
                        self._on_receiving_enabled_disabled)
     return self.starting_deferred
 def start(self):
     from twisted.internet import reactor
     from twisted.internet.defer import Deferred
     from transport.tcp import tcp_interface
     from transport import network_transport
     from transport import gateway
     from main.config import conf
     self.starting_deferred = Deferred()
     self.interface = tcp_interface.GateInterface()
     self.transport = network_transport.NetworkTransport(
         'tcp', self.interface)
     self.transport.automat('init',
                            (gateway.listener(), self._on_transport_state_changed))
     reactor.callLater(0, self.transport.automat, 'start')
     conf().addCallback('services/tcp-transport/enabled',
                        self._on_enabled_disabled)
     conf().addCallback('services/tcp-transport/receiving-enabled',
                        self._on_receiving_enabled_disabled)
     return self.starting_deferred
 def _on_proxy_routers_dht_layer_connected(self, ok):
     from twisted.internet import reactor  # @UnresolvedImport
     from logs import lg
     from dht import dht_service
     from dht import dht_records
     from transport import gateway
     from userid import my_id
     lg.info('connected to DHT layer for proxy routers: %r' % ok)
     if my_id.getIDURL():
         dht_service.set_node_data('idurl',
                                   my_id.getIDURL().to_text(),
                                   layer_id=dht_records.LAYER_PROXY_ROUTERS)
     if self.transport:
         if self.starting_deferred and not self.starting_deferred.called:
             self.transport.automat(
                 'init',
                 (gateway.listener(), self._on_transport_state_changed))
             reactor.callLater(0, self.transport.automat,
                               'start')  # @UndefinedVariable
     return ok
Пример #10
0
 def start(self):
     from twisted.internet import reactor  # @UnresolvedImport
     from twisted.internet.defer import Deferred
     from transport.udp import udp_interface
     from transport import network_transport
     from transport import gateway
     from main.config import conf
     self.starting_deferred = Deferred()
     self.transport = network_transport.NetworkTransport('udp', udp_interface.GateInterface())
     self.transport.automat(
         'init', (gateway.listener(), self._on_transport_state_changed))
     reactor.callLater(0, self.transport.automat, 'start')  # @UndefinedVariable
     conf().addConfigNotifier('services/udp-transport/enabled',
                        self._on_enabled_disabled)
     conf().addConfigNotifier('services/udp-transport/receiving-enabled',
                        self._on_receiving_enabled_disabled)
     conf().addConfigNotifier('services/network/receive-limit',
                        self._on_network_receive_limit_modified)
     conf().addConfigNotifier('services/network/send-limit',
                        self._on_network_send_limit_modified)
     return self.starting_deferred