def test_lookuprequest_with_data(self): sender = routing.Hash(value="sender") lookup = routing.Hash(value="lookup") for _ in xrange(100): data = os.urandom(random.randint(100, 10000)) pkt = chord.LookupRequest.make_packet(sender, lookup, data) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_lookupresponse(self): sender = routing.Hash(value="sender") lookup = routing.Hash(value="lookup") req = chord.LookupRequest.make_packet(sender, lookup) req.pack() pkt = chord.LookupResponse.make_packet(sender, lookup, sender, ("127.0.0.1", 0xB00B), 5, original=req) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_messagecontainer(self): h = routing.Hash(value="sender") n = message.MessageContainer(message.MessageType.MSG_CH_NOTIFY, h, data="hey babes\x77hey", sequence=2884) # debug.dump_packet(n.pack(), n.full_format()) self.assertEqual(n.pack(), self._repack(n.pack()))
def test_hashes(self): for i in xrange(self.HASH_COUNT): start = ''.join([ random.choice(string.lowercase) for _ in xrange(random.randint(10, 20)) ]) # print "Hashing value: %s" % repr(start) h = routing.Hash(value=start) self.assertEqual(routing.Hash.pack_hash(str(h)), h.parts)
def _notify_response(self, flag): sender = routing.Hash(value="sender") send_node = chordnode.ChordNode(sender, ("localhost", 0xB00B)) req = chord.NotifyRequest.make_packet(sender, send_node, send_node, send_node) req.pack() pkt = chord.NotifyResponse.make_packet(sender, flag, original=req) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_inforesponse_with_successor(self): sender = routing.Hash(value="sender") send_node = chordnode.ChordNode(sender, ("localhost", 0xB00B)) req = chord.InfoRequest.make_packet(sender) req.pack() # need to pack for checksum injection pkt = chord.InfoResponse.make_packet(sender, send_node, None, send_node, original=req) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_joinrequest(self): sender = routing.Hash(value="sender") pkt = chord.JoinRequest.make_packet(sender, ("127.0.0.1", 0xB00B)) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_inforequest(self): sender = routing.Hash(value="sender") pkt = chord.InfoRequest.make_packet(sender) # debug.dump_packet(pkt.pack(), pkt.full_format()) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))
def test_lookuprequest(self): sender = routing.Hash(value="sender") lookup = routing.Hash(value="lookup") pkt = chord.LookupRequest.make_packet(sender, lookup) self.assertEqual(pkt.pack(), self._repack(pkt.pack()))