Пример #1
0
    def new_node(self,
                 port: int,
                 parent_ab: AddressBook = None) -> AddressBook:

        new_node_pub, new_node_priv = generate_contact_key_pair()

        parent_id = "" if parent_ab is None else parent_ab.self_contact.id
        contacts = [] if parent_ab is None else parent_ab.contacts + [
            parent_ab.self_contact
        ]

        new_node_contact = Contact(host="127.0.0.1",
                                   id=generate_contact_id(parent_id),
                                   port=port,
                                   public_key=new_node_pub)

        new_node_ab = AddressBook(
            self_contact=new_node_contact,
            private_key=new_node_priv,
            contacts=contacts,
            receiver_notify_interval=self.receiver_notify_interval,
            contact_restore_timeout=self.contact_restore_timeout,
            inactive_nodes_ping_interval=self.inactive_nodes_ping_interval,
        )

        if parent_ab is not None:

            parent_ab.create_new_distributed_contact(new_node_contact)

        return new_node_ab
Пример #2
0
 def create_new_address_book(self, provider, child_index):
     """
     This method creates a new AddressBook to pass to the child. It sets the child's contact as self_contact
     and adds the parent's contact in the contacts list.
     """
     child_pub, child_priv = messaging.generate_contact_key_pair()
     child_id = messaging.generate_contact_id(
         self.address_book.self_contact.id)
     ip = self.get_node_ip(provider, child_index)
     child_contact = messaging.Contact(child_id, ip, self.port, child_pub)
     new_address_book = address_book.AddressBook(child_contact,
                                                 self.address_book.contacts,
                                                 child_priv)
     new_address_book.contacts.append(self.address_book.self_contact)
     # TODO : Add child's contact to parent's addressbook?
     return new_address_book
Пример #3
0
 def init_address_book(self, parent_id: str = ""):
     node_id = messaging.generate_contact_id(parent_id)
     ip = get('https://api.ipify.org').text
     self_contact = messaging.Contact(node_id, ip, self.port, self.node_pub)
     self.address_book = address_book.AddressBook(self_contact,
                                                  self.node_priv)
Пример #4
0
 def init_address_book(self, parent_id: str = ""):
     node_id = messaging.generate_contact_id(parent_id)
     index = core.get_node_index()
     ip = self.get_node_ip(str(self.self_state.provider).lower(), index)
     self_contact = messaging.Contact(node_id, ip, self.port, self.node_pub)
     return address_book.AddressBook(self_contact, self.node_priv)