在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:multiformats/py-multiaddr开源软件地址:https://github.com/multiformats/py-multiaddr开源编程语言:Python 96.1%开源软件介绍:py-multiaddrmultiaddr implementation in Python UsageSimplefrom multiaddr import Multiaddr
# construct from a string
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
# construct from bytes
m2 = Multiaddr(bytes_addr=m1.to_bytes())
assert str(m1) == "/ip4/127.0.0.1/udp/1234"
assert str(m1) == str(m2)
assert m1.to_bytes() == m2.to_bytes()
assert m1 == m2
assert m2 == m1
assert not (m1 != m2)
assert not (m2 != m1) Protocolsfrom multiaddr import Multiaddr
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
# get the multiaddr protocol description objects
m1.protocols()
# [Protocol(code=4, name='ip4', size=32), Protocol(code=17, name='udp', size=16)] En/decapsulatefrom multiaddr import Multiaddr
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
m1.encapsulate(Multiaddr("/sctp/5678"))
# <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m1.decapsulate(Multiaddr("/udp"))
# <Multiaddr /ip4/127.0.0.1> TunnelingMultiaddr allows expressing tunnels very nicely. printer = Multiaddr("/ip4/192.168.0.13/tcp/80")
proxy = Multiaddr("/ip4/10.20.30.40/tcp/443")
printerOverProxy = proxy.encapsulate(printer)
print(printerOverProxy)
# /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80
proxyAgain = printerOverProxy.decapsulate(printer)
print(proxyAgain)
# /ip4/10.20.30.40/tcp/443 MaintainersOriginal author: @sbuss. ContributeContributions welcome. Please check out the issues. Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct. LicenseDual-licensed: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论