-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use standard IP cidr format for allow/deny lists #1510
Comments
Related issue: libp2p/js-libp2p-utils#12 |
@achingbrain Doesn't multiaddr already have Seems like we are missing https://github.com/multiformats/go-multiaddr/blob/master/protocols.go#L112 in js? Should we add cidr based filtering implementation in js-multiaddr (like go) or in js-libp2p-utils? |
related to libp2p/js-libp2p#1510 --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
do we still need this @achingbrain ? |
Yes |
JS Colo 2024 rough discussionIt looks like we already have the code in js-multiaddr, https://github.com/multiformats/js-multiaddr/blob/d4164fbce730d3b43a10682b651bcc96db845e7c/src/convert.ts#L120C17-L135, so we don't need to change itShould only need changes in js-libp2p
Action items:
|
@SgtPooki @achingbrain |
@acul71 go for it! open a PR when you're ready. |
I modified the code following #1510 (comment) LUCA1234 init.allow= [ '/ip4/83.13.55.32' ]
62 passing (3s)
1 failing
1) Connection Manager
should not close connection that is on the allowlist when pruning:
Error: Invalid multiaddr
at convertToIpNet (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/node_modules/@multiformats/multiaddr/src/convert.ts:132:11)
at /home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/src/connection-manager/index.ts:229:47
at Array.map (<anonymous>)
at new DefaultConnectionManager (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/src/connection-manager/index.ts:229:37)
at new Libp2p (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/src/libp2p.ts:123:50)
at createLibp2p (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/src/index.ts:202:16)
at createNode (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/test/fixtures/creators/peer.ts:49:16)
at Context2.<anonymous> (/home/luca/Informatica/Learning/PNL_Launchpad_Curriculum/Libp2p/js-libp2p/packages/libp2p/test/connection-manager/index.spec.ts:206:14)
Is '/ip4/83.13.55.32' a valid multiaddress? this.allow = (init.allow ?? []).map(ma => convertToIpNet(multiaddr(ma))) This is the test it('should not close connection that is on the allowlist when pruning', async () => {
const max = 2
const remoteAddr = multiaddr('/ip4/83.13.55.32/tcp/59283')
console.log("LUCA9999") // luca
libp2p = await createNode({
config: createBaseOptions({
connectionManager: {
maxConnections: max,
allow: [
'/ip4/83.13.55.32'
]
}
}),
started: false
}) This is the function processing the multiaddress (convertToIpNet) export function convertToIpNet (multiaddr: Multiaddr): IpNet {
let mask: string | undefined
let addr: string | undefined
multiaddr.stringTuples().forEach(([code, value]) => {
if (code === ip4Protocol.code || code === ip6Protocol.code) {
addr = value
}
if (code === ipcidrProtocol.code) {
mask = value
}
})
if (mask == null || addr == null) {
throw new Error('Invalid multiaddr')
}
return new IpNet(addr, mask)
} |
Is there any further work to do here? #2783 was completed and this can probably be closed unless i'm missing something. |
No, this is complete and has shipped. |
Currently the connection manager treats multiaddrs in the allow/deny lists as string prefixes (e.g.
"/ip4/52.55"
), it should use the standard IP cidr format instead (e.g."/ip4/52.55.0.0/ipcidr/16"
) which will allow us to validate these as multiaddrs.This will likely involve changes to the
@multiformats/multiaddr
module to allow using address ranges.The text was updated successfully, but these errors were encountered: