def atlas_peer_sync_zonefile_inventory( my_hostport, peer_hostport, maxlen, timeout=None, peer_table=None ):
    """
    Synchronize our knowledge of a peer's zonefiles up to a given byte length
    NOT THREAD SAFE; CALL FROM ONLY ONE THREAD.

    maxlen is the maximum length in bits of the expected zonefile.

    Return the new inv vector if we synced it (updating the peer table in the process)
    Return None if not
    """
    if timeout is None:
        timeout = atlas_inv_timeout()

    peer_inv = ""
    bit_offset = None

    with AtlasPeerTableLocked(peer_table) as ptbl:
        if peer_hostport not in ptbl.keys():
            return None 

        peer_inv = atlas_peer_get_zonefile_inventory( peer_hostport, peer_table=ptbl )

        bit_offset = (len(peer_inv) - 1) * 8      # i.e. re-obtain the last byte
        if bit_offset < 0:
            bit_offset = 0

        else:
            peer_inv = peer_inv[:-1]

    peer_inv = atlas_peer_download_zonefile_inventory( my_hostport, peer_hostport, maxlen, bit_offset=bit_offset, timeout=timeout, peer_table=peer_table )
  
    with AtlasPeerTableLocked(peer_table) as ptbl:
        if peer_hostport not in ptbl.keys():
            log.debug("%s no longer a peer" % peer_hostport)
            return None 

        inv_str = atlas_inventory_to_string(peer_inv)
        if len(inv_str) > 40:
            inv_str = inv_str[:40] + "..."

        log.debug("Set zonefile inventory %s: %s" % (peer_hostport, inv_str))
        atlas_peer_set_zonefile_inventory( peer_hostport, peer_inv, peer_table=ptbl ) # NOTE: may have trailing 0's for padding

    return peer_inv
Synchronize our knowledge of a peer's zonefiles up to a given byte length
    NOT THREAD SAFE; CALL FROM ONLY ONE THREAD.

    maxlen is the maximum length in bits of the expected zonefile.

    Return the new inv vector if we synced it (updating the peer table in the process)
    Return None if not