async def handleReceive(self): """ Handle one incoming TCP connection. Multiple data packets may be transferred over a single connection. """ while True: try: ret = await read_tl_num_from_stream(self.reader) assert ret == TypeNumber.DATA siz = await read_tl_num_from_stream(self.reader) data_bytes = await self.reader.readexactly(siz) except aio.IncompleteReadError as exc: self.writer.close() logging.info('Closed TCP connection') return except Exception as exc: print(exc) return # Parse data again to obtain the name (data_name, _, _, _) = parse_data(data_bytes, with_tl=False) self.storage.put(Name.to_str(data_name), data_bytes) logging.info(f'Inserted data: {Name.to_str(data_name)}') # Register prefix for this data existing = CommandHandle.update_prefixes_in_storage( self.storage, data_name) if not existing: self.read_handle.listen(data_name)
def check_signatures(self, name: str, commit: Commit) -> bool: # No need to check signature for code branch if self.is_code_branch(name): return True # Verify every tlv file for file in commit.tree.traverse(): # Verify tlv and cert files only is_tlv = file.name.endswith('.tlv') is_cert = file.name.endswith('.cert') if not is_tlv and not is_cert: continue # Verify the signature without considering the signer wire = file.data_stream.read() try: if is_tlv: _, sig_ptrs = proto.parse_gitobj(wire) else: _, _, _, sig_ptrs = enc.parse_data(wire, with_tl=True) except (ValueError, IndexError, TypeError, enc.DecodeError) as e: logging.error(f'Malformed file {name}@{file.name} - {e}') return False if not self.accounts.verify(sig_ptrs): logging.error( f'Unable to verify the signature {name}@{file.name}') return False return True
async def handleReceive(self): """ Handle one incoming TCP connection. Multiple data packets may be transferred over a single connection. """ while True: try: bio = io.BytesIO() ret = await read_tl_num_from_stream(self.reader, bio) # only accept data packets if ret != TypeNumber.DATA: logging.fatal('TCP handle received non-data type, closing connection ...') self.writer.close() return siz = await read_tl_num_from_stream(self.reader, bio) bio.write(await self.reader.readexactly(siz)) data_bytes = bio.getvalue() except aio.IncompleteReadError as exc: self.writer.close() logging.info('Closed TCP connection') return except Exception as exc: print(exc) return # Parse data again to obtain the name data_name, _, _, _ = parse_data(data_bytes, with_tl=True) self.storage.put_data_packet(data_name, data_bytes) logging.info(f'Inserted data: {Name.to_str(data_name)}') await aio.sleep(0)
def put_data_packet(self, name:NonStrictName, data_packet:bytes) -> None: _, meta_info, _, _ = parse_data(data_packet) expire_time_ms = self.time_ms() if meta_info.freshness_period: expire_time_ms += meta_info.freshness_period name = Name.normalize(name) self.cache[name] = (data_packet, expire_time_ms) logging.info(f'SVSyncStorage: cache save {Name.to_str(name)}')
def verify(self, pkt): _, _, _, sig_ptrs = parse_data(pkt) pub_key = ECC.import_key(self.pub_key) verifier = DSS.new(pub_key, 'fips-186-3', 'der') h = SHA256.new() for content in sig_ptrs.signature_covered_part: h.update(content) verifier.verify(h, bytes(sig_ptrs.signature_value_buf))
async def _receive(self, typ: int, data: BinaryStr): """ Pipeline when a packet is received. :param typ: the Type. :param data: the Value of the packet with TL. """ logging.debug('Packet received %s, %s' % (typ, bytes(data))) if typ == LpTypeNumber.LP_PACKET: try: nack_reason, fragment = parse_lp_packet(data, with_tl=True) except (DecodeError, TypeError, ValueError, struct.error): logging.warning('Unable to decode received packet') return data = fragment typ, _ = parse_tl_num(data) else: nack_reason = None if nack_reason is not None: try: name, _, _, _ = parse_interest(data, with_tl=True) except (DecodeError, TypeError, ValueError, struct.error): logging.warning('Unable to decode the fragment of LpPacket') return logging.debug('NetworkNack received %s, reason=%s' % (Name.to_str(name), nack_reason)) self._on_nack(name, nack_reason) else: if typ == TypeNumber.INTEREST: try: name, param, app_param, sig = parse_interest(data, with_tl=True) except (DecodeError, TypeError, ValueError, struct.error): logging.warning('Unable to decode received packet') return logging.debug('Interest received %s' % Name.to_str(name)) await self._on_interest(name, param, app_param, sig, raw_packet=data) elif typ == TypeNumber.DATA: try: name, meta_info, content, sig = parse_data(data, with_tl=True) except (DecodeError, TypeError, ValueError, struct.error): logging.warning('Unable to decode received packet') return logging.debug('Data received %s' % Name.to_str(name)) await self._on_data(name, meta_info, content, sig, raw_packet=data) else: logging.warning('Unable to decode received packet')
def onDataInterest(self, int_name: FormalName, int_param: InterestParam, _app_param: Optional[BinaryStr]) -> None: data_bytes = self.storage.get_data_packet(int_name, int_param.can_be_prefix) if data_bytes: _, _, content, _ = parse_data(data_bytes) logging.info(f'SVSync: served data {bytes(content)}') self.app.put_data(int_name, content=bytes(content), freshness_period=500)
def test_default_3(): data = (b"\x06\x1b\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix" b"\x14\x03\x18\x01\x00") name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/local/ndn/prefix") assert meta_info.content_type == ContentType.BLOB assert meta_info.freshness_period is None assert meta_info.final_block_id is None assert sig.signature_info is None assert content is None assert sig.signature_value_buf is None
def read_trust_anchor(self): ta_path = os.path.abspath(os.getenv('GIT_NDN_TRUST_ANCHOR')) with open(ta_path, 'rb') as f: cert = f.read() ta_name, _, key_bits, _ = enc.parse_data(cert, with_tl=True) user_name = bytes(enc.Component.get_value(ta_name[-5])).decode() key_name = bytes(enc.Component.get_value(ta_name[-3])).hex() self.trust_anchor_name = (user_name, key_name) pub_key = ECC.import_key(bytes(key_bits)) self.trust_anchor_verifier = DSS.new(pub_key, 'fips-186-3', 'der') logging.info(f'Trust anchor loaded: {enc.Name.to_str(ta_name)}')
def verify(self, sig_ptrs: enc.SignaturePtrs) -> bool: if (sig_ptrs.signature_info is None or sig_ptrs.signature_info.key_locator is None or sig_ptrs.signature_info.key_locator.name is None): logging.info(f'No signature') return False user_name = bytes( enc.Component.get_value( sig_ptrs.signature_info.key_locator.name[-3])).decode() key_name = bytes( enc.Component.get_value( sig_ptrs.signature_info.key_locator.name[-1])).hex() if (user_name, key_name) == self.trust_anchor_name: verifier = self.trust_anchor_verifier else: try: cert = self.repo.read_file( f'refs/users/{user_name[:2]}/{user_name}', f'KEY/{key_name}.cert') except KeyError as e: if e.args[0] == 0: logging.warning(f'Repo {e.args[1]} does not exist') if e.args[0] == 1: logging.warning(f'User {user_name} does not exist') elif e.args[0] == 2: logging.warning( f'Certificate {user_name}/KEY/{key_name}.cert does not exist' ) return False try: _, _, key_bits, _ = enc.parse_data(cert, with_tl=True) pub_key = ECC.import_key(bytes(key_bits)) verifier = DSS.new(pub_key, 'fips-186-3', 'der') except (ValueError, IndexError, KeyError): logging.warning( f'Certificate {user_name}/KEY/{key_name}.cert is malformed' ) return False h = SHA256.new() for content in sig_ptrs.signature_covered_part: h.update(content) try: verifier.verify(h, bytes(sig_ptrs.signature_value_buf)) except ValueError: logging.info( f'Unable to verify the signature: signed by {user_name}/KEY/{key_name}' ) return False logging.debug(f'Verification passed') return True
def test_data_1(self): key = bytes(i for i in range(32)) signer = HmacSha256Signer('key1', key) data = make_data('/ndn/abc', MetaInfo(None), b'SUCCESS!', signer) assert ( data.hex() == '0649070a08036e646e0803616263' '140015085355434345535321' '160d1b01041c08070608046b657931' '172019868e7183998df373332f3dd1c9c950fc29d734c07977791d8396fa3b91fd36' ) _, _, _, sig_ptrs = parse_data(data) validator = HmacChecker.from_key('key1', key) assert aio.run(validator(Name.from_str('/ndn/abc'), sig_ptrs))
def test_verify(self): # Ecdsa signature is not unique, so we only test if we can verify it pri_key = ECC.generate(curve="P-256") key = pri_key.export_key(format="DER") pub_key = pri_key.public_key() signer = Sha256WithEcdsaSigner("/K/KEY/x", key) pkt = make_data("/test", MetaInfo(), b"test content", signer=signer) _, _, _, sig_ptrs = parse_data(pkt) # Test its format is ASN.1 der format DerSequence().decode(bytes(sig_ptrs.signature_value_buf)) validator = EccChecker.from_key( "/K/KEY/x", bytes(pub_key.export_key(format='DER'))) assert aio.run(validator(Name.from_str("/test"), sig_ptrs))
def test_default_4(): data = bytes.fromhex("0630 0703080145" "1400 1500 16031b0100" "1720f965ee682c6973c3cbaa7b69e4c7063680f83be93a46be2ccc98686134354b66") name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/E") assert meta_info.content_type is None assert meta_info.freshness_period is None assert meta_info.final_block_id is None assert sig.signature_info.signature_type == SignatureType.DIGEST_SHA256 assert content == b'' algo = hashlib.sha256() for part in sig.signature_covered_part: algo.update(part) assert sig.signature_value_buf == algo.digest()
def test_meta_info(): data = (b"\x06\x4e\x07\x17\x08\x05local\x08\x03ndn\x08\x06prefix\x25\x01\x00" b"\x14\x0c\x18\x01\x00\x19\x02\x03\xe8\x1a\x03\x25\x01\x02" b"\x16\x03\x1b\x01\x00" b"\x17 \x03\xb8,\x18\xffMw\x84\x86\xa5a\x94e\xcc\xdaQ\x15\xb7\xfb\x19\xab\x9d1lw\'\xdf\xac\x03#\xcad") name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/local/ndn/prefix/37=%00") assert meta_info.content_type == ContentType.BLOB assert meta_info.freshness_period == 1000 assert meta_info.final_block_id == Component.from_sequence_num(2) assert sig.signature_info.signature_type == SignatureType.DIGEST_SHA256 assert content is None algo = hashlib.sha256() for part in sig.signature_covered_part: algo.update(part) assert sig.signature_value_buf == algo.digest()
def test_verify(self): # Ecdsa signature is not unique, so we only test if we can verify it pri_key = ECC.generate(curve="P-256") key = pri_key.export_key(format="DER") pub_key = pri_key.public_key() signer = Sha256WithEcdsaSigner("/K/KEY/x", key) pkt = make_data("/test", MetaInfo(), b"test content", signer=signer) _, _, _, sig_ptrs = parse_data(pkt) # Test its format is ASN.1 der format DerSequence().decode(bytes(sig_ptrs.signature_value_buf)) verifier = DSS.new(pub_key, 'fips-186-3', 'der') h = SHA256.new() for content in sig_ptrs.signature_covered_part: h.update(content) # verify() throws ValueError if it fails, the return value is undefined # So do not assert its value verifier.verify(h, bytes(sig_ptrs.signature_value_buf))
def put_data_packet(self, name: NonStrictName, data: bytes): """ Insert a data packet named ``name`` with value ``data``. This method will parse ``data`` to get its freshnessPeriod, and compute its expiration time\ by adding the freshnessPeriod to the current time. :param name: NonStrictName. The name of the data packet. :param data: bytes. The value of the data packet. """ _, meta_info, _, _ = parse_data(data) expire_time_ms = self._time_ms() if meta_info.freshness_period: expire_time_ms += meta_info.freshness_period # write data packet and freshness_period to cache name = Name.normalize(name) self.cache[name] = (data, expire_time_ms) logging.info(f'Cache save: {Name.to_str(name)}')
def test_default_1(): data = (b"\x06\x42\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix" b"\x14\x03\x18\x01\x00" b"\x16\x03\x1b\x01\x00" b"\x17 \x7f1\xe4\t\xc5z/\x1d\r\xdaVh8\xfd\xd9\x94" b"\xd8\'S\x13[\xd7\x15\xa5\x9d%^\x80\xf2\xab\xf0\xb5") name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/local/ndn/prefix") assert meta_info.content_type == ContentType.BLOB assert meta_info.freshness_period is None assert meta_info.final_block_id is None assert sig.signature_info.signature_type == SignatureType.DIGEST_SHA256 assert content is None algo = hashlib.sha256() for part in sig.signature_covered_part: algo.update(part) assert sig.signature_value_buf == algo.digest()
def test_default_2(): data = (b'\x06L\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix' b'\x14\x03\x18\x01\x00' b'\x15\x0801020304' b'\x16\x03\x1b\x01\x00' b'\x17 \x94\xe9\xda\x91\x1a\x11\xfft\x02i:G\x0cO\xdd!' b'\xe0\xc7\xb6\xfd\x8f\x9cn\xc5\x93{\x93\x04\xe0\xdf\xa6S') name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/local/ndn/prefix") assert meta_info.content_type == ContentType.BLOB assert meta_info.freshness_period is None assert meta_info.final_block_id is None assert sig.signature_info.signature_type == SignatureType.DIGEST_SHA256 assert content == b'01020304' algo = hashlib.sha256() for part in sig.signature_covered_part: algo.update(part) assert sig.signature_value_buf == algo.digest()
def test_meta_info(): data = ( b"\x06\x4e\x07\x17\x08\x05local\x08\x03ndn\x08\x06prefix\x25\x01\x00" b"\x14\x0c\x18\x01\x00\x19\x02\x03\xe8\x1a\x03\x3a\x01\x02" b"\x16\x03\x1b\x01\x00" b"\x17 \x0f^\xa1\x0c\xa7\xf5Fb\xf0\x9cOT\xe0FeC\x8f92\x04\x9d\xabP\x80o\'\x94\xaa={hQ" ) name, meta_info, content, sig = parse_data(data) assert name == Name.from_str("/local/ndn/prefix/37=%00") assert meta_info.content_type == ContentType.BLOB assert meta_info.freshness_period == 1000 assert meta_info.final_block_id == Component.from_sequence_num(2) assert sig.signature_info.signature_type == SignatureType.DIGEST_SHA256 assert content is None algo = hashlib.sha256() for part in sig.signature_covered_part: algo.update(part) assert sig.signature_value_buf == algo.digest()
async def _fetch( self, nid: Name, seqno: int, retries: int = 0) -> Tuple[Optional[bytes], Optional[BinaryStr]]: name = self.getDataName(nid, seqno) while retries + 1 > 0: try: SVSyncLogger.info(f'SVSync: fetching data {Name.to_str(name)}') _, _, _, pkt = await self.app.express_interest( name, need_raw_packet=True, must_be_fresh=True, can_be_prefix=True, lifetime=self.DATA_INTEREST_LIFETIME) ex_int_name, meta_info, content, sig_ptrs = parse_data(pkt) isValidated = await self.secOptions.validate( ex_int_name, sig_ptrs) if not isValidated: return (None, None) SVSyncLogger.info(f'SVSync: received data {bytes(content)}') if content and self.cacheOthers: self.storage.put_packet(name, pkt) return (bytes(content), pkt) if content else (None, pkt) except InterestNack as e: SVSyncLogger.warning( f'SVSync: nacked with reason={e.reason} {Name.to_str(name)}' ) except InterestTimeout: SVSyncLogger.warning(f'SVSync: timeout {Name.to_str(name)}') except InterestCanceled: SVSyncLogger.warning(f'SVSync: canceled {Name.to_str(name)}') except ValidationFailure: SVSyncLogger.warning( f'SVSync: data failed to validate {Name.to_str(name)}') except Exception as e: SVSyncLogger.warning(f'SVSync: unknown error has occured: {e}') retries = retries - 1 if retries + 1 > 0: SVSyncLogger.info("SVSync: retrying fetching data") return (None, None)
def test_verify(self): pri_key = Ed25519PrivateKey.generate() key = pri_key.private_bytes( encoding=serialization.Encoding.Raw, format=serialization.PrivateFormat.Raw, encryption_algorithm=serialization.NoEncryption(), ) pub_key = pri_key.public_key() signer = Ed25519Signer("/K/KEY/x", key) pkt = make_data("/test", MetaInfo(), b"test content", signer=signer) _, _, _, sig_ptrs = parse_data(pkt) pub_bits = pub_key.public_bytes( encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo, ) validator = Ed25519Checker.from_key("/K/KEY/x", bytes(pub_bits)) assert aio.run(validator(Name.from_str("/test"), sig_ptrs))
async def sendPropInterest(self, source: Name, pckno: int) -> Optional[StateVector]: name: Name = source + self.groupPrefix + [ Component.from_str("prop") ] + [Component.from_number(pckno, Component.TYPE_SEQUENCE_NUM)] try: SVSyncLogger.info( f'SVSyncBalancer: balancing by {Name.to_str(name)}') _, _, _, pkt = await self.app.express_interest( name, need_raw_packet=True, must_be_fresh=True, can_be_prefix=True, lifetime=self.PROP_INTEREST_LIFETIME) int_name, meta_info, content, sig_ptrs = parse_data(pkt) isValidated = await self.secOptions.validate(int_name, sig_ptrs) return StateVector(bytes( content)) if bytes(content) != b'' and isValidated else None except (InterestNack, InterestTimeout, InterestCanceled, ValidationFailure): SVSyncLogger.info( f'SVSyncBalancer: failed to balance from {Name.to_str(name)}') return None
def add_account(self, signer, cert: bytes, email: typing.Optional[str], full_name: typing.Optional[str]) -> bool: repo = self['All-Users.git'] # Read the cert ta_name, _, _, _ = enc.parse_data(cert, with_tl=True) user_name = bytes(enc.Component.get_value(ta_name[-5])).decode() key_name = bytes(enc.Component.get_value(ta_name[-3])).hex() # Test if user exists try: repo.get_head(f'refs/users/{user_name[:2]}/{user_name}') return False except (KeyError, ValueError): pass # All-Users.git@refs/users/ad/admin:account.tlv+KEY account = proto.AccountConfig() account.user_id = user_name.encode() account.email = email.encode() if email else None account.full_name = full_name.encode() if full_name else None account_data = proto.encode(account, signer) tree = {'account.tlv': account_data, 'KEY': {key_name + '.cert': cert}} commit = repo.create_init_commit(tree) repo.set_head(f'refs/users/{user_name[:2]}/{user_name}', commit) return True
def test_data(self): key = bytes([ 0x30, 0x82, 0x04, 0xbf, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x04, 0xa9, 0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb8, 0x09, 0xa7, 0x59, 0x82, 0x84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dd, 0xbc, 0x25, 0xe6, 0xa2, 0xc1, 0xd2, 0x33, 0xdc, 0xef, 0x0a, 0x97, 0x2b, 0xdc, 0x59, 0x6a, 0x86, 0x61, 0x4e, 0xa6, 0xc7, 0x95, 0x99, 0xa6, 0xa6, 0x55, 0x6c, 0x5a, 0x8e, 0x72, 0x25, 0x63, 0xac, 0x52, 0xb9, 0x10, 0x69, 0x83, 0x99, 0xd3, 0x51, 0x6c, 0x1a, 0xb3, 0x83, 0x6a, 0xff, 0x50, 0x58, 0xb7, 0x28, 0x97, 0x13, 0xe2, 0xba, 0x94, 0x5b, 0x89, 0xb4, 0xea, 0xba, 0x31, 0xcd, 0x78, 0xe4, 0x4a, 0x00, 0x36, 0x42, 0x00, 0x62, 0x41, 0xc6, 0x47, 0x46, 0x37, 0xea, 0x6d, 0x50, 0xb4, 0x66, 0x8f, 0x55, 0x0c, 0xc8, 0x99, 0x91, 0xd5, 0xec, 0xd2, 0x40, 0x1c, 0x24, 0x7d, 0x3a, 0xff, 0x74, 0xfa, 0x32, 0x24, 0xe0, 0x11, 0x2b, 0x71, 0xad, 0x7e, 0x14, 0xa0, 0x77, 0x21, 0x68, 0x4f, 0xcc, 0xb6, 0x1b, 0xe8, 0x00, 0x49, 0x13, 0x21, 0x02, 0x81, 0x81, 0x00, 0xb6, 0x18, 0x73, 0x59, 0x2c, 0x4f, 0x92, 0xac, 0xa2, 0x2e, 0x5f, 0xb6, 0xbe, 0x78, 0x5d, 0x47, 0x71, 0x04, 0x92, 0xf0, 0xd7, 0xe8, 0xc5, 0x7a, 0x84, 0x6b, 0xb8, 0xb4, 0x30, 0x1f, 0xd8, 0x0d, 0x58, 0xd0, 0x64, 0x80, 0xa7, 0x21, 0x1a, 0x48, 0x00, 0x37, 0xd6, 0x19, 0x71, 0xbb, 0x91, 0x20, 0x9d, 0xe2, 0xc3, 0xec, 0xdb, 0x36, 0x1c, 0xca, 0x48, 0x7d, 0x03, 0x32, 0x74, 0x1e, 0x65, 0x73, 0x02, 0x90, 0x73, 0xd8, 0x3f, 0xb5, 0x52, 0x35, 0x79, 0x1c, 0xee, 0x93, 0xa3, 0x32, 0x8b, 0xed, 0x89, 0x98, 0xf1, 0x0c, 0xd8, 0x12, 0xf2, 0x89, 0x7f, 0x32, 0x23, 0xec, 0x67, 0x66, 0x52, 0x83, 0x89, 0x99, 0x5e, 0x42, 0x2b, 0x42, 0x4b, 0x84, 0x50, 0x1b, 0x3e, 0x47, 0x6d, 0x74, 0xfb, 0xd1, 0xa6, 0x10, 0x20, 0x6c, 0x6e, 0xbe, 0x44, 0x3f, 0xb9, 0xfe, 0xbc, 0x8d, 0xda, 0xcb, 0xea, 0x8f ]) meta_info = MetaInfo(None, 5000, b'\x08\x02\x00\x09') signer = Sha256WithRsaSigner('/testname/KEY/123', key) data = make_data('/ndn/abc', meta_info, b'SUCCESS!', signer) assert ( data.hex() == '06fd0143070a08036e646e0803616263' '140a190213881a0408020009' '15085355434345535321' '161b1b01011c1607140808746573746e616d6508034b45590803313233' '17fd0100' '5716f5b96a3141dba78970efa4f45601a36c2fc9910e82292c321ae6672ee099' '44930ef3dab60d714927a87063f1b8382d6c98c894cf2f065d7da28b380fa6cd' '08c83a243d847bc086da99c85fd14e941593d16e4f060b6a3bffb98035900643' '0ac22a334cb37dce105902e86ee8c7f4363042bdb815b455d0ce62ae7c43b027' '9842dd956f67a696ee176415873c918f36d976d68971d8d7f903a71ef6f38b27' '3c0d8ccfe23f12ecf5212a34b94eb62f822cda1f09e0f949640319cd026fb1ab' '85282e30a8fe3899bc86d86696e11e157b74f88c0efd9823369dab63262f5d7a' 'abb372a3aaf43307331a2796e913e3d36150f6a387b4c97c19a493bb4513af3f') validator = RsaChecker.from_key('/testname/KEY/123', key) _, _, _, sig_ptrs = parse_data(data) assert aio.run(validator(Name.from_str('/ndn/abc'), sig_ptrs))
def serveDataPacket(datapkt: BinaryStr) -> None: name, _, content, _ = parse_data(datapkt) if content: self.storage.put_packet(name, datapkt)