예제 #1
0
def handle_push():
    """
    Handles the push opcode. Firstly it will check if there are commits to push using the commit counter from the JSON
    file, after that it will check if there were commits made since the last push, if there are new commits, a new
    client object will be created and started. It will check if the repo is already authenticated with the server,
    if not it will initiate the auth_user() method in the Client object, if the authentication was succesfull,
    the remote auth field will be set as true. After that it will check if there is a repo id in the JSON file,
    if there is one it will use it, otherwise will ask the client, and the initiate the push_to_remote() method
    in the client object.
    """
    global REMOTE_AUTH
    global VERSIONED_FILE_NAMES
    global COMMIT
    global REMOTE_REPO_ID
    global REMOTE_COMMIT
    conf_parse()

    if COMMIT >= 1:
        if COMMIT > REMOTE_COMMIT:
            client = client_class.Client()
            if client.start_client():
                if not REMOTE_AUTH:
                    if client.auth_user():
                        print("Connection authorized")
                        conf_file_utils.update_remote_auth_status(True)
                    else:
                        return

                if int(REMOTE_REPO_ID) > -1:
                    if client.push_to_remote(VERSIONED_FILE_NAMES[0], REMOTE_REPO_ID):
                        conf_file_utils.set_remote_commit(COMMIT)
                        print("Pushed commits successfully.")
                    else:
                        conf_file_utils.update_remote_auth_status(False)

                else:
                    REMOTE_REPO_ID = input("Enter a repository ID: ")
                    conf_file_utils.set_repo_id(REMOTE_REPO_ID)
                    if client.push_to_remote(VERSIONED_FILE_NAMES[0], REMOTE_REPO_ID):
                        conf_file_utils.set_remote_commit(COMMIT)
                        print("Pushed commits successfully.")
                    else:
                        conf_file_utils.update_remote_auth_status(False)
                        conf_file_utils.set_repo_id(-1)

        elif COMMIT == REMOTE_COMMIT:
            print("The latest commit was already pushed.")
    else:
        print("No commmits to push.")
예제 #2
0
def handle_pull():
    """
    Handles the pull opcode. Creates a new Client object and initiates the pull method in client_class.py with the
    relevant arguments.
    """
    global REMOTE_REPO_ID
    global VERSIONED_FILE_NAMES
    conf_parse()

    client = client_class.Client()
    if client.start_client():
        if client.pull(VERSIONED_FILE_NAMES[0], REMOTE_REPO_ID):
            print("Pulled successfully.")
        else:
            print("Pull failed.")
예제 #3
0
def handle_clone():
    global REMOTE_AUTH
    global COMMIT

    conf_parse()
    if COMMIT == 0:
        client = client_class.Client()
        client.start_client()

        remote_repo_id = input("Enter a repository id: ")

        status, file_name = client.clone_repository(remote_repo_id)
        if status:
            conf_file_utils.set_repo_id(remote_repo_id)
            print(f"The remote repository with the id of {remote_repo_id} was cloned successfully.")
            handle_add(file_name)
    else:
        print("Can't clone a remote repository to a local repository that is not empty.")
예제 #4
0
def client_thread(conn):
    global clients
    driver_name = None
    while True:
        data = conn.recv(4096)
        if (data.decode() is not None):
            driver_name = data.decode()
            conn.send("Success".encode())
            break
    print("Connected by", driver_name)
    client = client_class.Client(driver_name, conn)
    clients.append(client)
    client.state_counts = load_state_counts(client)
    vector_size = load_vector_size(client)
    if (vector_size is not None):
        client.vector_size = vector_size
    main_thread = threading.Thread(target=receive_data, args=(
        client,
        conn,
    ))
    merging_thread = threading.Thread(target=merging_warning, args=(client, ))
    main_thread.start()
    merging_thread.start()
    server_loop(client, conn)
예제 #5
0
    cipher_rsa = PKCS1_OAEP.new(recipient_key)
    enc_session_key = cipher_rsa.encrypt(session_key)

    # Encrypt the data with the AES session key
    cipher_aes = AES.new(session_key, AES.MODE_EAX)
    ciphertext, tag = cipher_aes.encrypt_and_digest(message.encode("UTF-8"))
    encrypted_message = b"".join(
        [x for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext)])
    return encrypted_message


id_connections = []
# TODO: check everything and add remaining functions, test functionality
if __name__ == '__main__':
    client_information = []
    client_1 = cl.Client('config_1')
    client_2 = cl.Client('config_2')
    # print(client_1.id)
    # print(client_1.pubkey)
    # print(client_1.name)
    # print(client_1.prikey)

    register(client_1.id, client_1.name, client_1.pubkey)

    print(client_information)

    HOST = '127.0.0.1'
    PORT = 13370
    client_information = []

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)