2018-02-13 12:39:27 +00:00
|
|
|
import secrets
|
|
|
|
from tornado.web import RequestHandler, HTTPError
|
2018-02-08 15:26:28 +00:00
|
|
|
|
2018-02-09 13:06:11 +00:00
|
|
|
from tfw.config.logs import logging
|
|
|
|
log = logging.getLogger(__name__)
|
2018-02-08 15:26:28 +00:00
|
|
|
|
|
|
|
class SolutionCheckHandler(RequestHandler):
|
2018-02-13 12:39:27 +00:00
|
|
|
def initialize(self, solvable_connector, token):
|
2018-02-08 15:26:28 +00:00
|
|
|
self.solvable_connector = solvable_connector
|
2018-02-13 12:39:27 +00:00
|
|
|
self.token = token
|
2018-02-08 15:26:28 +00:00
|
|
|
|
2018-02-12 17:04:59 +00:00
|
|
|
async def get(self):
|
2018-02-09 13:06:11 +00:00
|
|
|
log.debug('Sending request to solvable')
|
2018-02-08 15:26:28 +00:00
|
|
|
self.solvable_connector.send('solution_check', {})
|
2018-02-13 12:39:27 +00:00
|
|
|
resp_token, resp_data = await self.solvable_connector.recv()
|
|
|
|
if not secrets.compare_digest(self.token, resp_token):
|
|
|
|
raise HTTPError(500, 'Solvable didn\'t provide initial token.')
|
2018-02-09 13:06:11 +00:00
|
|
|
log.debug('Received answer from solvable')
|
2018-02-09 13:04:47 +00:00
|
|
|
self.write(resp_data)
|