Don't use network for sending ACK #2205

Merged
PeterSurda merged 6 commits from gitea-77 into v0.6 2024-04-05 01:15:06 +02:00
3 changed files with 30 additions and 1 deletions
Showing only changes of commit 9747f65884 - Show all commits

View File

@ -436,6 +436,17 @@ def assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText=''):
# Packet decoding # Packet decoding
def decodeObjectParameters(data):
"""Decode the parameters of a raw object needed to put it in inventory"""
# BMProto.decode_payload_content("QQIvv")
expiresTime = unpack('>Q', data[8:16])[0]
objectType = unpack('>I', data[16:20])[0]
parserPos = 20 + decodeVarint(data[20:30])[1]
toStreamNumber = decodeVarint(data[parserPos:parserPos + 10])[0]
return objectType, toStreamNumber, expiresTime
def decryptAndCheckPubkeyPayload(data, address): def decryptAndCheckPubkeyPayload(data, address):
""" """
Version 4 pubkeys are encrypted. This function is run when we Version 4 pubkeys are encrypted. This function is run when we

View File

@ -54,3 +54,12 @@ sample_subscription_addresses = [
'BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq', 'BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq',
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw'] 'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw']
sample_subscription_name = 'test sub' sample_subscription_name = 'test sub'
sample_object_expires = 1712271487
# from minode import structure
# obj = structure.Object(
# b'\x00' * 8, sample_object_expires, 42, 1, 2, b'HELLO')
# .. do pow and obj.to_bytes()
sample_object_data = unhexlify(
'00000000001be7fc00000000660f307f0000002a010248454c4c4f')

View File

@ -5,7 +5,8 @@ from struct import pack
from pybitmessage import addresses, protocol from pybitmessage import addresses, protocol
from .samples import sample_addr_data from .samples import (
sample_addr_data, sample_object_data, sample_object_expires)
from .test_protocol import TestSocketInet from .test_protocol import TestSocketInet
@ -49,6 +50,14 @@ class TestSerialize(TestSocketInet):
self.assertEqual( self.assertEqual(
protocol.CreatePacket(b'ping')[:len(head)], head) protocol.CreatePacket(b'ping')[:len(head)], head)
def test_decode_obj_parameters(self):
"""Check parameters decoded from a sample object"""
objectType, toStreamNumber, expiresTime = \
protocol.decodeObjectParameters(sample_object_data)
self.assertEqual(objectType, 42)
self.assertEqual(toStreamNumber, 2)
self.assertEqual(expiresTime, sample_object_expires)
def test_encodehost(self): def test_encodehost(self):
"""Check the result of protocol.encodeHost()""" """Check the result of protocol.encodeHost()"""
self.assertEqual( self.assertEqual(