code: def info_from_p2p_addr(addr: Multiaddr) -> PeerInfo:
      if addr is None:
          raise InvalidAddrError("`addr` should not be `None`")
  
      parts = addr.split()
      if not parts:
          raise InvalidAddrError(
              f"`parts`={parts} should at least have a protocol `P_P2P`"
          )
  
      p2p_part = parts[-1]
      last_protocol_code = p2p_part.protocols()[0].code
      if last_protocol_code != protocols.P_P2P:
          raise InvalidAddrError(
              f"The last protocol should be `P_P2P` instead of `{last_protocol_code}`"
          )
  
      # make sure the /p2p value parses as a peer.ID
      peer_id_str: str = p2p_part.value_for_protocol(protocols.P_P2P)
      peer_id = PeerID.from_base58(peer_id_str)
  
      # we might have received just an / p2p part, which means there's no addr.
      if len(parts) > 1:
          addr = Multiaddr.join(*parts[:-1])
  
      return PeerInfo(peer_id, [addr])
  
imports: import hashlib
  from typing import Any, Sequence, Union
  import base58
  import multihash
  from cryptography.hazmat.primitives import serialization
  from multiaddr import Multiaddr, protocols
  from hivemind.proto import crypto_pb2, p2pd_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: info_from_p2p_addr(addr) and returns: PeerInfo