<s> import gevent <EOL> import random <EOL> import string <EOL> from powerpool . clients import StratumClients <EOL> import logging <EOL> logging . getLogger ( ) . addHandler ( logging . StreamHandler ( ) ) <EOL> SEED_CLIENTS = <NUM_LIT:1000> <EOL> client_id = <NUM_LIT:0> <EOL> def rand_str ( N ) : <EOL> return '<STR_LIT>' . join ( random . choice ( string . ascii_uppercase + string . digits ) for _ in range ( N ) ) <EOL> class DummyClient ( object ) : <EOL> def __init__ ( self , address , worker , id ) : <EOL> self . address = address <EOL> self . worker = worker <EOL> self . id = id <EOL> class DummyReporter ( object ) : <EOL> def add_one_minute ( self , address , acc , stamp , worker , dup , low , stale ) : <EOL> print "<STR_LIT>" <EOL> def add_shares ( self , address , shares ) : <EOL> print "<STR_LIT>" <EOL> def agent_send ( self , address , worker , typ , data , time ) : <EOL> print "<STR_LIT>" <EOL> def transmit_block ( self , address , worker , height , total_subsidy , fees , <EOL> hex_bits , hash , merged ) : <EOL> pass <EOL> class DummyServer ( object ) : <EOL> reporter = DummyReporter ( ) <EOL> config = dict ( share_batch_interval = <NUM_LIT:10> ) <EOL> server = DummyServer ( ) <EOL> clients = StratumClients ( server ) <EOL> clients . start ( ) <EOL> def client_sim ( ) : <EOL> global client_id <EOL> print "<STR_LIT>" . format ( client_id ) <EOL> if clients . address_lut . keys ( ) and random . randint ( <NUM_LIT:1> , <NUM_LIT:3> ) == <NUM_LIT:1> : <EOL> address = random . choice ( clients . address_lut . keys ( ) ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> address = rand_str ( <NUM_LIT> ) <EOL> worker = rand_str ( <NUM_LIT:10> ) <EOL> client = DummyClient ( address , worker , client_id ) <EOL> clients [ client_id ] = client <EOL> clients . set_user ( client ) <EOL> client_id += <NUM_LIT:1> <EOL> try : <EOL> while True : <EOL> if <NUM_LIT:1> == random . randint ( <NUM_LIT:1> , <NUM_LIT:100> ) : <EOL> break <EOL> if <NUM_LIT:1> == random . randint ( <NUM_LIT:1> , <NUM_LIT:5> ) : <EOL> clients . add_share ( address , worker , <NUM_LIT:100> , <NUM_LIT:1> ) <EOL> gevent . sleep ( random . uniform ( <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> finally : <EOL> del clients [ client . id ] <EOL> print "<STR_LIT>" . format ( client . id ) <EOL> def client_maker ( ) : <EOL> for i in xrange ( SEED_CLIENTS ) : <EOL> gevent . spawn ( client_sim ) <EOL> while True : <EOL> gevent . sleep ( random . uniform ( <NUM_LIT> , <NUM_LIT:2> ) ) <EOL> client_sim ( ) <EOL> gevent . joinall ( [ gevent . spawn ( client_maker ) ] ) </s>
