Ejemplo n.º 1
0
    def _on_packet_action(self, packet):
        """ Function that we'll execute to examine the packets we're receiving 
        The proxy will only receive packets from legacy devices, so he can keep his own database 
        of devices """

        # Get the mac address
        mac_address = packet[Ether].src
        # Añadir comprobación de si está en la red

        # If the mac address is not in macs but the ip is in our network
        # that means that the sender is one of the legacy devices
        if packet[IP].src in self.network and mac_address not in self.macs:
            packet.summary()
            # Add it to our mac address set
            self.macs.add(mac_address)
            print('Added', mac_address, 'to the list of addresses')

            # Create a new account using mac as password
            account_num = self.w3.personal.newAccount(mac_address)
            ip_addr = packet[IP].src
            print('Cuenta del cliente', account_num)

            # Unlock account forever
            self.w3.personal.unlockAccount(account_num, mac_address, 0)
            print('Account unlocked')

            # Create a new client
            # Since the client won't even know that we're in an
            # ethereum environment, we have to set the proxy's w3 as the client's
            # so we can do transactions quickly
            new_client = Client(account=account_num,
                                w3=self.w3,
                                ip_address=ip_addr,
                                mac_address=mac_address)
            # Register the client
            print('Registering client with address:', account_num)
            print('Proxy address', self.account)
            print('Default Account:', new_client.w3.eth.defaultAccount)

            # Register the new client
            new_client.register()
            print('Registered new client')

            # Set the dictionary so we relate mac_addresses to the clients' interface
            self.clients[mac_address] = new_client
            print('New dictionary:', self.clients)

            # Add it to the database
            with self.conn as conn:
                command = """
                INSERT INTO devices(account, mac_address, ip_address) values ('{}','{}','{}')
                """.format(account_num, mac_address, ip_addr)
                conn.execute(command)
Ejemplo n.º 2
0
def main():

    print('Instantiating ContractInterface')
    client = ContractInterface()

    print('Registering...')
    client.register()
    '''
    print("Transfering 50 IoT's")
    client.transfer(client.w3.eth.accounts[2], 50)'''

    # Request 5 GB. This one should be accepted
    print('Request 5 GB (even)')
    client.request_storage(5000)

    input('Press enter for freeing')
    id, _ = client.remoteStorage.popitem()
    client.free_storage(id)
Ejemplo n.º 3
0
def register_client(client: ContractInterface):
    client.register()