def update_servers(self, ed2k=None, kad=None):
     if ed2k:
         tags = [(codes.EC_TAG_SERVERS_UPDATE_URL, unicode(ed2k))]
         self.communicate(
             ECPacket((codes.EC_OP_SERVER_UPDATE_FROM_URL, tags)))
     if kad:
         tags = [(codes.EC_TAG_KADEMLIA_UPDATE_URL, unicode(kad))]
         self.communicate(ECPacket((codes.EC_OP_KAD_UPDATE_FROM_URL, tags)))
    def get_shared(self):
        """Get list of shared files.

        Returns a list of shared files. The data for a file is stored in a
         dictionary with the following keys:
        - "name": file name
        - "size": size in Bytes
        - "link": eD2k link to the file
        - "hash": file hash stored in 16 Byte
        - "prio": upload priority, Auto is prefixed by 1, e.g. 12 is Auto (High)
            - 4: Very Low
            - 0: Low
            - 1: Normal
            - 2: High
            - 3: Very High
            - 6: Release
        - "aich": file's AICH hash (see: http://wiki.amule.org/index.php/AICH)
        - "part_status": unknown
        - "uploaded": Bytes uploaded during the current session
        - "uploaded_total": total Bytes uploaded
        - "requests": number of requests for this file during the current session
        - "requests_total": total number of requests for this file
        - "accepted": number of accepted requests for this file during the current session
        - "accepted_total": total number of accepted requests for this file
        """
        data = ECPacket((codes.EC_OP_GET_SHARED_FILES, []))
        response = self.communicate(data)
        return response[1]
    def get_status(self):
        """Get status information from remote core.

        Returns a dictionary with the following keys:
        - "ul_speed": upload speed in Bytes/s
        - "dl_speed": download speed in Bytes/s
        - "ul_limit": upload limit, 0 is unlimited
        - "dl_limit": download limit, 0 is unlimited
        - "queue_len": number of clients waiting in the upload queue
        - "src_count": number of download sources
        - "ed2k_users": users in the eD2k network
        - "kad_users": users in the kademlia network
        - "ed2k_files": files in the eD2k network
        - "kad_files": files in the kademlia network
        - "connstate": connection status, dictionary with the following keys:
            - "ed2k": ed2k network status. possible values: "connected", "connecting", "Not connected"
            - "kad": kademlia network status. possible values: "connected", "Not connected", "Not running"
            - "server_addr": server address in ip:port format
            - "ed2k_id": identification number for the ed2k network
            - "client_id": identification number for the kademlia network
            - "id": connection status. possible values: "LowID", "HighID", ""
            - "kad_firewall": kademlia status. possible values: "ok", "firewalled", ""

        """
        data = ECPacket((codes.EC_OP_STAT_REQ, []))
        response = self.communicate(data)
        # structure: (op['stats'], [(tag['stats_ul_speed'], 0), (tag['stats_dl_speed'], 0), (tag['stats_ul_speed_limit'], 0), (tag['stats_dl_speed_limit'], 0), (tag['stats_ul_queue_len'], 0), (tag['stats_total_src_count'], 0), (tag['stats_ed2k_users'], 3270680), (tag['stats_kad_users'], 0), (tag['stats_ed2k_files'], 279482794), (tag['stats_kad_files'], 0), (tag['connstate'], ((connstate, [subtags])))])
        return response[1]
 def stop_paused_downloads(self):
     """
     Stops all paused download
     """
     tags = [(codes.EC_TAG_PARTFILE, str(download["partfile_hash"]))
             for download in self.show_dl().itervalues()
             if download["partfile_status"] == 7]
     data = ECPacket((codes.EC_OP_PARTFILE_STOP, tags))
     self.communicate(data)
    def add_link(self, link):
        """Add link to aMule core.

        Returns True when the link was added and False if the link is invalid.
        """
        data = ECPacket(
            (codes.EC_OP_ADD_LINK, [(codes.EC_TAG_STRING, unicode(link))]))
        response = self.communicate(data, False)
        return response[0] == codes.EC_OP_NOOP
    def disconnect(self):
        """Disconnect remote core from networks.

        Returns a tuple with a boolean indicating success and a list of strings
         with status messages."""
        # (op['noop'], [])
        # (op['strings'], [(tag['string'], u'Disconnected from eD2k.'), (tag['string'], u'Disconnected from Kad.')])
        data = ECPacket((codes.EC_OP_DISCONNECT, []))
        opcode, tags = self.communicate(data)
        return (opcode == codes.EC_OP_STRINGS, tags.values())
    def shutdown(self):
        '''
        Shutdown remote core

        For consistent behaviour between official EC client, you should
        call stop_paused_downloads method prior to this. Otherwise
        paused downloads will be resumed at next session startup.
        '''
        data = ECPacket((codes.EC_OP_SHUTDOWN, []))
        self.send(data)
    def connect(self):
        '''
        Connect remote core to enabled networks in config file.

        Returns a tuple with a boolean indicating success and a list of strings
        with status messages.
        '''
        data = ECPacket((codes.EC_OP_CONNECT, []))
        opcode, tags = self.communicate(data, False)
        # (op['failed'], [(tag['string'], u'All networks are disabled.')])
        # (op['strings'], [(tag['string'], u'Connecting to eD2k...'), (tag['string'], u'Connecting to Kad...')])
        return (opcode != codes.EC_OP_FAILED, tags.values())
    def search_results(self):
        """Get results of last search.

        Returns a list of search results. The data for a search result is
         stored in a dictionary with the following keys:
        - "name": file name
        - "size": size in Bytes
        - "hash": file hash stored in 16 Byte
        - "sources": number of clients sharing the file
        - "sources_complete": number of clients sharing all parts of the file
        """
        data = ECPacket((codes.EC_OP_SEARCH_RESULTS, []))
        response = self.communicate(data)
        return response[1]
Beispiel #10
0
    def get_connstate(self):
        """Get connection status information from remore core.

        Returns a dictionary with the following keys:
        - "ed2k": ed2k network status. possible values: "connected", "connecting", "Not connected"
        - "kad": kademlia network status. possible values: "connected", "Not connected", "Not running"
        - "server_addr": server address in ip:port format
        - "ed2k_id": identification number for the ed2k network
        - "client_id": identification number for the kademlia network
        - "id": connection status. possible values: "LowID", "HighID", ""
        - "kad_firewall": kademlia status. possible values: "ok", "firewalled", ""
        """
        data = ECPacket((codes.EC_OP_GET_CONNSTATE,
                         [(codes.EC_TAG_DETAIL_LEVEL, codes.EC_DETAIL_CMD)]))
        opcode, tags = self.communicate(data)
        # structure: (op['misc_data'], [(tag['connstate'], (connstate, [subtags]))])
        connstate = tags['connstate'][0]
        status = tags['connstate'][1]
        if (connstate & 0x01):  # ed2k connected
            status["ed2k"] = "connected"
            highest_lowid_ed2k_kad = 16777216
            status["id"] = "HighID" if (
                status["client_id"] > highest_lowid_ed2k_kad) else "LowID"
        elif (connstate & 0x02):  # ed2k connecting
            status["ed2k"] = "connecting"
        else:
            status["ed2k"] = "Not connected"
        if (connstate & 0x10):  # kad running
            if (connstate & 0x04):  # kad connected
                status["kad"] = "connected"
                if (connstate & 0x08):  # kad firewalled
                    status["kad_firewall"] = "firewalled"
                else:
                    status["kad_firewall"] = "ok"
            else:
                status["kad"] = "Not connected"
        else:
            status["kad"] = "Not running"
        return status
Beispiel #11
0
    def search(self, type, keywords):
        """Start a search.

        Returns a tuple consisting of a boolean value indicating success and
        a string with aMule's answer.

        Type is one of local (0x00), global (0x01) and kad (0x02), denoting the
         scope of the search.
        "local" queries only the connected server, "global" all servers in the
         server list and "kad" starts a search in the kad network.
        Usage of the helper functions "search_local", "search_global" and
         "search_kad" is recommended.

        Keywords is a string of words for which to search.
        """
        packet = (codes.EC_OP_SEARCH_START, [
            (codes.EC_TAG_SEARCH_TYPE, (type, [(codes.EC_TAG_SEARCH_NAME,
                                                unicode(keywords))]))
        ])
        data = ECPacket(packet)
        opcode, tags = self.communicate(data)
        not_connected = "progress" in tags["search_status"]
        return (not_connected, tags)
Beispiel #12
0
 def search_progress(self):
     """Doesn't work correctly, don't use it.
     """
     data = ECPacket((codes.EC_OP_SEARCH_PROGRESS, []))
     response = self.communicate(data)
     return response
Beispiel #13
0
 def reload_ipfilter(self):
     """Reload ipfilter on remote core."""
     data = ECPacket((codes.EC_OP_IPFILTER_RELOAD, []))
     response = self.communicate(data)
Beispiel #14
0
 def get_short_status(self):
     data = ECPacket((codes.EC_OP_STAT_REQ, codes.EC_DETAIL_CMD, []))
     response = self.communicate(data)
     return response[1]
Beispiel #15
0
 def server_list(self):
     data = ECPacket((codes.EC_OP_GET_SERVER_LIST, []))
     response = self.communicate(data, False)
     return response[1]
Beispiel #16
0
 def pause_hash(self, dhash):
     data = ECPacket((codes.EC_OP_PARTFILE_PAUSE, [(codes.EC_TAG_PARTFILE,
                                                    str(dhash))]))
     self.communicate(data)
Beispiel #17
0
 def set_directory_incoming(self, path):
     data = ECPacket(
         (codes.EC_OP_SET_PREFERENCES, [(codes.EC_TAG_DIRECTORIES_INCOMING,
                                         unicode(path))]))
     self.communicate(data)
Beispiel #18
0
    def connect_kad(self):
        """Connect remote core to kademlia network.

        Returns a boolean indicating success."""
        data = ECPacket((codes.EC_OP_KAD_START, []))
        self.communicate(data)
Beispiel #19
0
    def connect_ed2k(self):
        """Connect remote core to eD2k network.

        Returns a boolean indicating success."""
        data = ECPacket((codes.EC_OP_SERVER_CONNECT, []))
        self.communicate(data)
Beispiel #20
0
 def resume_all(self):
     tags = [(codes.EC_TAG_PARTFILE, str(v["partfile_hash"]))
             for v in self.show_dl().itervalues()]
     data = ECPacket((codes.EC_OP_PARTFILE_RESUME, tags))
     self.communicate(data)
Beispiel #21
0
 def show_ul(self):
     data = ECPacket((codes.EC_OP_GET_ULOAD_QUEUE, []))
     response = self.communicate(data, False)
     return response[1].get("partfile", {})
Beispiel #22
0
 def resume_hash(self, dhash):
     data = ECPacket((codes.EC_OP_PARTFILE_RESUME, [(codes.EC_TAG_PARTFILE,
                                                     str(dhash))]))
     self.communicate(data)
Beispiel #23
0
 def disconnect_server(self):
     """Disconnect remote core from eD2k network."""
     data = ECPacket((codes.EC_OP_SERVER_DISCONNECT, []))
     response = self.communicate(data)
Beispiel #24
0
 def remove_hash(self, dhash):
     data = ECPacket((codes.EC_OP_PARTFILE_DELETE, [(codes.EC_TAG_PARTFILE,
                                                     str(dhash))]))
     response = self.communicate(data, False)
     return response[0] == codes.EC_OP_NOOP
Beispiel #25
0
 def disconnect_kad(self):
     """Disconnect remote core from kademlia network."""
     data = ECPacket((codes.EC_OP_KAD_STOP, []))
     response = self.communicate(data)
Beispiel #26
0
 def show_shared(self):
     data = ECPacket((codes.EC_OP_GET_SHARED_FILES, []))
     response = self.communicate(data, False)
     return response[1].get("knownfile", {})
Beispiel #27
0
 def reload_shared(self):
     """Reload shared files on remote core."""
     data = ECPacket((codes.EC_OP_SHAREDFILES_RELOAD, []))
     response = self.communicate(data)