示例#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(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)
示例#2
0
 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