def got_moreinfo(self): self.set_started() self._last_moreinfo = datetime.utcnow() for c in self.downloadimpl.midict.get("channels", []): self._active_channels.add( (Address.tuple((c["socket_ip"], c["socket_port"])), Address.tuple((c["ip"], c["port"])) )) # Tuple can handle both ipv4 and ipv6 (port can be string)
def test_update_contacts(self): sock_addr = ("1.1.1.1", 3) packets = ["asdf", "sf"] comm, dc = self.common.update_dispersy_contacts(sock_addr, packets, recv=False) first_contact = iter(self.common.dispersy_contacts).next() self.assertEqual(dc, None) self.assertEqual(len(self.common.dispersy_contacts), 1) self.assertEqual(first_contact.address.ip, sock_addr[0]) self.assertEqual(self.common.get_contact(Address.tuple(sock_addr)), first_contact) more_packets = ["sfjdoiwenfo", "sfjisa"] comm, dc = self.common.update_dispersy_contacts(sock_addr, more_packets, recv=False) self.assertEqual(dc, None) self.assertEqual(len(self.common.dispersy_contacts), 1) self.assertEqual(first_contact.num_sent(), len(packets + more_packets)) self.assertEqual(first_contact.total_sent(), sum(len(p) for p in packets + more_packets)) comm, dc = self.common.update_dispersy_contacts(sock_addr, more_packets, recv=True) self.assertEqual(dc, first_contact, str(dc) + " != " + str(first_contact)) self.assertEqual(len(self.common.dispersy_contacts), 1) self.assertEqual(first_contact.num_sent(), len(packets + more_packets)) self.assertEqual(first_contact.total_sent(), sum(len(p) for p in packets + more_packets)) self.assertEqual(first_contact.num_rcvd(), len(more_packets)) self.assertEqual(first_contact.total_rcvd(), sum(len(p) for p in more_packets)) new_sock_addr = ("2.2.1.2", 5) comm, dc = self.common.update_dispersy_contacts(new_sock_addr, packets, recv=True) for c in self.common.dispersy_contacts: if c != first_contact: second_contact = c self.assertEqual(dc, second_contact) self.assertEqual(len(self.common.dispersy_contacts), 2) self.assertEqual(first_contact.num_sent(), len(packets + more_packets)) self.assertEqual(first_contact.total_sent(), sum(len(p) for p in packets + more_packets)) self.assertEqual(first_contact.num_rcvd(), len(more_packets)) self.assertEqual(first_contact.total_rcvd(), sum(len(p) for p in more_packets)) self.assertEqual(second_contact.num_rcvd(), len(packets)) self.assertEqual(second_contact.total_rcvd(), sum(len(p) for p in packets))
def allowed_addresses(self): if isinstance(self._destination, CandidateDestination.Implementation): return [ Address.tuple(c.sock_addr) for c in self._destination._candidates ] return None # We're not returning a list if this is not a candidatedestination.. Deal with it
def allowed_addresses(self): if isinstance(self._destination, CandidateDestination.Implementation): return [Address.tuple(c.sock_addr) for c in self._destination._candidates] return None # We're not returning a list if this is not a candidatedestination.. Deal with it
def got_moreinfo(self): self.set_started() self._last_moreinfo = datetime.utcnow() for c in self.downloadimpl.midict.get("channels", []): self._active_channels.add((Address.tuple((c["socket_ip"], c["socket_port"])), Address.tuple((c["ip"], c["port"])))) # Tuple can handle both ipv4 and ipv6 (port can be string)