Skip to content

Conversation

lla-dane
Copy link
Contributor

@lla-dane lla-dane commented Sep 22, 2025

Tracks: multiformats/multiaddr#181
Adds the ipcidr protocol in py-multiaddr in reference with go-implementation

var TranscoderIPCIDR = NewTranscoderFromFunctions(ipcidrStB, ipcidrBtS, ipcidrValidate)

func ipcidrBtS(b []byte) (string, error) {
	if err := ipcidrValidate(b); err != nil {
		return "", err
	}
	return strconv.Itoa(int(b[0])), nil
}

func ipcidrStB(s string) ([]byte, error) {
	ipMask, err := strconv.ParseUint(s, 10, 8)
	if err != nil {
		return nil, err
	}
	return []byte{byte(uint8(ipMask))}, nil
}

func ipcidrValidate(b []byte) error {
	if len(b) != 1 {
		return fmt.Errorf("invalid length (should be == 1)")
	}
	return nil
}

@seetadev @acul71

- Added the codec utility functions in codecs/ipcidr.py
- Added the general codec internal tests in test_protocols.py
@lla-dane
Copy link
Contributor Author

Now will write the ipcidr + multiaddr tests as written in go implementation.

@seetadev
Copy link
Contributor

@lla-dane : Great, thanks Abhinav.

Lets try and getting key protocols in the upcoming multiaddr release. We plan for another release 4 weeks from now.

- Included the ipcidr addresses in the test-cases
- Now all the test cases are running for ipcidr addrs also
"/ip4/192.0.2.0/ipcidr/24",
"/ip6/::1",
"/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21",
"/ip6/2001:db8::/ipcidr/32",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seetadev @acul71: I included the ipcidr type addresses in existing test cases, so now all the tests are running the same ipcidr address, as go-multiaddr.

@lla-dane
Copy link
Contributor Author

@seetadev @acul71: I added the tests, I think this PR should be ready for merge.

@lla-dane lla-dane changed the title WIP: Add ipcidr protocol in reference with go-multiaddr Add ipcidr protocol in reference with go-multiaddr Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants