<s> """<STR_LIT>""" <EOL> import argparse <EOL> from lbrynet . dht . node import Node <EOL> from txjsonrpc . web import jsonrpc <EOL> from twisted . web import server <EOL> from twisted . internet import reactor , defer <EOL> class RPCNode ( jsonrpc . JSONRPC ) : <EOL> def __init__ ( self , node , shut_down_cb ) : <EOL> jsonrpc . JSONRPC . __init__ ( self ) <EOL> self . node = node <EOL> self . shut_down_cb = shut_down_cb <EOL> def jsonrpc_total_dht_nodes ( self ) : <EOL> return self . node . getApproximateTotalDHTNodes ( ) <EOL> def jsonrpc_total_dht_hashes ( self ) : <EOL> return self . node . getApproximateTotalHashes ( ) <EOL> def jsonrpc_stop ( self ) : <EOL> self . shut_down_cb ( ) <EOL> return "<STR_LIT>" <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> type = int ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> type = int ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> nargs = '<STR_LIT:?>' ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> nargs = '<STR_LIT:?>' , default = <NUM_LIT> , type = int ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> default = "<STR_LIT:127.0.0.1>" ) <EOL> args = parser . parse_args ( ) <EOL> def start_rpc ( ) : <EOL> rpc_node = RPCNode ( node , shut_down ) <EOL> reactor . listenTCP ( args . rpc_port , server . Site ( rpc_node ) , interface = args . rpc_ip_address ) <EOL> def shut_down ( ) : <EOL> d = defer . maybeDeferred ( node . stop ) <EOL> d . addBoth ( lambda _ : reactor . stop ( ) ) <EOL> return d <EOL> known_nodes = [ ] <EOL> if args . dht_bootstrap_host : <EOL> known_nodes . append ( ( args . dht_bootstrap_host , args . dht_bootstrap_port ) ) <EOL> node = Node ( udpPort = args . node_port ) <EOL> node . joinNetwork ( known_nodes ) <EOL> d = node . _joinDeferred <EOL> d . addCallback ( lambda _ : start_rpc ( ) ) <EOL> reactor . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
