Author: ArcRiley
Date: 2009-01-03 17:18:55 -0500 (Sat, 03 Jan 2009)
New Revision: 1413

Modified:
   trunk/concordance/src/Core.c
Log:
Further network code cleanup and comments


Modified: trunk/concordance/src/Core.c
===================================================================
--- trunk/concordance/src/Core.c        2009-01-03 21:50:34 UTC (rev 1412)
+++ trunk/concordance/src/Core.c        2009-01-03 22:18:55 UTC (rev 1413)
@@ -51,10 +51,33 @@
       conCoreObject*    self = (conCoreObject*) s;
       static char*      kwlist[] = {"client", "server", 0};
 
-    /* set defaults for optional arguments */
+    /* set defaults for optional arguments
+
+       0.0.0.0 listens on every IP interface
+
+       xmpp-client     5222/tcp                        # XMPP Client Connection
+       xmpp-server     5269/tcp                        # XMPP Server Connection
+
+       XEP-0035 (SSL/TLS Integration) :
+         Traditionally, Jabber servers has supported TLS by utilising a 
+         "wrapper" around the standard protocol stream. This wrapper usually 
+         listens on a port other than those listed in the IANA registry  
+         (commonly 5223 for client-to-server communications and 5270 for 
+         server-to-server communications). In the case of client-to-server 
+         communications, clients must initiate a TLS session immediately after 
+         connecting, before beginning the normal XML stream. This method of 
+         utilising TLS is typical of many servers that implement stream-based 
+         protocols, but has a number of flaws, which are outlined in section 7 
+         of RFC 2595. Accordingly, the use of port 5223 and port 5270 for 
+         secure sessions is deprecated.
+
+       Thus, we use only two listening sockets; one for clients, one for 
+       servers.  If additional ports are required (ie, for IPv6 support) it's
+       recommended to run multiple servers or one server with multiple cores.
+    */
     self->c2s.addr = "0.0.0.0";
+    self->s2s.addr = "0.0.0.0";
     self->c2s.port = 5222;
-    self->s2s.addr = "0.0.0.0";
     self->s2s.port = 5269;
 
     /* parse arguments and keywords */
@@ -94,98 +117,6 @@
     PyObject_Del(self);
   }
 
-  static int opensocket(conSocket sock) {                                 /*\
-    cdef :                                                                \*/
-      int                ret;
-      struct addrinfo*   resinfo = NULL;
-
-    /* Get address family and struct
-
-       int getaddrinfo(const char *node, const char *service,
-                       const struct addrinfo *hints,
-                       struct addrinfo **res);
-       getaddrinfo() returns  0  if it succeeds, or non-zero on failure.
-    */
-    ret = getaddrinfo(sock.addr, NULL, NULL, &resinfo);
-    if (ret != 0) {
-      switch (ret) {
-        case EAI_AGAIN : 
-          /* EAI_AGAIN
-              The  name  server  returned a temporary failure indication.  Try
-              again later. */
-          PyErr_SetString(PyExc_OSError, "temporary dns failure");
-        case EAI_FAIL : 
-          /* EAI_FAIL
-              The name server returned a permanent failure indication. */
-          PyErr_SetString(PyExc_OSError, "permanent dns failure");
-        case EAI_FAMILY :
-          /* EAI_FAMILY
-              The requested address family is not supported. */
-          PyErr_SetString(PyExc_OSError, "address family not supported");
-        case EAI_MEMORY :
-          /* EAI_MEMORY
-              Out of memory. */
-          PyErr_SetString(PyExc_MemoryError, "out of memory on getaddrinfo");
-        case EAI_NODATA :
-          /* EAI_NODATA
-              The specified network host exists, but does not have any network
-              addresses defined. */
-          PyErr_SetString(PyExc_AttributeError, "host lacks IP address");
-        default :
-          PyErr_SetString(PyExc_AttributeError, "invalid address/hostname");
-      }
-      return 0;
-    }
-
-    /* Copy port into sockaddr struct
-
-       uint16_t htons(uint16_t hostshort);
-         The htons() function converts the unsigned short integer hostshort 
-         from host byte order to network byte order.
-    */
-    ((struct sockaddr_in*) resinfo->ai_addr)->sin_port = htons(sock.port);
-
-    /* Open new socket of the appropriate family (AF_INET or AF_INET6)
-
-       int socket(int domain, int type, int protocol);
-    */
-    sock.sock = socket(resinfo->ai_family, SOCK_STREAM, 0);
-
-    /* If successful continue to bind/listen, else set error message */
-    if (sock.sock > -1) {
-      /* Bind and Listen to opened socket
-
-         int bind(int sockfd, const struct sockaddr *addr, 
-                  socklen_t addrlen);
-           On success, zero is returned.  On error, -1 is returned.
-
-         int listen(int sockfd, int backlog);
-           On  success,  zero is returned.  On error, -1 is returned.
-      */
-      if (bind(sock.sock, resinfo->ai_addr, resinfo->ai_addrlen) == 0 &&
-          listen(sock.sock, 16) == 0 )
-        ret = 1;
-      else {
-        PyErr_SetString(PyExc_OSError, "unable to bind listening socket");
-        ret = 0;
-      }
-    } 
-    else {
-      PyErr_SetString(PyExc_OSError, "unable to bind listening socket");
-      ret = 0;
-    }
-
-    /* before returning, free the previously created resinfo struct
-
-       void freeaddrinfo(struct addrinfo *res);
-    */
-    if (resinfo)
-      freeaddrinfo(resinfo);
-
-    return ret;
-  }
-
-
   static PyMethodDef conCore_methods[] = {
     { NULL, NULL },
   };
@@ -234,3 +165,99 @@
     0,                                 /*tp_free*/
     0,                                 /*tp_is_gc*/
   };
+
+
+
+/***************************************************************************\
+ * Core helper functions                                                   */
+
+static int opensocket(conSocket sock) {                                   /*\
+  cdef :                                                                  \*/
+    int                ret;
+    struct addrinfo*   resinfo = NULL;
+
+  /* Get address family and struct
+
+     int getaddrinfo(const char *node, const char *service,
+                     const struct addrinfo *hints,
+                     struct addrinfo **res);
+     getaddrinfo() returns  0  if it succeeds, or non-zero on failure.
+  */
+  ret = getaddrinfo(sock.addr, NULL, NULL, &resinfo);
+  if (ret != 0) {
+    switch (ret) {
+      case EAI_AGAIN : 
+        /* EAI_AGAIN
+            The  name  server  returned a temporary failure indication.
+            Try again later. */
+        PyErr_SetString(PyExc_OSError, "temporary dns failure");
+      case EAI_FAIL : 
+        /* EAI_FAIL
+            The name server returned a permanent failure indication. */
+        PyErr_SetString(PyExc_OSError, "permanent dns failure");
+      case EAI_FAMILY :
+        /* EAI_FAMILY
+            The requested address family is not supported. */
+        PyErr_SetString(PyExc_OSError, "address family not supported");
+      case EAI_MEMORY :
+        /* EAI_MEMORY
+            Out of memory. */
+        PyErr_SetString(PyExc_MemoryError, "out of memory on getaddrinfo");
+      case EAI_NODATA :
+        /* EAI_NODATA
+            The specified network host exists, but does not have any
+            network addresses defined. */
+        PyErr_SetString(PyExc_AttributeError, "host lacks IP address");
+      default :
+        PyErr_SetString(PyExc_AttributeError, "invalid address/hostname");
+    }
+    return 0;
+  }
+
+  /* Copy port into sockaddr struct
+
+     uint16_t htons(uint16_t hostshort);
+       The htons() function converts the unsigned short integer hostshort 
+       from host byte order to network byte order.
+  */
+  ((struct sockaddr_in*) resinfo->ai_addr)->sin_port = htons(sock.port);
+
+  /* Open new socket of the appropriate family (AF_INET or AF_INET6)
+
+     int socket(int domain, int type, int protocol);
+  */
+  sock.sock = socket(resinfo->ai_family, SOCK_STREAM, 0);
+
+  /* If successful continue to bind/listen, else set error message */
+  if (sock.sock > -1) {
+    /* Bind and Listen to opened socket
+
+       int bind(int sockfd, const struct sockaddr *addr, 
+                socklen_t addrlen);
+         On success, zero is returned.  On error, -1 is returned.
+
+       int listen(int sockfd, int backlog);
+         On  success,  zero is returned.  On error, -1 is returned.
+    */
+    if (bind(sock.sock, resinfo->ai_addr, resinfo->ai_addrlen) == 0 &&
+        listen(sock.sock, 16) == 0 )
+      ret = 1;
+    else {
+      PyErr_SetString(PyExc_OSError, "unable to bind listening socket");
+      ret = 0;
+    }
+  } 
+  else {
+    PyErr_SetString(PyExc_OSError, "unable to bind listening socket");
+    ret = 0;
+  }
+
+  /* before returning, free the previously created resinfo struct
+
+     void freeaddrinfo(struct addrinfo *res);
+  */
+  if (resinfo)
+    freeaddrinfo(resinfo);
+
+  return ret;
+}

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to