# Buggy code
def register(self, session, session_lock):
    assert isInIOThread()

    self.session = session
    self.session_lock = session_lock

    self.tracker_manager = TrackerManager(self.session)

    # On Mac, we bundle the root certificate for the SSL validation since Twisted is not using the root
    # certificates provided by the system trust store.
    if sys.platform == "darwin":
        os.environ["SSL_CERT_FILE"] = os.path.join(get_lib_path(), "root_certs_mac.pem")

    if self.session.config.get_video_server_enabled():
        self.video_server = VideoServer(
            self.session.config.get_video_server_port(), self.session
        )
        self.video_server.start()

    # IPv8
    if self.session.config.get_ipv8_enabled():
        from ipv8.configuration import get_default_configuration

        ipv8_config = get_default_configuration()
        ipv8_config["port"] = self.session.config.get_ipv8_port()
        ipv8_config["address"] = self.session.config.get_ipv8_address()
        ipv8_config["overlays"] = []
        ipv8_config["keys"] = []  # We load the keys ourselves

        if self.session.config.get_ipv8_bootstrap_override():
            import ipv8.community as community_file

            community_file._DEFAULT_ADDRESSES = [
                self.session.config.get_ipv8_bootstrap_override()
            ]
            community_file._DNS_ADDRESSES = []

        self.ipv8 = IPv8(
            ipv8_config, enable_statistics=self.session.config.get_ipv8_statistics()
        )

        self.session.config.set_anon_proxy_settings(
            2,
            (
                "127.0.0.1",
                self.session.config.get_tunnel_community_socks5_listen_ports(),
            ),
        )
    self.init()


# Traceback (ValueError)
ERROR   1576450617.34                 community:695  (TriblerTunnelCommunity)  Exception occurred while handling packet!
Traceback (most recent call last):
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 692, in on_packet_from_circuit
self.decode_map_private[msg_id](source_address, data, circuit_id)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 76, in wrapper
return inner_wrapper(self, source_address, data)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/lazy_community.py", line 104, in wrapper
return func(self, source_address, *unpacked)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 74, in inner_wrapper
return func(inner_self, inner_source_address, *combo)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 774, in on_created
self._ours_on_created_extended(circuit, payload)
File "/home/tribler/tribler/Tribler/community/triblertunnel/community.py", line 447, in _ours_on_created_extended
super(TriblerTunnelCommunity, self)._ours_on_created_extended(circuit, payload)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 551, in _ours_on_created_extended
payload.auth, hop.public_key.key.pk)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/tunnelcrypto.py", line 51, in verify_and_generate_shared_secret
libnacl.crypto_auth_verify(auth, dh_received, shared_secret)
File "/home/tribler/.local/lib/python3.7/site-packages/libnacl/__init__.py", line 887, in crypto_auth_verify
raise ValueError('Invalid secret key')
ValueError: Invalid secret key

# Fixed code
def register(self, session, session_lock):
    assert isInIOThread()

    self.session = session
    if not self.session.trustchain_keypair:
        self.session.init_keypair()
    self.session_lock = session_lock

    self.tracker_manager = TrackerManager(self.session)

    # On Mac, we bundle the root certificate for the SSL validation since Twisted is not using the root
    # certificates provided by the system trust store.
    if sys.platform == "darwin":
        os.environ["SSL_CERT_FILE"] = os.path.join(get_lib_path(), "root_certs_mac.pem")

    if self.session.config.get_video_server_enabled():
        self.video_server = VideoServer(
            self.session.config.get_video_server_port(), self.session
        )
        self.video_server.start()

    # IPv8
    if self.session.config.get_ipv8_enabled():
        from ipv8.configuration import get_default_configuration

        ipv8_config = get_default_configuration()
        ipv8_config["port"] = self.session.config.get_ipv8_port()
        ipv8_config["address"] = self.session.config.get_ipv8_address()
        ipv8_config["overlays"] = []
        ipv8_config["keys"] = []  # We load the keys ourselves

        if self.session.config.get_ipv8_bootstrap_override():
            import ipv8.community as community_file

            community_file._DEFAULT_ADDRESSES = [
                self.session.config.get_ipv8_bootstrap_override()
            ]
            community_file._DNS_ADDRESSES = []

        self.ipv8 = IPv8(
            ipv8_config, enable_statistics=self.session.config.get_ipv8_statistics()
        )

        self.session.config.set_anon_proxy_settings(
            2,
            (
                "127.0.0.1",
                self.session.config.get_tunnel_community_socks5_listen_ports(),
            ),
        )
    self.init()