github.com/annchain/OG@v0.0.9/scripts/p2p_sim/config_generator.py (about)

     1  
     2  import sys
     3  import socket
     4  import toml
     5  
     6  boot_node = 'a4d8435e9923d6cc950ff47df5f8fef469b1acfa255cf9b5daab53abdca3d76403bda33ebedd1336d526ffc510c9420c7df0731ee37ea6b28780ca6011fe741e'
     7  boot_node_key = '3fa29b2f6b83e037e2573545a6d9c06c0809aeb929cc8c14f992546ae5530b7d'
     8  boot_ip = '172.28.152.31'
     9  #boot_ip = '127.0.0.1'
    10  
    11  def generate_config(id, seq_enabled):
    12      with open('sample.toml') as f:
    13          d = toml.load(f)
    14  
    15      port_add = 11300 + id * 10
    16  
    17      d['rpc']['port'] = port_add + 0
    18      d['p2p']['port'] = port_add + 1
    19      d['p2p']['bootstrap_node'] = seq_enabled
    20      d['p2p']['bootstrap_nodes'] = "onode://%s@%s:%d" % (boot_node,boot_ip, 11301)
    21      if (seq_enabled ):
    22          d['p2p']['node_key'] = boot_node_key
    23      d['websocket']['port'] = port_add + 2
    24      d['profiling']['port'] = port_add + 3
    25      d['leveldb']['path'] = 'data/datadir_%02d' % (id)
    26      #change it to true manualy
    27      d['auto_client']['sequencer']['enabled'] = seq_enabled
    28      d['auto_client']['tx']['enabled'] = False
    29      d['auto_client']['tx']['account_ids'] = [id,]
    30  
    31      d['debug']['node_id'] = id
    32  
    33      with open('configs/config_%02d.toml' % (id), 'w') as f:
    34          toml.dump(d, f)
    35  
    36      return d
    37  
    38  
    39  def public_ip():
    40      try:
    41          s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    42          s.connect(('114.114.114.114', 80))
    43          ip = s.getsockname()[0]
    44      finally:
    45          s.close()
    46      return ip
    47  
    48  
    49  if __name__ == '__main__':
    50      total = len(sys.argv) <= 1 and 100 or sys.argv[1]
    51      ip = public_ip()
    52      enable_sequencer = False
    53      if  ip == boot_ip or boot_ip == '127.0.0.1' :
    54          enable_sequencer = True
    55      print('Total nodes: %d. Sequencer: %s' % (total, enable_sequencer))
    56  
    57      for i in range(total):
    58          generate_config(i, i == 0 and enable_sequencer)