Skip to content

support the tuple ip and port#1283

Open
wuzhongdehua wants to merge 1 commit intoapache:trunkfrom
wuzhongdehua:panpan-3.29.2
Open

support the tuple ip and port#1283
wuzhongdehua wants to merge 1 commit intoapache:trunkfrom
wuzhongdehua:panpan-3.29.2

Conversation

@wuzhongdehua
Copy link

No description provided.

Copy link
Contributor

@absurdfarce absurdfarce left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @wuzhongdehua!

The main things for me on an initial pass would be a preference for namedtuples instead of conventional tuples and the comments around the API changes.

if type(translated_address) is tuple and len(translated_address)>1:
ip = translated_address[0]
port = translated_address[1]
log.debug( "PANDU: CREATING Default endpoint {} {}".format(ip, port))
Copy link
Contributor

Choose a reason for hiding this comment

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

This debug line should also be removed

# TODO next major, create a TranslatedEndPoint type
## Overriden by Pandu. using ip + port translation
translated_address = self.cluster.address_translator.translate(addr)
log.debug("PANDU: translated address {}".format(translated_address))
Copy link
Contributor

Choose a reason for hiding this comment

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

This debug line should be removed

## Overriden by Pandu. using ip + port translation
translated_address = self.cluster.address_translator.translate(addr)
log.debug("PANDU: translated address {}".format(translated_address))
if type(translated_address) is tuple and len(translated_address)>1:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer a namedtuple here rather than a straight tuple... just to avoid any possible confusion with positions in a base tuple.

# create the endpoint with the translated address
# TODO next major, create a TranslatedEndPoint type
## Overriden by Pandu. using ip + port translation
translated_address = self.cluster.address_translator.translate(addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems really odd to me that this changes the API from address -> translated address to address -> (translated address, translated port). It's not immediately obvious to me how many use cases would be able to compute a translation for port numbers based only on an input address. Seems like the more complete option would be to provide both address and port if we're going to return a combination of translated address and port.

This also probably helps out with the API. We have something like this right now:

def translate(self, addr) -> str:

The proposal here is to move to something like this:

def translate(self, addr) -> (str | [tuple[str,int])

This is an API change but it's an addition rather than a change of existing functionality; we won't break any address translators out there. But if we add a new method which clearly returns a host/string tuple (of some form) then we can clearly distinguish between these cases:

def translate(self, addr) -> str:
...
def translate_all(self, addr, port) -> tuple[str,int]

We'd still have the question of how we want DefaultEndPointFactory to use these methods... but it might be clearer if we did so?

@absurdfarce
Copy link
Contributor

@bschoening I'm curious what you think about this one.

@bschoening bschoening self-requested a review March 23, 2026 21:05
@bschoening
Copy link
Contributor

@wuzhongdehua can you add a description to this PR? I don't understand why a tuple format is preferable and turns one line into ten.

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.

4 participants