def tcp_client(): client = rpc.TCPClient(ip_to_str(N.net[0].ip), port=PORT, net=N, me=N.net[1], sockmodgen=Sock) x = 5 xsquare = client.square(x) print xtime.time(), 'assert xsquare == 25' assert xsquare == 25 xmul7 = client.mul(x, 7) print xtime.time(), 'assert xmul7 == 35' assert xmul7 == 35 xadd9 = client.nestmod.add(x, 9) print xtime.time(), 'assert xadd9 == 14' assert xadd9 == 14 # something trickier n, nn = client, client.nestmod result = n.square(n.mul(x, nn.add(x, 10))) assert (1, 2) == client.caller_test(1, 2) try: # should crash now client.private_func() except Exception, e: logging.debug(str(e))
def store(self, ip_table): """Substitute the old ip_table with the new and notify about the changes ip_table: the new ip_table; """ # the rows deleted during truncation died_ip_list = [] ip_table, died_ip_list = self._truncate(ip_table) # first of all we cycle through the old ip_table # looking for nodes that aren't in the new one for key in self.ip_table: # if we find a row that isn't in the new ip_table and whose # deletion hasn't already been notified (raising an event) # during truncation if not key in ip_table and not key in died_ip_list: self.delete(key, remove_from_iptable=False) # now we cycle through the new ip_table # looking for nodes who weren't in the old one # or whose rtt has sensibly changed for key in ip_table: # if a node has been added if not key in self.ip_table: # generate an id and add the entry in translation_table self.ip_to_id(key) # create a TCP connection to the neighbour self.ntk_client[key] = rpc.TCPClient(ip_to_str(key)) # send a message notifying we added a node self.events.send('NEIGH_NEW', (Neigh(bestdev=ip_table[key].bestdev, devs=ip_table[key].devs, idn=self.translation_table[key], ip=key, netid=self.netid_table[key], ntkd=self.ntk_client[key]), )) else: # otherwise (if the node already was in old ip_table) check if # its rtt has changed more than rtt_variation new_rtt = ip_table[key].bestdev[1] old_rtt = self.ip_table[key].bestdev[1] rtt_variation = abs(new_rtt - old_rtt) / float(old_rtt) if rtt_variation > self.rtt_variation_threshold: # send a message notifying the node's rtt changed self.events.send( 'NEIGH_REM_CHGED', (Neigh(bestdev=self.ip_table[key].bestdev, devs=self.ip_table[key].devs, idn=self.translation_table[key], ip=key, netid=self.netid_table[key], ntkd=self.ntk_client[key]), Rtt(new_rtt))) # finally, update the ip_table self.ip_table = ip_table
def tcp_client(): client = rpc.TCPClient(port=PORT) x = 5 xsquare = client.square(x) assert xsquare == 25 xmul7 = client.mul(x, 7) assert xmul7 == 35 xadd9 = client.nestmod.add(x, 9) assert xadd9 == 14 # something trickier n, nn = client, client.nestmod result = n.square(n.mul(x, nn.add(x, 10))) assert (1, 2) == client.caller_test(1, 2) try: # should crash now client.private_func() except Exception, e: logging.debug(str(e))
def ip_change(self, oldip, newip): """Adds `newip' in the Neighbours as a copy of `oldip', then it removes `oldip'. The relative events are raised.""" logging.info("New IP of neighbour %s is now %s " % (ip_to_str(oldip), ip_to_str(newip))) self.ip_table[newip] = self.ip_table[oldip] self.translation_table[newip] = self.translation_table[oldip] self.netid_table[newip] = self.netid_table[oldip] # we have to create a new TCP connection self.ntk_client[newip] = rpc.TCPClient(ip_to_str(newip)) self.events.send('NEIGH_NEW', (Neigh(bestdev=self.ip_table[newip].bestdev, devs=self.ip_table[newip].devs, idn=self.translation_table[newip], ip=newip, netid=self.netid_table[newip], ntkd=self.ntk_client[newip]), )) self.delete(oldip)