コード例 #1
0
    def generate_poa(self, swarm_id, perm_id):
        """
        Generate a POA if the swarm-id private key is available
        """

        status = Status.get_status_holder("LivingLab")

        # Randomly allow 80% to be authorized...
        if random.randint(0,100) > 80:
            status.create_and_add_event("denied", [swarm_id, perm_id])
            status.get_status_element("poas_failed").inc()
            raise Exception("Randomly denied...")

        key_file = os.path.join(KEY_PATH, swarm_id + ".tkey")
        if not os.path.exists(key_file):
            raise Exception("Missing key file")

        # Load keys
        try:
            torrent_keypair = ClosedSwarm.read_cs_keypair(key_file)
        except Exception,e:
            raise Exception("Bad torrent key file")
コード例 #2
0
ファイル: createpoa.py プロジェクト: Anaconda84/Anaconda
        config['key_file'] = torrent + ".tkey"
        
    if not os.path.exists(config['key_file']):
        print "Error: Could not find key file '%s'"%config['key_file']
        raise SystemExit(1)

    # Load the torrent file
    try:
        t = TorrentDef.load(torrent)
    except Exception,e:
        print "Bad torrent file:",e
        raise SystemExit(1)
    if not t.get_cs_keys():
        print "Not a closed swarm torrent"
        raise SystemExit(1)
 
    try:
        torrent_keypair = ClosedSwarm.read_cs_keypair(config['key_file'])
    except Exception,e:
        print "Bad torrent key file",e
        raise SystemExit(1)
    
    # Need permid of the receiving node
    if not config['node_id']:
        print "Missing nodeid"
        raise SystemExit(1)

    create_poa(t, torrent_keypair, 
               config['node_id'], config['output_file'])
    
コード例 #3
0
    if not os.path.exists(config['key_file']):
        print "Error: Could not find key file '%s'"%config['key_file']
        raise SystemExit(1)

    # Load the torrent file
    try:
        t = TorrentDef.load(torrent)
    except Exception,e:
        print "Bad torrent file:",e
        raise SystemExit(1)
    if not t.get_cs_keys():
        print "Not a closed swarm torrent"
        raise SystemExit(1)
 
    try:
        torrent_keypair = ClosedSwarm.read_cs_keypair(config['key_file'])
    except Exception,e:
        print "Bad torrent key file",e
        raise SystemExit(1)
    
    # Need permid of the receiving node
    if not config['node_id']:
        print "Missing nodeid"
        raise SystemExit(1)
    
    if not config['output_file']:
        config['output_file'] = os.path.join(config['node_id'], ".poa")
        config['output_file'] = config['output_file'].replace("/","")
        config['output_file'] = config['output_file'].replace("\\","")