#
Synchronization service
Služba je zodpovedná za sychronizáciu hlasov medzi gateway-om a serverom. Služba je implementovaná ako REST API v knižnici FastAPI.
Služba pracuje s hlasmi v lokálnej Mongo databáze, ktoré boli vložené pomocou Voting service. Hlasy sa synchronizujú po dávkach (prednastavená hodnota je 10) a po zašifrovaní sa posielajú pomocou HTTP požiadavky na endpoint servera, ktorý ich zvaliduje. Synchronizácia prebehne úspešne iba ak sú všetky hlasy v poriadku prijaté. Úspešne synchronizované hlasy označí ako {"synchronized": true}
.
Synchronizácia prebieha na pozadí každú minútu (implementované pomocou FastAPI Utils Repeated Tasks). Dá sa však spustiť aj manuálne pomocou endpointu POST /api/synchronize
, ktorý je popísaný nižšie.
#
Štruktúra posielaných hlasov
Hlasy sú posielané v HTTP požiadavke, ktorú tvorí JSON s ID volebnej miestnosti a hlasmi, ktoré sú zašifrované ako pole zašifrovaných hlasov pomocou knižnice rsaelectie, funkcie encrypt_vote
.
{
"polling_place_id": 0,
"votes": [
{
"encrypted_message": "string",
"encrypted_object": "string"
}
]
}
#
Popis API
#
root__get
Code samples
import requests
headers = {
'Accept': 'application/json'
}
r = requests.get('/gateway/synchronization-service-api/', headers = headers)
print(r.json())
GET /
Root
Simple hello message.
Example responses
200 Response
{
"status": "string",
"message": "string"
}
Responses
Response Schema
#
synchronize_synchronize_post
Code samples
import requests
headers = {
'Accept': 'application/json'
}
r = requests.post('/gateway/synchronization-service-api/synchronize', headers = headers)
print(r.json())
POST /synchronize
Synchronize
Try to send local votes to server and updates local status. If server response is different than 200, response has status 500 with error from server.
Example responses
200 Response
{
"status": "string",
"message": "string"
}
Responses
Response Schema
#
statistics_statistics_post
Code samples
import requests
headers = {
'Accept': 'application/json'
}
r = requests.post('/gateway/synchronization-service-api/statistics', headers = headers)
print(r.json())
POST /statistics
Statistics
Provide statistics of votes in gateway database. Count of synchronized and unsynchronized votes.
Example responses
200 Response
{
"status": "string",
"last_synchronization": null,
"last_success_synchronization": null,
"statistics": {
"all_count": 0,
"syncronized_count": 0,
"unsyncronized_count": 0
}
}
Responses
Response Schema
#
seed_seed_post
Code samples
import requests
headers = {
'Accept': 'application/json'
}
r = requests.post('/gateway/synchronization-service-api/seed', headers = headers)
print(r.json())
POST /seed
Seed
Insert 10 unsynced dummy votes into gataway local gatabase.
Example responses
200 Response
{
"status": "string"
}
Responses
Response Schema
#
test_encrypt_test_encrypt_get
Code samples
import requests
headers = {
'Accept': 'application/json'
}
r = requests.get('/gateway/synchronization-service-api/test-encrypt', headers = headers)
print(r.json())
GET /test-encrypt
Test Encrypt
Get a batch of encrypted votes.
Example responses
200 Response
{
"polling_place_id": 0,
"votes": []
}