def send_file_single(self, remote_idurl, filename, host, description=''): """ """ return tcp_node.send(filename, net_misc.normalize_address(host), description, keep_alive=False)
def _send_new_identity(self): """ Send created identity to the identity servers to register it. """ if _Debug: lg.out(_DebugLevel, 'id_registrator._send_new_identity') from transport.tcp import tcp_node sendfilename = settings.LocalIdentityFilename() + '.new' dlist = [] for idurl in self.new_identity.getSources(as_originals=True): 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, )) if _Debug: lg.out(_DebugLevel, ' sending to %r via TCP' % srvhost) dlist.append( tcp_node.send( sendfilename, srvhost, 'Identity', keep_alive=False, )) return DeferredList(dlist, fireOnOneCallback=True)
def SendServers(): """ My identity file can be stored in different locations, see the "sources" field. So I can use different identity servers to store more secure. This method will send my identity file to all my identity servers via transport_tcp. """ from transport.tcp import tcp_node sendfile, sendfilename = tmpfile.make("propagate") os.close(sendfile) LocalIdentity = my_id.getLocalIdentity() bpio.WriteFile(sendfilename, LocalIdentity.serialize()) dlist = [] for idurl in LocalIdentity.sources: # sources for out identity are servers we need to send to protocol, host, port, filename = nameurl.UrlParse(idurl) # if host == settings.IdentityServerName(): # host = '67.207.147.183' webport, tcpport = known_servers.by_host().get( host, (settings.IdentityWebPort(), settings.IdentityServerPort())) # srvhost = '%s:%d' % (host, int(tcpport)) dlist.append( tcp_node.send(sendfilename, (host, int(tcpport)), 'Identity', True)) # dlist.append(gateway.send_file_single('tcp', srvhost, sendfilename, 'Identity')) dl = DeferredList(dlist, consumeErrors=True) return dl
def _do_send_my_identity(self): """ Send my updated identity to the identity servers to register it. """ from transport.tcp import tcp_node sendfilename = settings.LocalIdentityFilename() my_sources = my_id.getLocalIdentity().getSources(as_originals=True) dlist = [] if _Debug: lg.out( _DebugLevel, 'id_rotator._do_send_my_identity my_sources=%r' % my_sources) for idurl_bin in my_sources: _, host, _, _ = nameurl.UrlParse(idurl_bin) tcpport = None if host in self.preferred_servers: tcpport = int(self.preferred_servers[host][1]) if not tcpport and host in self.known_servers: tcpport = int(self.known_servers[host][1]) if not tcpport: tcpport = settings.IdentityServerPort() srvhost = net_misc.pack_address(( host, tcpport, )) if _Debug: lg.out(_DebugLevel, ' sending to %r via TCP' % srvhost) dlist.append( tcp_node.send( sendfilename, srvhost, 'Identity', keep_alive=False, )) return DeferredList(dlist, fireOnOneCallback=True)
def SendServers(): """ My identity file can be stored in different locations, see the "sources" field. So I can use different identity servers to store more secure and reliable. This method will send my identity file to all my identity servers via transport_tcp. """ from transport.tcp import tcp_node sendfile, sendfilename = tmpfile.make("propagate") os.close(sendfile) LocalIdentity = my_id.getLocalIdentity() bpio.WriteTextFile(sendfilename, LocalIdentity.serialize(as_text=True)) dlist = [] for idurl in LocalIdentity.getSources(as_originals=True): # sources for out identity are servers we need to send to protocol, host, port, filename = nameurl.UrlParse(idurl) # TODO: rebuild identity-server logic to be able to send my identity via HTTP POST instead of TCP and # get rid of second TCP port at all webport, tcpport = known_servers.by_host().get(host, ( # by default use "expected" port numbers settings.IdentityWebPort(), settings.IdentityServerPort())) normalized_address = net_misc.normalize_address((host, int(tcpport), )) dlist.append(tcp_node.send( sendfilename, normalized_address, 'Identity', keep_alive=False, )) if _Debug: lg.args(_DebugLevel, normalized_address=normalized_address, filename=filename) dl = DeferredList(dlist, consumeErrors=True) return dl
def main(): lg.set_debug_level(24) if len(sys.argv) >= 4 and sys.argv[1] == 'connect': tcp_node.connect_to( net_misc.normalize_address((sys.argv[2], int(sys.argv[3])))) reactor.run() return if len(sys.argv) >= 5 and sys.argv[1] == 'send': tcp_node.send( sys.argv[2], net_misc.normalize_address((sys.argv[3], int(sys.argv[4])))) reactor.run() return print('Usage:') print('tcp_node.py <command> <arguments>') print('') print('Commands:') print(' connect host port') print(' send filename host port') print('')
def send_file_single(self, remote_idurl, filename, host, description=''): """ """ host = host.split(':') host = (host[0], int(host[1])) return tcp_node.send(filename, host, description, keep_alive=False)