Exemplo n.º 1
0
def do_replicate(sock: socket) -> bool:
    job = RecvJob(sock)
    ip = RecvStr(sock)
    # noinspection PyTypeChecker
    SSP.replicate(ip, job)
    SendResponse(sock, SUCCESS)
    return False
Exemplo n.º 2
0
def download(sock: socket) -> bool:
    job = RecvJob(sock)
    path = RecvStr(sock)
    j = Jobs.AddDownloadJob(job, [path])
    SendResponse(sock, SUCCESS)
    if not j.wait(LoadTimeout):
        Jobs.CompleteJob(job)
        return True
    return False
Exemplo n.º 3
0
def prepare_replicate(sock: socket) -> bool:
    job = RecvJob(sock)
    paths = RecvStr(sock)
    paths = paths.strip().split(PathSeparator)
    j = Jobs.AddReplicationJob(job, paths)
    SendResponse(sock, SUCCESS)
    if not j.wait(LoadTimeout):
        Jobs.CompleteJob(job)
        return True
    return False
Exemplo n.º 4
0
def download(sock: socket, virt: str, real: str) -> ResponseType:
    SendStr(sock, virt)
    re = RecvResponse(sock)
    if re != SUCCESS:
        return re
    # Remote accepted request
    job = RecvJob(sock)
    pubip = RecvStr(sock)
    # Connect to storage
    # noinspection PyTypeChecker
    if CSP.download(pubip, job, real):
        SendResponse(sock, SUCCESS)
        return SUCCESS
    # Response to server
    SendResponse(sock, DownloadFail % real)
    return DownloadFail % real
Exemplo n.º 5
0
def ServeClient(sock: socket):
    job = RecvJob(sock)
    j = Jobs.StartJob(sock, job)
    if j:
        path = j.paths[0]
        if j.typ == Jobs.JT_Upload:
            upload(sock, path)
        elif j.typ == Jobs.JT_Download:
            download(sock, path)
        elif j.typ == Jobs.JT_Replicate:
            raise CSPException('Replication job passed from client %s:%d' %
                               sock.getpeername())
        else:
            raise CSPException('Unknown job passed from client %s:%d' %
                               sock.getpeername())
    else:
        raise CSPException('Invalid job passed from client %s:%d' %
                           sock.getpeername())