Exemplo n.º 1
0
def request(linkedLibraries, filePath, peerIP=HOST, MYTOKEN="0123456789ABCDF", gcc=False, zipf=False):  # @IgnorePep8
    '''
    '''
    if gcc:
        appID = AppID_GCC
    else:
        appID = AppID_GPP
    if zipf:
        outChannel = CHANNEL_ZIP_FTP
    else:
        outChannel = CHANNEL_FTP
    '''
    MAKE MSG
    '''
    header = MYTOKEN+'\n'+TYPE_API_REQUEST_MSG+'\n'
    apiRequestMsg = appID+'\n'\
        + linkedLibraries + '\n'\
        + outChannel + '\n'\
        + str(fileLength(filePath)) + '\n'\
        + CHANNEL_FTP + '\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_API_REQUESTS)
    dummySocket.sendData(header+apiRequestMsg)
    '''
    GET TICKET
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    ticket = answerData.split('\n')[2]
    return ticket
Exemplo n.º 2
0
def request():
    '''
    Requests the run of the SHA256 over a local file, without data recovery
    '''
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_API_REQUEST_MSG+'\n'
    apiRequestMsg = AppID_SHA256_TEST+'\n'\
        + "60000 -verbose 20000" + '\n'\
        + CHANNEL_LOCAL_FILE + '\n'\
        + "testsData/experimentData.dat"+'\n'\
        + CHANNEL_LOCAL_FILE + '\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(ASSISTANCE_SERVER, PORT_API_REQUESTS)
    dummySocket.sendData(header+apiRequestMsg)
    '''
    GET TICKET
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    ticket = answerData.split('\n')[2]
    return ticket
Exemplo n.º 3
0
def request(filePath, runTimes, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    '''
    Requests execution of the AssistanceApp.
Forms the message to be sent, specifying the parameters of the execution
of the app. Then, sends it and receives a ticket as answer
    :param filePath: the path to the file to be sent.
It will be used to determine the size of the file, necessary for the task submission.  # @IgnorePep8
    '''
    '''
    MAKE MSG
    '''
    header = MYTOKEN+'\n'+TYPE_API_REQUEST_MSG+'\n'
    apiRequestMsg = AppID_SHA256_TEST+'\n'\
        + runTimes + '\n'\
        + CHANNEL_FTP + '\n'\
        + fileLength(filePath) + '\n'\
        + CHANNEL_FTP + '\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_API_REQUESTS)
    dummySocket.sendData(header+apiRequestMsg)
    '''
    GET TICKET
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    ticket = answerData.split('\n')[2]
    return ticket
Exemplo n.º 4
0
def submit(serviceTicket, filePath, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    '''
    Sends a file over Assistance.
Waits until the task is ready to receive data, then sends it
    :param serviceTicket: the ticket of the task to be verified.
    :param filePath: The ABSPATH to the file to be sent.
    '''
    while checkStatus(serviceTicket, peerIP) != STATUS_GATHERING_DATA:
        time.sleep(TIME_DATA_SERVER_INTERVAL)
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    header = MYTOKEN + '\n' + TYPE_DATA_SUBMIT_MSG + '\n'
    submitMsg = serviceTicket + '\n' + filePath.split('/')[-1] + '\n'  # @IgnorePep8
    dummySocket.sendData(header + submitMsg)
    dummySocket.sendData(open(filePath, 'rb').read())
    dummySocket.close()
Exemplo n.º 5
0
def submit(serviceTicket, filePath, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    """
    Sends a file over Assistance.
Waits until the task is ready to receive data, then sends it
    :param serviceTicket: the ticket of the task to be verified.
    :param filePath: The ABSPATH to the file to be sent.
    """
    while checkStatus(serviceTicket, peerIP) != STATUS_GATHERING_DATA:
        time.sleep(TIME_DATA_SERVER_INTERVAL)
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    header = MYTOKEN + "\n" + TYPE_DATA_SUBMIT_MSG + "\n"
    submitMsg = serviceTicket + "\n" + filePath.split("/")[-1] + "\n"
    dummySocket.sendData(header + submitMsg)
    dummySocket.sendFile(filePath)
    dummySocket.close()
Exemplo n.º 6
0
def checkStatus(serviceTicket):
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_STATUS_CHECK_MSG+'\n'
    statusCheckMsg = serviceTicket+'\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(ASSISTANCE_SERVER, PORT_DATA_REQUESTS)
    dummySocket.sendData(header+statusCheckMsg)
    '''
    GET STATUS
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    status = answerData.split('\n')[3]
    return status
Exemplo n.º 7
0
def synch(serviceTicket, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    """
    Waits until the task is completed, and ready for redeem.
Then recovers the answers
    :param serviceTicket: ticket of the task to be recovered
    """
    while checkStatus(serviceTicket, peerIP) != STATUS_READY:
        time.sleep(TIME_DATA_SERVER_INTERVAL)
    """
    MAKE MSG
    """
    header = MYTOKEN + "\n" + TYPE_RECOVER_RESULTS_MSG + "\n"
    recoverMsg = serviceTicket + "\n"
    """
    SEND
    """
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    dummySocket.sendData(header + recoverMsg)
    """
    GET THE ANSWER FILES
    """
    # creates the files to return
    stdout = "testsResults/" + serviceTicket + "-stdout.dat"
    stderr = "testsResults/" + serviceTicket + "-stderr.dat"
    # stdoutFile = open(stdout, 'wb')
    # stderrFile = open(stderr, 'wb')
    with open(stdout, "wb") as stdoutFile, open(stderr, "wb") as stderrFile:
        currentFile = stdoutFile
        receivedData = dummySocket.receiveData()
        while receivedData:
            if SYMBOL_SEPARATOR in receivedData:
                filePieces = receivedData.split(SYMBOL_SEPARATOR)
                stdoutFile.write(filePieces[0])
                stderrFile.write(filePieces[1])
                currentFile = stderrFile
            else:
                currentFile.write(receivedData)
            receivedData = dummySocket.receiveData()
    # closes up and returns
    # stdoutFile.close()
    # stderrFile.close()
    dummySocket.close()
    return stdout, stderr
Exemplo n.º 8
0
def synch(serviceTicket, peerIP=HOST):
    '''
    Waits until the task is completed, and ready for redeem.
Then recovers the answers
    :param serviceTicket: ticket of the task to be recovered
    '''
    while checkStatus(serviceTicket, peerIP) != STATUS_READY:
        time.sleep(TIME_DATA_SERVER_INTERVAL)
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_RECOVER_RESULTS_MSG+'\n'
    recoverMsg = serviceTicket+'\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    dummySocket.sendData(header+recoverMsg)
    '''
    GET THE ANSWER FILES
    '''
    # creates the files to return
    stdout = "testsResults/"+serviceTicket+"-stdout.dat"
    stderr = "testsResults/"+serviceTicket+"-stderr.dat"
    stdoutFile = open(stdout, 'wb')
    stderrFile = open(stderr, 'wb')
    currentFile = stdoutFile
    receivedData = dummySocket.receiveData()
    while receivedData:
        if SYMBOL_SEPARATOR in receivedData:
            filePieces = receivedData.split(SYMBOL_SEPARATOR)
            stdoutFile.write(filePieces[0])
            stderrFile.write(filePieces[1])
            currentFile = stderrFile
        else:
            currentFile.write(receivedData)
        receivedData = dummySocket.receiveData()
    # closes up and returns
    stdoutFile.close()
    stderrFile.close()
    dummySocket.close()
    return stdout+'\n'+stderr
Exemplo n.º 9
0
def synch(serviceTicket, peerIP=HOST):
    while checkStatus(serviceTicket, peerIP) != STATUS_READY:
        time.sleep(0.1)
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_RECOVER_RESULTS_MSG+'\n'
    recoverMsg = serviceTicket+'\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    dummySocket.sendData(header+recoverMsg)
    '''
    GET RESULTS
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    results = answerData.split('\n')[4]
    return results
Exemplo n.º 10
0
def request(messageToEcho, peerIP=HOST):
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_API_REQUEST_MSG+'\n'
    apiRequestMsg = AppID_LOCAL_ECHO_TEST + '\n'\
        + messageToEcho + '\n' + NULL + '\n'\
        + NULL + '\n'\
        + CHANNEL_IMMEDIATE + '\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_API_REQUESTS)
    dummySocket.sendData(header+apiRequestMsg)
    '''
    GET TICKET
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    ticket = answerData.split('\n')[2]
    return ticket
Exemplo n.º 11
0
def request(wekaFunction, arguments, filePath, peerIP=HOST, MYTOKEN="0123456789ABCDF"):  # @IgnorePep8
    """
    Requests a WEKA APP_ID Quest to the Assistance System
    :param wekaFunction: WEKA function to be run
    :param arguments: arguments for the WEKA function
    :param filePath: path to the WEKA data file
    :param peerIP: IP to send the request to
    """
    # Checks if it is a known WEKA function
    wekaFunctionsList = open("testsData/assistanceWEKAfunctions.txt", "r").read()  # @IgnorePep8
    if str(wekaFunction) not in wekaFunctionsList:
        raise ValueError("ERROR! WEKA FUNCTION NOT KNOWN TO ASSISTANCE!")
    # Making the message
    header = MYTOKEN + "\n" + TYPE_API_REQUEST_MSG + "\n"
    apiRequestMsg = (
        AppID_WEKA
        + "\n"
        + wekaFunction
        + " "
        + arguments
        + "\n"
        + CHANNEL_FTP
        + "\n"
        + fileLength(filePath)
        + "\n"
        + CHANNEL_FTP
        + "\n"
    )
    """
    SEND
    """
    dummySocket = AssistanceSocketClient(peerIP, PORT_API_REQUESTS)
    dummySocket.sendData(header + apiRequestMsg)
    """
    GET TICKET
    """
    answerData = dummySocket.receiveData()
    dummySocket.close()
    ticket = answerData.split("\n")[2]
    return ticket
Exemplo n.º 12
0
def checkStatus(serviceTicket, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    '''
    Sends a message checking the current status of the given ticket, and returns  # @IgnorePep8
        that status
    :param serviceTicket: the ticket of the task with the status is to be checked  # @IgnorePep8
    '''
    '''
    MAKE MSG
    '''
    header = MYTOKEN+'\n'+TYPE_STATUS_CHECK_MSG+'\n'
    statusCheckMsg = serviceTicket+'\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    dummySocket.sendData(header+statusCheckMsg)
    '''
    GET STATUS
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    status = answerData.split('\n')[3]
    return status
Exemplo n.º 13
0
def checkStatus(serviceTicket, peerIP=HOST, MYTOKEN="0123456789ABCDF"):
    """
    Sends a message checking the current status of the given ticket, and returns  # @IgnorePep8
        that status
    :param serviceTicket: the ticket of the task with the status is to be checked  # @IgnorePep8
    """
    """
    MAKE MSG
    """
    header = MYTOKEN + "\n" + TYPE_STATUS_CHECK_MSG + "\n"
    statusCheckMsg = serviceTicket + "\n"
    """
    SEND
    """
    dummySocket = AssistanceSocketClient(peerIP, PORT_DATA_REQUESTS)
    dummySocket.sendData(header + statusCheckMsg)
    """
    GET STATUS
    """
    answerData = dummySocket.receiveData()
    dummySocket.close()
    status = answerData.split("\n")[3]
    return status
Exemplo n.º 14
0
def synch(serviceTicket):
    '''
    Waits untill the task is completed, and ready for redeem
    '''
    while checkStatus(serviceTicket) != STATUS_READY:
        time.sleep(0.1)
    '''
    MAKE MSG
    '''
    header = TOKEN_TESTS_VERSION+'\n'+TYPE_RECOVER_RESULTS_MSG+'\n'
    recoverMsg = serviceTicket+'\n'
    '''
    SEND
    '''
    dummySocket = AssistanceSocketClient(ASSISTANCE_SERVER, PORT_DATA_REQUESTS)
    dummySocket.sendData(header+recoverMsg)
    '''
    GET RESULTS
    '''
    answerData = dummySocket.receiveData()
    dummySocket.close()
    results = answerData.split('\n')[4] + '\n'\
        + answerData.split('\n')[5]
    return results