Пример #1
0
from client_tallier import ClientTallier
from client_registrar import ClientRegistrar
from client_authority import ClientAuthority
import entity_locations
import sys
from voter import Voter

import pickle
import random
from flask import Flask, render_template, request
from flaskext.xmlrpc import XMLRPCHandler, Fault

app = Flask(__name__)
r_endpoint = entity_locations.get_registrar_endpoint()
# may want to remove the endpoint location
r = ClientRegistrar(r_endpoint)
a_endpoint = entity_locations.get_authority_endpoint()
a = ClientAuthority()


@app.route('/api/submit_vote', methods=['POST'])
def submit_vote():
    message = 'Success!'
    try:
        e, tallier_endpoints = r.get_election(int(request.form['eid']))
        if not e:
            message = 'Invalid Election ID'
            return render_template('voting_interface.html',
                                   submit_vote_msg=message)

        t = ClientTallier(random.choice(tallier_endpoints))
Пример #2
0
import random
import pickle
import sys


if __name__ == '__main__':
    voter_ids = ['rsridhar', 'kevinzhu', 'vmohan', 'sunl', 'akshayr']
    candidates = ['bernie', 'shillary']

    NUM_VOTERS = len(voter_ids)
    NUM_CANDIDATES = len(candidates)
    FREQUENCY = 1


    r_endpoint = entity_locations.get_registrar_endpoint()
    r = ClientRegistrar(r_endpoint)
    eid = r.register_election(voter_ids, candidates)
    print("Got Election ID", eid)
    if eid == False:
        print("Could not get an election")
        sys.exit(0)

    e, tallier_endpoints = r.get_election(eid)

    print("Connected to Talliers:")
    for endpoint in tallier_endpoints:
        print(endpoint.hostname, str(endpoint.port))

    voters = [Voter(voter_ids[i], r, ClientTallier(tallier_endpoints[i%len(tallier_endpoints)]), e) for i in range(NUM_VOTERS)]
    expected_vote_totals = {candidates[i]:0 for i in range(NUM_CANDIDATES)}