예제 #1
0
파일: main.py 프로젝트: ArtPes/BitTorrent
    def run(self):
        tracker = False

        out_lck = threading.Lock()
        # connessione al database
        db = MongoConnection(out_lck)
        db.refresh()
        print(r"""
          ___                       ___           ___           ___           ___           ___           ___           ___           ___     
         /\  \          ___        /\  \         /\  \         /\  \         /\  \         /\  \         /\  \         /\__\         /\  \    
        /::\  \        /\  \       \:\  \        \:\  \       /::\  \       /::\  \       /::\  \       /::\  \       /::|  |        \:\  \   
       /:/\:\  \       \:\  \       \:\  \        \:\  \     /:/\:\  \     /:/\:\  \     /:/\:\  \     /:/\:\  \     /:|:|  |         \:\  \  
      /::\~\:\__\      /::\__\      /::\  \       /::\  \   /:/  \:\  \   /::\~\:\  \   /::\~\:\  \   /::\~\:\  \   /:/|:|  |__       /::\  \ 
     /:/\:\ \:|__|  __/:/\/__/     /:/\:\__\     /:/\:\__\ /:/__/ \:\__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/ |:| /\__\     /:/\:\__\
     \:\~\:\/:/  / /\/:/  /       /:/  \/__/    /:/  \/__/ \:\  \ /:/  / \/_|::\/:/  / \/_|::\/:/  / \:\~\:\ \/__/ \/__|:|/:/  /    /:/  \/__/
      \:\ \::/  /  \::/__/       /:/  /        /:/  /       \:\  /:/  /     |:|::/  /     |:|::/  /   \:\ \:\__\       |:/:/  /    /:/  /     
       \:\/:/  /    \:\__\       \/__/         \/__/         \:\/:/  /      |:|\/__/      |:|\/__/     \:\ \/__/       |::/  /     \/__/      
        \::/__/      \/__/                                    \::/  /       |:|  |        |:|  |        \:\__\         /:/  /                 
         ~~                                                    \/__/         \|__|         \|__|         \/__/         \/__/                  
        """)
        int_choice = loop_menu(out_lck, "Are you a tracker?", ["Yes", "No"])

        if int_choice == 1:
            output(out_lck, "YOU ARE A TRACKER")
            tracker = True
        else:
            output(out_lck, "YOU ARE A PEER")

        # Avvio il server in ascolto sulle porte 3000 e 6000
        server = multithread_server.Server(tracker)
        server.print_trigger.connect(mainwindow.print_on_main_panel)
        server.start()

        # se sono un tracker
        if not tracker:
            client = Client(config.my_ipv4, config.my_ipv6,
                            int(config.my_port), config.track_ipv4,
                            config.track_ipv6, config.track_port, db, out_lck,
                            self.print_trigger, self.download_trigger,
                            self.download_progress_trigger)

            while client.session_id is None:
                int_option = loop_menu(
                    out_lck,
                    "Select one of the following options ('e' to exit)",
                    ["Login", "Set parallel downloads", "Set part length"])
                if int_option == 1:
                    client.login()
                    if client.session_id == '0000000000000000' or client.session_id == '' or client.session_id is None:
                        client.session_id = None
                    else:
                        while True:
                            int_option = loop_menu(
                                out_lck,
                                "Select one of the following options ('e' to exit): ",
                                ["Add file", "Search file", "Logout"])
                            if int_option == 1:
                                # scelgo un file dalla cartella e lo aggiungo al tracker
                                client.share()
                            elif int_option == 2:
                                # creo una query e la invio al tracker
                                client.look()
                            elif int_option == 3:
                                client.logout()
                                if client.session_id == None:
                                    output(out_lck, 'Logout completed.')
                                else:
                                    output(out_lck, "Try again\n")
                            else:
                                output(
                                    out_lck, "Option " + str(int_option) +
                                    " not available")
                elif int_option == 2:
                    client.parallel_downloads = loop_int_input(
                        out_lck, "Insert the number of parallel downloads: ")

                elif int_option == 3:

                    client.part_size = loop_int_input(
                        out_lck, "Insert the new part size: ")
예제 #2
0
def start_ftp_client():
    ftpclient = Client('127.0.0.1', 2121)
    ftpclient.login('admin', 'admin')
    CLI = ClientCLI(ftpclient)
    CLI.start_client_cli()
    ftpclient.logout()
예제 #3
0
파일: main.py 프로젝트: ArtPes/Kazaa
    def run(self):
        supernode_mode = False

        out_lck = threading.Lock()
        db = MongoConnection(out_lck)
        db.refreshDB()

        print("  _  __  ")
        print(" | |/ /     ")
        print(" | ' /    __ _   ____   __ _    __ _ ")
        print(" |  <    / _` | |_  /  / _` |  / _` |")
        print(" | . \  | (_| |  / /  | (_| | | (_| |")
        print(" |_|\_\  \__,_| /___|  \__,_|  \__,_|")
        print("")

        # inserisco un vicino che può essere un supernodo
        add_neighbor(out_lck, db)

        output(out_lck, "Are you a supernode?")
        output(out_lck, "1: YES")
        output(out_lck, "2: NO")

        int_choice = None
        while int_choice is None:
            try:
                option = input()  # Input da tastiera
            except SyntaxError:
                option = None

            if option is None:
                output(out_lck, "Please select an option")
            else:
                try:
                    int_choice = int(option)
                except ValueError:
                    output(out_lck, "A choice is required")

        if int_choice == 1:
            output(out_lck, "YOU ARE A SUPERNODE")
            supernode_mode = True
        else:
            output(out_lck, "YOU ARE A PEER!")

        # Avvio il server in ascolto sulle porte 80 e 6000
        server = multithread_server.Server(supernode_mode)
        server.print_trigger.connect(mainwindow.print_on_main_panel)
        server.start()

        client = Client(config.my_ipv4, config.my_ipv6, int(config.my_port),
                        None, None, None, config.ttl, db, out_lck,
                        self.print_trigger)

        if supernode_mode:
            while client.session_id is None:
                #print_menu_top(out_lck)
                output(out_lck,
                       "Select one of the following options ('e' to exit): ")
                output(out_lck,
                       "1: Search supernodes                               ")
                output(out_lck,
                       "2: View supernodes                                 ")
                output(out_lck,
                       "3: Log in (to self)                                ")

                int_option = None
                try:
                    option = input()
                except SyntaxError:
                    option = None

                if option is None:
                    output(out_lck, "Please select an option")
                elif option == 'e':
                    output(out_lck, "Bye bye")
                    server.stop()
                    sys.exit()  # Interrompo l'esecuzione
                else:
                    try:
                        int_option = int(option)
                    except ValueError:
                        output(out_lck, "A number is required")
                    else:
                        if int_option == 1:
                            # ricerca supernodi e salvataggio nel db
                            client.search_supe()
                        elif int_option == 2:
                            output(out_lck, "Supernodes available:")
                            supernodes = db.get_supernodes()
                            for idx, sn in enumerate(supernodes):
                                output(
                                    out_lck, sn['ipv4'] + "\t" + sn['ipv6'] +
                                    "\t" + sn['port'])
                        elif int_option == 3:
                            client.dir_ipv4 = "127.0.0.1"
                            client.dir_ipv6 = "::1"
                            client.dir_port = 3000
                            client.login()

                            while client.session_id is not None:
                                # print_menu_top(out_lck)
                                output(
                                    out_lck,
                                    "1: Add file (to self)                              "
                                )
                                output(
                                    out_lck,
                                    "2: Delete file (from self)                         "
                                )
                                output(
                                    out_lck,
                                    "3: Search file                                     "
                                )
                                output(
                                    out_lck,
                                    "4: Log out                                         "
                                )
                                # print_menu_bottom(out_lck)

                                int_option = None
                                try:
                                    option = input()
                                except SyntaxError:
                                    option = None

                                if option is None:
                                    output(out_lck, "Please select an option")
                                else:
                                    try:
                                        int_option = int(option)
                                    except ValueError:
                                        output(out_lck, "A number is required")
                                    else:
                                        if int_option == 1:
                                            # scelgo un file dalla cartella e lo aggiungo alla directory
                                            client.share()
                                        elif int_option == 2:
                                            # scelgo un file dalla directory (tra i miei) e lo rimuovo
                                            client.remove()
                                        elif int_option == 3:
                                            # creo una query e la invio agli altri supernodi
                                            client.search_file()
                                        elif int_option == 4:
                                            client.logout()
                                        else:
                                            output(
                                                out_lck,
                                                "Option " + str(int_option) +
                                                " not available")

                        else:
                            output(
                                out_lck,
                                "Option " + str(int_option) + " not available")
        else:
            while client.session_id is None:
                # print_menu_top(out_lck)
                output(out_lck,
                       "Select one of the following options ('e' to exit): ")
                output(out_lck,
                       "1: Search supernodes                               ")
                output(out_lck,
                       "2: View supernodes                                 ")
                output(out_lck,
                       "3: Select supernode and log in                     ")

                int_option = None
                try:
                    option = input()
                except SyntaxError:
                    option = None

                if option is None:
                    output(out_lck, "Please select an option")
                elif option == 'e':
                    output(out_lck, "Bye bye")
                    server.stop()
                    sys.exit()  # Interrompo l'esecuzione
                else:
                    try:
                        int_option = int(option)
                    except ValueError:
                        output(out_lck, "A number is required")
                    else:
                        if int_option == 1:
                            # ricerca supernodi e salvataggio nel db
                            client.search_supe()
                        elif int_option == 2:
                            output(out_lck, "Supernodes available:")
                            supernodes = db.get_supernodes()
                            for idx, sn in enumerate(supernodes):
                                output(
                                    out_lck, sn['ipv4'] + "\t" + sn['ipv6'] +
                                    "\t" + sn['port'])
                        elif int_option == 3:
                            output(
                                out_lck,
                                "Select a supernode to log in ('r' to reload, 'e' to exit):"
                            )

                            supernodes = db.get_supernodes()
                            for idx, sn in enumerate(supernodes):
                                output(
                                    out_lck,
                                    str(idx) + ":\t" + sn['ipv4'] + "\t" +
                                    sn['ipv6'] + "\t" + sn['port'])

                            int_option = None
                            while int_option is None:
                                try:
                                    option = input()
                                except SyntaxError:
                                    option = None

                                if option is None:
                                    output(out_lck, "Please select an option")
                                elif option == 'r':
                                    supernodes = db.get_supernodes()
                                    for idx, sn in enumerate(supernodes):
                                        output(
                                            out_lck,
                                            str(idx) + ":\t" + sn['ipv4'] +
                                            "\t" + sn['ipv6'] + "\t" +
                                            sn['port'])
                                elif option == 'e':
                                    break
                                else:
                                    try:
                                        int_option = int(option)
                                    except ValueError:
                                        output(out_lck, "A number is required")
                                    else:
                                        supernodes = db.get_supernodes()
                                        for idx, sn in enumerate(supernodes):
                                            if idx == int_option:
                                                client.dir_ipv4 = sn['ipv4']
                                                client.dir_ipv6 = sn['ipv6']
                                                client.dir_port = 3000  # porta delle directory

                                        # faccio il login
                                        client.login()

            while client.session_id is not None:
                #print_menu_top(out_lck)
                output(out_lck,
                       "Select one of the following options:               ")
                output(out_lck,
                       "1: Add file                                        ")
                output(out_lck,
                       "2: Delete file                                     ")
                output(out_lck,
                       "3: Search file                                     ")
                output(out_lck,
                       "4: Log out                                         ")
                #print_menu_bottom(out_lck)

                int_option = None
                try:
                    option = input()
                except SyntaxError:
                    option = None

                if option is None:
                    output(out_lck, "Please select an option")
                else:
                    try:
                        int_option = int(option)
                    except ValueError:
                        output(out_lck, "A number is required")
                    else:
                        if int_option == 1:
                            # scelgo un file dalla cartella e lo aggiungo alla directory
                            client.share()
                        elif int_option == 2:
                            # scelgo un file dalla directory (tra i miei) e lo rimuovo
                            client.remove()
                        elif int_option == 3:
                            # creo una query e la invio agli altri supernodi
                            client.search_file()
                        elif int_option == 4:
                            output(out_lck, "Logging out...")
                            client.logout()
                        else:
                            output(
                                out_lck,
                                "Option " + str(int_option) + " not available")
예제 #4
0
    def run(self):
        tracker = False

        out_lck = threading.Lock()
        db = MongoConnection(out_lck)

        output(out_lck, "\nAre you a tracker?")
        output(out_lck, "1: YES")
        output(out_lck, "2: NO")

        int_choice = None
        while int_choice is None:
            try:
                option = raw_input()  # Input da tastiera
            except SyntaxError:
                option = None

            if option is None:
                output(out_lck, "Please select an option")
            else:
                try:
                    int_choice = int(option)
                except ValueError:
                    output(out_lck, "A choice is required")

        if int_choice == 1:
            output(out_lck, "YOU ARE A TRACKER")
            tracker = True
        else:
            output(out_lck, "YOU ARE A PEER!")

        # Avvio il server in ascolto sulle porte 3000 e 6000
        server = multithread_server.Server(tracker)
        server.print_trigger.connect(mainwindow.print_on_main_panel)
        server.start()

        if not tracker:
            client = Client(config.my_ipv4, config.my_ipv6,
                            int(config.my_port), config.track_ipv4,
                            config.track_ipv6, config.track_port, db, out_lck,
                            self.print_trigger, self.download_trigger,
                            self.download_progress_trigger)

            while client.session_id is None:
                # print_menu_top(out_lck)
                output(
                    out_lck,
                    "\nSelect one of the following options ('e' to exit): ")
                output(out_lck,
                       "1: Log in                                          ")
                output(out_lck,
                       "2: Set parallel downloads                          ")
                output(out_lck,
                       "3: Set part length                                 ")

                int_option = None
                try:
                    option = raw_input()
                except SyntaxError:
                    option = None

                if option is None:
                    output(out_lck, "Please select an option")
                elif option == 'e':
                    output(out_lck, "Bye bye")
                    server.stop()
                    sys.exit()  # Interrompo l'esecuzione
                else:
                    try:
                        int_option = int(option)
                    except ValueError:
                        output(out_lck, "A number is required")
                    else:
                        if int_option == 1:

                            client.login()

                            while client.session_id is not None:
                                output(
                                    out_lck,
                                    "\nSelect one of the following options ('e' to exit): "
                                )
                                output(
                                    out_lck,
                                    "1: Add file                                        "
                                )
                                output(
                                    out_lck,
                                    "2: Search file                                     "
                                )
                                output(
                                    out_lck,
                                    "3: Log out                                         "
                                )

                                int_option = None
                                try:
                                    option = raw_input()
                                except SyntaxError:
                                    option = None

                                if option is None:
                                    output(out_lck, "Please select an option")
                                else:
                                    try:
                                        int_option = int(option)
                                    except ValueError:
                                        output(out_lck, "A number is required")
                                    else:
                                        if int_option == 1:
                                            # scelgo un file dalla cartella e lo aggiungo al tracker
                                            client.share()
                                        elif int_option == 2:
                                            # creo una query e la invio al tracker
                                            client.look()
                                        elif int_option == 3:
                                            client.logout()
                                            #output(out_lck, 'Logout completed')
                                        else:
                                            output(
                                                out_lck,
                                                "Option " + str(int_option) +
                                                " not available")
                        elif int_option == 2:
                            output(
                                out_lck,
                                "Insert the number of parallel downloads: ")

                            try:
                                option = raw_input()
                            except SyntaxError:
                                option = None

                            if option is None:
                                output(out_lck, "Please insert a number")
                            else:
                                try:
                                    int_option = int(option)
                                except ValueError:
                                    output(out_lck, "A number is required")
                                else:
                                    client.parallel_downloads = int_option
                                    output(
                                        out_lck,
                                        "Parallel downloads set to: " +
                                        str(int_option))

                        elif int_option == 3:
                            output(out_lck, "Insert the new part size: ")

                            try:
                                option = raw_input()
                            except SyntaxError:
                                option = None

                            if option is None:
                                output(out_lck, "Please insert a number")
                            else:
                                try:
                                    int_option = int(option)
                                except ValueError:
                                    output(out_lck, "A number is required")
                                else:
                                    client.part_size = int_option
                                    output(
                                        out_lck, "Parts size set to: " +
                                        str(int_option))
                        else:
                            output(
                                out_lck,
                                "Option " + str(int_option) + " not available")