commit 5a6529e1e2792fe794cee239f963bf5a65503e16 Author: David Fifield david@bamsoftware.com Date: Sat Feb 1 21:01:04 2014 -0800
Also figure out the register_addr after opening listeners.
So that you register the proper port number when you give ":0" on the command line.
There may be up to two listeners: one for IPv4 and one for IPv6, and they may be on different ports or they may be the same. Previously they could only be the same, so we could pass a specification like ":9000" to a registration helper, and whether it happened to use IPv4 or IPv6 things would work out. Now that the ports may be different with ":0", there is ambiguity because omitting the host part has meant "registration helper guesses the external address" which really means "the remote server the registration helper talks to guesses the address." If we have, for example, $ ./flashproxy-client --external --register :9001 :0 2014-02-01 21:35:29 Listening remote on 0.0.0.0:10000. 2014-02-01 21:35:29 Listening remote on [::]:20000. it would be a mistake to try and register both ":10000" and ":20000", because they will both be guessed to be the same address family. We don't have a way to hint to registration helpers that a guessed address should belong to a certain address family.
A similar but smaller difficulty exists with --register-addr. That option takes default values from the actual listening address, so that you can, for example, provide an IP address and have the port filled in automatically. Providing an IPv4 address would cause the IPv4 address to be registered twice, once correctly with a port belonging to IPv4 and once incorrectly with a port belonging to IPv6.
Unsure fo the best way to handle this, I kept that there is a single register_addr, and it is set only to the IPv4 listener. The behavior is the same in all cases that worked before; that is, all cases that don't use ":0" as a port specification. If you need to override it, you can use --register-addr. --- flashproxy-client | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/flashproxy-client b/flashproxy-client index f3c8926..09630b3 100755 --- a/flashproxy-client +++ b/flashproxy-client @@ -1179,7 +1179,6 @@ def main(): options.remote_addrs.append(("0.0.0.0", remote_addr[1])) if socket.has_ipv6: options.remote_addrs.append(("::", remote_addr[1])) - options.register_addr = parse_addr_spec(register_addr_spec or ":", *remote_addr)
if not register_methods: register_methods = DEFAULT_REGISTER_METHODS @@ -1196,6 +1195,13 @@ def main(): continue remote_listen.append(listen) log(u"Listening remote on %s." % format_sockaddr(listen.getsockname())) + if options.register_addr is None: + host, port = socket.getnameinfo(listen.getsockname(), socket.NI_NUMERICHOST | socket.NI_NUMERICSERV) + port = int(port) + if not remote_addr[0]: + # Make host part blank (not 0.0.0.0) if unspecified. + host = "" + options.register_addr = parse_addr_spec(register_addr_spec or ":", host, port) if not remote_listen: log(u"Failed to open any remote listeners, quitting.") pt_cmethoderror("Failed to open any remote listeners.")