Skip to content
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

Definition of canonical is confusing #8

Closed
zjkmxy opened this issue Jun 6, 2021 · 2 comments
Closed

Definition of canonical is confusing #8

zjkmxy opened this issue Jun 6, 2021 · 2 comments

Comments

@zjkmxy
Copy link
Member

zjkmxy commented Jun 6, 2021

The concept of canonical in YaNFD is confusing. For ethernetURI, fdURI, internalURI, nullURI, udpURI, canonical means well-formed:

YaNFD/ndn/uri.go

Lines 286 to 302 in 001755f

case ethernetURI:
isEthernet, _ := regexp.MatchString(macPattern, u.path)
return u.scheme == "ether" && isEthernet && u.port == 0
case fdURI:
fd, err := strconv.Atoi(u.path)
return u.scheme == "fd" && err == nil && fd >= 0 && u.port == 0
case internalURI:
return u.scheme == "internal" && u.path == "" && u.port == 0
case nullURI:
return u.scheme == "null" && u.path == "" && u.port == 0
case udpURI:
// Split off zone, if any
ip := net.ParseIP(u.PathHost())
// Port number is implicitly limited to <= 65535 by type uint16
// We have to test whether To16() && not IPv4 because the Go net library considers IPv4 addresses to be valid IPv6 addresses
isIPv4, _ := regexp.MatchString(ipv4Pattern, u.PathHost())
return ip != nil && ((u.scheme == "udp4" && ip.To4() != nil) || (u.scheme == "udp6" && ip.To16() != nil && !isIPv4)) && u.port > 0

For devURI and unixURI, canonical means existing interface, which is related to specific machine and operation system:

YaNFD/ndn/uri.go

Lines 303 to 306 in 001755f

case unixURI:
// Check whether file exists
fileInfo, err := os.Stat("/" + u.path)
return u.scheme == "unix" && ((err == nil && !fileInfo.IsDir()) || os.IsNotExist(err)) && u.port == 0

This restricts that the unit test can be only executed on specific machines:
uri := ndn.MakeUnixFaceURI("/run/nfd.sock")

Not every machine allows building program access to this path.

Note: ndn-cxx does not check the physical existence of interface in isCanonical.

@zjkmxy zjkmxy closed this as completed in 1fdd728 Jun 7, 2021
@eric135
Copy link
Collaborator

eric135 commented Jun 7, 2021

This concept was inherited from NFD/ndn-cxx. I'd recommend looking at what they did (and trying to stay compatible) :-)

@zjkmxy
Copy link
Member Author

zjkmxy commented Jun 7, 2021

This concept was inherited from NFD/ndn-cxx. I'd recommend looking at what they did (and trying to stay compatible) :-)

ndn-cxx does not check physical existence of faces. For devURI, it always succeed if there is a path; for unixURI, ndn-cxx always fails (not supported).

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

No branches or pull requests

2 participants