[CalendarServer-changes] [9087] CalendarServer/branches/users/glyph/ipv6-client/twext/internet
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 13 11:46:42 PDT 2012
Revision: 9087
http://trac.macosforge.org/projects/calendarserver/changeset/9087
Author: glyph at apple.com
Date: 2012-04-13 11:46:42 -0700 (Fri, 13 Apr 2012)
Log Message:
-----------
Add SSL support to GAIEndpoint.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/ipv6-client/twext/internet/gaiendpoint.py
CalendarServer/branches/users/glyph/ipv6-client/twext/internet/test/test_gaiendpoint.py
Modified: CalendarServer/branches/users/glyph/ipv6-client/twext/internet/gaiendpoint.py
===================================================================
--- CalendarServer/branches/users/glyph/ipv6-client/twext/internet/gaiendpoint.py 2012-04-13 18:46:37 UTC (rev 9086)
+++ CalendarServer/branches/users/glyph/ipv6-client/twext/internet/gaiendpoint.py 2012-04-13 18:46:42 UTC (rev 9087)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twext.internet.test.test_gaiendpoint -*-
##
# Copyright (c) 2012 Apple Inc. All rights reserved.
#
@@ -19,7 +20,7 @@
"""
from socket import getaddrinfo, AF_UNSPEC, AF_INET, AF_INET6, SOCK_STREAM
-from twisted.internet.endpoints import TCP4ClientEndpoint # misnamed :-(
+from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint
from twisted.internet.defer import Deferred
from twisted.internet.threads import deferToThread
from twisted.internet.task import LoopingCall
@@ -48,20 +49,43 @@
@ivar deferToThread: A function like L{deferToThread}, used to invoke
getaddrinfo. (Replaceable mainly for testing purposes.)
-
- @ivar subEndpoint: A 3-argument callable taking C{(reactor (IReactorTCP),
- host (str), port (int))} where 'host' is an IP address literal, either
- IPv6 or IPv6.
"""
deferToThread = staticmethod(deferToThread)
- subEndpoint = TCP4ClientEndpoint
+ def subEndpoint(self, reactor, host, port, contextFactory):
+ """
+ Create an endpoint to connect to based on a single address result from
+ L{getaddrinfo}.
- def __init__(self, reactor, host, port):
+ @param reactor: the reactor to connect to
+ @type reactor: L{IReactorTCP}
+
+ @param host: The IP address of the host to connect to, in presentation
+ format.
+ @type host: L{str}
+
+ @param port: The numeric port number to connect to.
+ @type port: L{int}
+
+ @param contextFactory: If not L{None}, the OpenSSL context factory to
+ use to produce client connections.
+
+ @return: a stream client endpoint that will connect to the given host
+ and port via the given reactor.
+ @rtype: L{IStreamClientEndpoint}
+ """
+ if contextFactory is None:
+ return TCP4ClientEndpoint(reactor, host, port)
+ else:
+ return SSL4ClientEndpoint(reactor, host, port, contextFactory)
+
+
+ def __init__(self, reactor, host, port, contextFactory=None):
self.reactor = reactor
self.host = host
self.port = port
+ self.contextFactory = contextFactory
def connect(self, factory):
@@ -72,7 +96,7 @@
for family, socktype, proto, canonname, sockaddr in gairesult:
if family in [AF_INET6, AF_INET]:
yield self.subEndpoint(self.reactor, sockaddr[0],
- sockaddr[1])
+ sockaddr[1], self.contextFactory)
@gaiToEndpoints.addCallback
def connectTheEndpoints(endpoints):
Modified: CalendarServer/branches/users/glyph/ipv6-client/twext/internet/test/test_gaiendpoint.py
===================================================================
--- CalendarServer/branches/users/glyph/ipv6-client/twext/internet/test/test_gaiendpoint.py 2012-04-13 18:46:37 UTC (rev 9086)
+++ CalendarServer/branches/users/glyph/ipv6-client/twext/internet/test/test_gaiendpoint.py 2012-04-13 18:46:42 UTC (rev 9087)
@@ -28,11 +28,12 @@
class FakeTCPEndpoint(object):
- def __init__(self, reactor, host, port):
+ def __init__(self, reactor, host, port, contextFactory):
self._reactor = reactor
self._host = host
self._port = port
self._attempt = None
+ self._contextFactory = contextFactory
def connect(self, factory):
@@ -54,8 +55,8 @@
return gaie
- def subEndpoint(self, reactor, host, port):
- ftcpe = FakeTCPEndpoint(reactor, host, port)
+ def subEndpoint(self, reactor, host, port, contextFactory):
+ ftcpe = FakeTCPEndpoint(reactor, host, port, contextFactory)
self.fakeRealEndpoints.append(ftcpe)
return ftcpe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120413/db5d79da/attachment-0001.html>
More information about the calendarserver-changes
mailing list