[Twisted-Python] twisted.internet and IPv6
![](https://secure.gravatar.com/avatar/1833d9a7642a05ddea0d27de72be2e2b.jpg?s=120&d=mm&r=g)
Hi! I'm curious: how much work would it be to enable IPv6 support in twisted.internet? When I do --------------------------------------- cd twisted/internet fgrep INET *.py --------------------------------------- I get a number of references to IPv4 that make me believe that t.i.* is not quite IPv6 clean by itself: --------------------------------------- default.py: server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) default.py: client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) javareactor.py: return ('INET', InetAddress.getLocalHost().getHostAddress(), self.jport.port) javareactor.py: return ('INET', addr.getHostAddress(), self.skt.getPort()) javareactor.py: return ("INET", self.host, self.port) tcp.py: addressFamily = socket.AF_INET tcp.py: return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',))) tcp.py: return address.IPv4Address('TCP', *(self.addr + ('INET',))) tcp.py: return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',))) tcp.py: return address.IPv4Address('TCP', *(self.client + ('INET',))) tcp.py: addressFamily = socket.AF_INET tcp.py: return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',))) tcp.py: return address.IPv4Address('TCP', self.host, self.port, 'INET') udp.py: addressFamily = socket.AF_INET udp.py: return address.IPv4Address('UDP', *(self.socket.getsockname() + ('INET_UDP',))) udp.py: Returns a tuple of ('INET_UDP', hostname, port), indicating udp.py: return address.IPv4Address('UDP', self.remotehost, self.remoteport, 'INET_UDP') --------------------------------------- What would be needed? Would a new reactor be a good solution? "reactor6" ? Or rather extending the current one? I'd say a reactor6 would be cleaner, but on the other hand, a simple flag could do the trick from the API perspective. Any comments on this? Stefan
![](https://secure.gravatar.com/avatar/77d03707d9cd7b54103dca504be78ed3.jpg?s=120&d=mm&r=g)
On Thu, 30 Sep 2004 10:12:18 +0200, Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de> wrote:
Hi!
I'm curious: how much work would it be to enable IPv6 support in twisted.internet?
I get a number of references to IPv4 that make me believe that t.i.* is not quite IPv6 clean by itself:
That a new reactor would solve nothing since the reactor is not the responsible for connections. Connection.py and tcp.py are the modules you are looking for (those that create the connection). Also there's a problem if you only write a new reactor, that IPv6 couldn't be used in other reactors, which is bad :). I'd rather hack on tcp.py and Connection.py and address.py (all in twisted.internet). Those sockets that you see in default.py are to wake up the main thread under windows IIRC. Since Twisted is very layered what happens at a lower level is actually unknown to the upper layers. So yes, twisted is not yet ready for IPv6, but implementing it won't brake anything (unless you use IPv6 by default). Maybe providing connectTCP6 could be a solution. -- Valentino Volonghi aka Dialtone Linux User #310274, Proud Gentoo User Blog: http://vvolonghi.blogspot.com Home Page: http://xoomer.virgilio.it/dialtone/
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Thu, 30 Sep 2004 10:12:18 +0200, Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de> wrote:
Hi!
I'm curious: how much work would it be to enable IPv6 support in twisted.internet?
Not very much. About a year ago, I wrote this: http://cvs.twistedmatrix.com/cvs/trunk/sandbox/exarkun/ipv6.py?view=markup&rev=10540&root=Twisted This is no longer how I'd like to see IPv6 supported in Twisted, but it gives an idea of how few changes are required. Jp
![](https://secure.gravatar.com/avatar/1833d9a7642a05ddea0d27de72be2e2b.jpg?s=120&d=mm&r=g)
exarkun@divmod.com schrieb:
That really doesn't seem to be a big change in the current code base. It's not very object oriented, though, so as you said, it would have to be rewritten to integrate it with Twisted. However, I think the address handling would be a thing worth generalizing. I found this on the web: http://c0re.23.nu/c0de/IPy/ I already had to adapt it a bit as some code parts are somewhat clumsy, but I find it a nice abstraction for IP addresses. If such a thing was part of Twisted, the interfaces for handling IPv[46] could become completely transparent. You could even cut them into the existing interfaces: ----------------------------------------- from IPy import IP def connectTCP(host, port, ...) if isinstance(host, str): ... # use original IPv4 implementation - or convert host to IP(host) elif isinstance(host, IP): ... # connect either with IPv4 or IPv6, depending on host.version() ----------------------------------------- Stefan
![](https://secure.gravatar.com/avatar/77d03707d9cd7b54103dca504be78ed3.jpg?s=120&d=mm&r=g)
On Thu, 30 Sep 2004 10:12:18 +0200, Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de> wrote:
Hi!
I'm curious: how much work would it be to enable IPv6 support in twisted.internet?
I get a number of references to IPv4 that make me believe that t.i.* is not quite IPv6 clean by itself:
That a new reactor would solve nothing since the reactor is not the responsible for connections. Connection.py and tcp.py are the modules you are looking for (those that create the connection). Also there's a problem if you only write a new reactor, that IPv6 couldn't be used in other reactors, which is bad :). I'd rather hack on tcp.py and Connection.py and address.py (all in twisted.internet). Those sockets that you see in default.py are to wake up the main thread under windows IIRC. Since Twisted is very layered what happens at a lower level is actually unknown to the upper layers. So yes, twisted is not yet ready for IPv6, but implementing it won't brake anything (unless you use IPv6 by default). Maybe providing connectTCP6 could be a solution. -- Valentino Volonghi aka Dialtone Linux User #310274, Proud Gentoo User Blog: http://vvolonghi.blogspot.com Home Page: http://xoomer.virgilio.it/dialtone/
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Thu, 30 Sep 2004 10:12:18 +0200, Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de> wrote:
Hi!
I'm curious: how much work would it be to enable IPv6 support in twisted.internet?
Not very much. About a year ago, I wrote this: http://cvs.twistedmatrix.com/cvs/trunk/sandbox/exarkun/ipv6.py?view=markup&rev=10540&root=Twisted This is no longer how I'd like to see IPv6 supported in Twisted, but it gives an idea of how few changes are required. Jp
![](https://secure.gravatar.com/avatar/1833d9a7642a05ddea0d27de72be2e2b.jpg?s=120&d=mm&r=g)
exarkun@divmod.com schrieb:
That really doesn't seem to be a big change in the current code base. It's not very object oriented, though, so as you said, it would have to be rewritten to integrate it with Twisted. However, I think the address handling would be a thing worth generalizing. I found this on the web: http://c0re.23.nu/c0de/IPy/ I already had to adapt it a bit as some code parts are somewhat clumsy, but I find it a nice abstraction for IP addresses. If such a thing was part of Twisted, the interfaces for handling IPv[46] could become completely transparent. You could even cut them into the existing interfaces: ----------------------------------------- from IPy import IP def connectTCP(host, port, ...) if isinstance(host, str): ... # use original IPv4 implementation - or convert host to IP(host) elif isinstance(host, IP): ... # connect either with IPv4 or IPv6, depending on host.version() ----------------------------------------- Stefan
participants (3)
-
exarkun@divmod.com
-
Stefan Behnel
-
Valentino Volonghi