本文整理汇总了Python中dht.storage.ForgetfulStorage类的典型用法代码示例。如果您正苦于以下问题:Python ForgetfulStorage类的具体用法?Python ForgetfulStorage怎么用?Python ForgetfulStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ForgetfulStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
def test_get(self):
v = Value()
v.valueKey = self.key1
v.serializedData = self.value
testv = [v.SerializeToString()]
f = ForgetfulStorage()
f[self.keyword1] = (self.key1, self.value)
self.assertEqual(testv, f.get(self.keyword1))
示例2: test_get
def test_get(self):
v = Value()
v.valueKey = self.key1
v.serializedData = self.value
v.ttl = 10
testv = [v.SerializeToString()]
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, 10)
self.assertEqual(testv, p.get(self.keyword1))
示例3: setUp
def setUp(self):
self.public_ip = '123.45.67.89'
self.port = 12345
self.own_addr = (self.public_ip, self.port)
self.addr1 = ('132.54.76.98', 54321)
self.addr2 = ('231.76.45.89', 15243)
self.clock = task.Clock()
connection.REACTOR.callLater = self.clock.callLater
self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
self.handler_mock = mock.Mock(spec_set=connection.Handler)
self.con = connection.Connection(
self.proto_mock,
self.handler_mock,
self.own_addr,
self.addr1
)
valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
verify_key = self.signing_key.verify_key
signed_pubkey = self.signing_key.sign(str(verify_key))
h = nacl.hash.sha512(signed_pubkey)
self.storage = ForgetfulStorage()
self.node = Node(unhexlify(h[:40]), self.public_ip, self.port, signed_pubkey, True)
self.protocol = KademliaProtocol(self.node, self.storage, 20)
self.handler = self.protocol.RPCHandler(False, 5, self.protocol._outstanding, self.protocol)
self.handler.connection = self.con
transport = mock.Mock(spec_set=udp.Port)
ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
self.protocol.makeConnection(transport)
示例4: setUp
def setUp(self):
self.version = PROTOCOL_VERSION
self.public_ip = '123.45.67.89'
self.port = 12345
self.own_addr = (self.public_ip, self.port)
self.addr1 = ('132.54.76.98', 54321)
self.addr2 = ('231.76.45.89', 15243)
self.clock = task.Clock()
connection.REACTOR.callLater = self.clock.callLater
self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
self.handler_mock = mock.Mock(spec_set=connection.Handler)
self.con = connection.Connection(
self.proto_mock,
self.handler_mock,
self.own_addr,
self.addr1
)
valid_key = "63d901c4d57cde34fc1f1e28b9af5d56ed342cae5c2fb470046d0130a4226b0c"
self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
verify_key = self.signing_key.verify_key
h = nacl.hash.sha512(verify_key.encode())
self.storage = ForgetfulStorage()
self.node = Node(unhexlify(h[:40]), self.public_ip, self.port,
verify_key.encode(), None, objects.FULL_CONE, True)
self.db = datastore.Database(filepath="test.db")
self.protocol = KademliaProtocol(self.node, self.storage, 20, self.db, self.signing_key)
self.wire_protocol = OpenBazaarProtocol(self.db, self.own_addr, objects.FULL_CONE)
self.wire_protocol.register_processor(self.protocol)
self.protocol.connect_multiplexer(self.wire_protocol)
self.handler = self.wire_protocol.ConnHandler([self.protocol], self.wire_protocol, None,
self.wire_protocol.ban_score)
self.handler.connection = self.con
transport = mock.Mock(spec_set=udp.Port)
ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
self.wire_protocol.makeConnection(transport)
示例5: setUp
def setUp(self):
self.version = PROTOCOL_VERSION
self.public_ip = '123.45.67.89'
self.port = 12345
self.own_addr = (self.public_ip, self.port)
self.addr1 = ('132.54.76.98', 54321)
self.addr2 = ('231.76.45.89', 15243)
self.clock = task.Clock()
connection.REACTOR.callLater = self.clock.callLater
self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
self.handler_mock = mock.Mock(spec_set=connection.Handler)
self.con = connection.Connection(
self.proto_mock,
self.handler_mock,
self.own_addr,
self.addr1
)
valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
verify_key = self.signing_key.verify_key
signed_pubkey = self.signing_key.sign(str(verify_key))
h = nacl.hash.sha512(signed_pubkey)
self.storage = ForgetfulStorage()
self.node = Node(unhexlify(h[:40]), self.public_ip, self.port, signed_pubkey, True)
self.db = datastore.Database(filepath="test.db")
self.protocol = KademliaProtocol(self.node, self.storage, 20, self.db)
self.wire_protocol = OpenBazaarProtocol(self.own_addr, "Full Cone")
self.wire_protocol.register_processor(self.protocol)
self.protocol.connect_multiplexer(self.wire_protocol)
self.handler = self.wire_protocol.ConnHandler([self.protocol], self.wire_protocol)
self.handler.connection = self.con
transport = mock.Mock(spec_set=udp.Port)
ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
self.wire_protocol.makeConnection(transport)
示例6: KademliaProtocolTest
class KademliaProtocolTest(unittest.TestCase):
def setUp(self):
self.version = PROTOCOL_VERSION
self.public_ip = '123.45.67.89'
self.port = 12345
self.own_addr = (self.public_ip, self.port)
self.addr1 = ('132.54.76.98', 54321)
self.addr2 = ('231.76.45.89', 15243)
self.clock = task.Clock()
connection.REACTOR.callLater = self.clock.callLater
self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
self.handler_mock = mock.Mock(spec_set=connection.Handler)
self.con = connection.Connection(
self.proto_mock,
self.handler_mock,
self.own_addr,
self.addr1
)
valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
verify_key = self.signing_key.verify_key
signed_pubkey = self.signing_key.sign(str(verify_key))
h = nacl.hash.sha512(signed_pubkey)
self.storage = ForgetfulStorage()
self.node = Node(unhexlify(h[:40]), self.public_ip, self.port, signed_pubkey, True)
self.db = datastore.Database(filepath="test.db")
self.protocol = KademliaProtocol(self.node, self.storage, 20, self.db)
self.wire_protocol = OpenBazaarProtocol(self.own_addr, "Full Cone")
self.wire_protocol.register_processor(self.protocol)
self.protocol.connect_multiplexer(self.wire_protocol)
self.handler = self.wire_protocol.ConnHandler([self.protocol], self.wire_protocol)
self.handler.connection = self.con
transport = mock.Mock(spec_set=udp.Port)
ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
self.wire_protocol.makeConnection(transport)
def tearDown(self):
if self.con.state != connection.State.SHUTDOWN:
self.con.shutdown()
self.wire_protocol.shutdown()
os.remove("test.db")
def test_invalid_datagram(self):
self.assertFalse(self.handler.receive_message("hi"))
self.assertFalse(self.handler.receive_message("hihihihihihihihihihihihihihihihihihihihih"))
def test_rpc_ping(self):
self._connecting_to_connected()
m = message.Message()
m.messageID = digest("msgid")
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("PING")
m.protoVer = self.version
m.testnet = False
data = m.SerializeToString()
m.arguments.append(self.protocol.sourceNode.getProto().SerializeToString())
expected_message = m.SerializeToString()
self.handler.receive_message(data)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
m_calls = self.proto_mock.send_datagram.call_args_list
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
received_message = sent_packet.payload
self.assertEqual(received_message, expected_message)
self.assertEqual(len(m_calls), 2)
def test_rpc_store(self):
self._connecting_to_connected()
self.protocol.router.addContact(self.protocol.sourceNode)
m = message.Message()
m.messageID = digest("msgid")
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("STORE")
m.protoVer = self.version
m.testnet = False
m.arguments.extend([digest("Keyword"), "Key",
self.protocol.sourceNode.getProto().SerializeToString(), str(10)])
data = m.SerializeToString()
del m.arguments[-4:]
m.arguments.append("True")
expected_message = m.SerializeToString()
self.handler.receive_message(data)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
m_calls = self.proto_mock.send_datagram.call_args_list
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
received_message = sent_packet.payload
self.assertEqual(received_message, expected_message)
#.........这里部分代码省略.........
示例7: test_ttl
def test_ttl(self):
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, .000000000001)
self.assertTrue(p.get(self.keyword1) is None)
示例8: test_iteritems
def test_iteritems(self):
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, 10)
for k, v in p.iteritems(self.keyword1):
self.assertEqual((self.key1, self.value), (k, v))
示例9: test_iterkeys
def test_iterkeys(self):
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, 10)
for k in p.iterkeys():
self.assertEqual(k[0].decode("hex"), self.keyword1)
示例10: test_delete
def test_delete(self):
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, 10)
p.delete(self.keyword1, self.key1)
self.assertEqual(p.get(self.keyword1), None)
示例11: test_getSpecific
def test_getSpecific(self):
p = ForgetfulStorage()
p[self.keyword1] = (self.key1, self.value, 10)
self.assertEqual(self.value, p.getSpecific(self.keyword1, self.key1))
示例12: KademliaProtocolTest
class KademliaProtocolTest(unittest.TestCase):
def setUp(self):
self.public_ip = '123.45.67.89'
self.port = 12345
self.own_addr = (self.public_ip, self.port)
self.addr1 = ('132.54.76.98', 54321)
self.addr2 = ('231.76.45.89', 15243)
self.clock = task.Clock()
connection.REACTOR.callLater = self.clock.callLater
self.proto_mock = mock.Mock(spec_set=rudp.ConnectionMultiplexer)
self.handler_mock = mock.Mock(spec_set=connection.Handler)
self.con = connection.Connection(
self.proto_mock,
self.handler_mock,
self.own_addr,
self.addr1
)
valid_key = "1a5c8e67edb8d279d1ae32fa2da97e236b95e95c837dc8c3c7c2ff7a7cc29855"
self.signing_key = nacl.signing.SigningKey(valid_key, encoder=nacl.encoding.HexEncoder)
verify_key = self.signing_key.verify_key
signed_pubkey = self.signing_key.sign(str(verify_key))
h = nacl.hash.sha512(signed_pubkey)
self.storage = ForgetfulStorage()
self.node = Node(unhexlify(h[:40]), self.public_ip, self.port, signed_pubkey, True)
self.protocol = KademliaProtocol(self.node, self.storage, 20)
self.handler = self.protocol.RPCHandler(False, 5, self.protocol._outstanding, self.protocol)
self.handler.connection = self.con
transport = mock.Mock(spec_set=udp.Port)
ret_val = address.IPv4Address('UDP', self.public_ip, self.port)
transport.attach_mock(mock.Mock(return_value=ret_val), 'getHost')
self.protocol.makeConnection(transport)
def tearDown(self):
self.con.shutdown()
self.protocol.shutdown()
def test_invalid_datagram(self):
self.assertFalse(self.handler.receive_message("hi"))
self.assertFalse(self.handler.receive_message("hihihihihihihihihihihihihihihihihihihihih"))
def test_rpc_ping(self):
self._connecting_to_connected()
m = message.Message()
m.messageID = digest("msgid")
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("PING")
data = m.SerializeToString()
m.arguments.append(self.protocol.sourceNode.getProto().SerializeToString())
expected_message = m.SerializeToString()
self.handler.receive_message(data)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
m_calls = self.proto_mock.send_datagram.call_args_list
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
received_message = sent_packet.payload
self.assertEqual(received_message, expected_message)
self.assertEqual(len(m_calls), 2)
def test_rpc_store(self):
self._connecting_to_connected()
m = message.Message()
m.messageID = digest("msgid")
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("STORE")
m.arguments.extend(["Keyword", "Key", self.protocol.sourceNode.getProto().SerializeToString()])
data = m.SerializeToString()
for i in range(0, 3):
del m.arguments[-1]
m.arguments.append("True")
expected_message = m.SerializeToString()
self.handler.receive_message(data)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
m_calls = self.proto_mock.send_datagram.call_args_list
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
received_message = sent_packet.payload
self.assertEqual(received_message, expected_message)
self.assertEqual(len(m_calls), 2)
self.assertTrue(self.storage.getSpecific("Keyword", "Key") == self.protocol.sourceNode.getProto().SerializeToString())
def test_rpc_delete(self):
self._connecting_to_connected()
# Set a keyword to store
m = message.Message()
m.messageID = digest("msgid")
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("STORE")
m.arguments.extend(["Keyword", "Key", self.protocol.sourceNode.getProto().SerializeToString()])
#.........这里部分代码省略.........
示例13: test_iterkeys
def test_iterkeys(self):
f = ForgetfulStorage()
f[self.keyword1] = (self.key1, self.value, 10)
for k in f.iterkeys():
self.assertEqual(k, self.keyword1)
示例14: test_delete
def test_delete(self):
f = ForgetfulStorage()
f[self.keyword1] = (self.key1, self.value, 10)
f.delete(self.keyword1, self.key1)
self.assertEqual(f.get(self.keyword1), None)
示例15: test_iteritems
def test_iteritems(self):
f = ForgetfulStorage()
f[self.keyword1] = (self.key1, self.value)
for k, v in f.iteritems(self.keyword1):
self.assertEqual((self.key1, self.value), (k, v))