# Buggy code
def create_introduction_point(self, info_hash, amount=1):
    # Create a separate key per infohash
    self.find_download(info_hash).add_peer(("1.1.1.1", 1024))

    if info_hash not in self.session_keys:
        self.session_keys[info_hash] = self.crypto.generate_key("curve25519")

    def callback(circuit):
        # We got a circuit, now let's create an introduction point
        circuit_id = circuit.circuit_id
        self.my_intro_points[circuit_id].append((info_hash))

        cache = self.request_cache.add(IPRequestCache(self, circuit))
        self.send_cell(
            [Candidate(circuit.first_hop, False)],
            "establish-intro",
            (circuit_id, cache.number, info_hash),
        )
        self.tunnel_logger.info("Established introduction tunnel %s", circuit_id)
        if self.notifier:
            self.notifier.notify(
                NTFY_TUNNEL, NTFY_IP_CREATED, info_hash.encode("hex")[:6], circuit_id
            )

    for _ in range(amount):
        # Create a circuit to the introduction point + 1 hop, to prevent the introduction
        # point from knowing what the seeder is seeding
        circuit_id = self.create_circuit(
            self.hops[info_hash] + 1, CIRCUIT_TYPE_IP, callback, info_hash=info_hash
        )
        self.infohash_ip_circuits[info_hash].append((circuit_id, time.time()))


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 92, in on_read_data
RuntimeError: Unhandled Error
Traceback (most recent call last):
File "lib\multiprocessing\process.py", line 114, in run

File "TriblerGUI\core_manager.py", line 63, in start_tribler_core

File "lib\site-packages\twisted\internet\base.py", line 1195, in run

File "lib\site-packages\twisted\internet\base.py", line 1204, in mainLoop

--- <exception caught here> ---
File "lib\site-packages\twisted\internet\base.py", line 798, in runUntilCurrent

File "Tribler\dispersy\endpoint.py", line 253, in dispersythread_data_came_in

File "Tribler\dispersy\dispersy.py", line 1488, in on_incoming_packets

File "Tribler\dispersy\dispersy.py", line 685, in get_community

File "Tribler\dispersy\community.py", line 226, in init_community

File "Tribler\community\tunnel\tunnel_community.py", line 316, in initialize

File "Tribler\community\tunnel\Socks5\server.py", line 309, in start

File "lib\site-packages\twisted\internet\posixbase.py", line 478, in listenTCP

File "lib\site-packages\twisted\internet\tcp.py", line 983, in startListening

twisted.internet.error.CannotListenError: Couldn't listen on any:55661: [Errno 10048] Elk socketadres (protocol/netwerkadres/poort) kan normaal slechts n keer worden gebruikt.

# Fixed code
def create_introduction_point(self, info_hash, amount=1):
    download = self.find_download(info_hash)
    if download:
        download.add_peer(("1.1.1.1", 1024))
    else:
        self.tunnel_logger.error(
            "When creating introduction point: could not find download!"
        )
        return

    # Create a separate key per infohash
    if info_hash not in self.session_keys:
        self.session_keys[info_hash] = self.crypto.generate_key("curve25519")

    def callback(circuit):
        # We got a circuit, now let's create an introduction point
        circuit_id = circuit.circuit_id
        self.my_intro_points[circuit_id].append((info_hash))

        cache = self.request_cache.add(IPRequestCache(self, circuit))
        self.send_cell(
            [Candidate(circuit.first_hop, False)],
            "establish-intro",
            (circuit_id, cache.number, info_hash),
        )
        self.tunnel_logger.info("Established introduction tunnel %s", circuit_id)
        if self.notifier:
            self.notifier.notify(
                NTFY_TUNNEL, NTFY_IP_CREATED, info_hash.encode("hex")[:6], circuit_id
            )

    for _ in range(amount):
        # Create a circuit to the introduction point + 1 hop, to prevent the introduction
        # point from knowing what the seeder is seeding
        circuit_id = self.create_circuit(
            self.hops[info_hash] + 1, CIRCUIT_TYPE_IP, callback, info_hash=info_hash
        )
        self.infohash_ip_circuits[info_hash].append((circuit_id, time.time()))