[Telepathy-commits] [telepathy-salut/master] Tubes: check that the incoming connection on a tube comes from an IP advertised by the SalutContact. Update the test suite

Alban Crequy alban.crequy at collabora.co.uk
Tue Nov 25 03:59:28 PST 2008


---
 src/salut-direct-bytestream-manager.c |   44 +++++++++++++++++++++++++++++++++
 tests/twisted/avahi/test-tube.py      |   13 +++++++++-
 2 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/src/salut-direct-bytestream-manager.c b/src/salut-direct-bytestream-manager.c
index 3d7381a..ab7b44a 100644
--- a/src/salut-direct-bytestream-manager.c
+++ b/src/salut-direct-bytestream-manager.c
@@ -238,6 +238,46 @@ salut_direct_bytestream_manager_new (SalutConnection *conn)
       NULL);
 }
 
+static gboolean
+check_bytestream_direct_peer_addr (GibberBytestreamDirect *bytestream,
+                                   struct sockaddr_storage *addr,
+                                   socklen_t addrlen,
+                                   gpointer user_data)
+{
+  SalutDirectBytestreamManager *self =
+    SALUT_DIRECT_BYTESTREAM_MANAGER (user_data);
+  SalutDirectBytestreamManagerPrivate *priv =
+    SALUT_DIRECT_BYTESTREAM_MANAGER_GET_PRIVATE (self);
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) priv->connection, TP_HANDLE_TYPE_CONTACT);
+  TpHandle handle;
+  SalutContactManager *contact_mgr;
+  SalutContact *contact;
+  gchar *peer;
+  gboolean result;
+
+  g_object_get (bytestream, "peer-id", &peer, NULL);
+  g_assert (peer != NULL);
+
+  handle = tp_handle_lookup (contact_repo, peer, NULL, NULL);
+  g_assert (handle != 0);
+  g_free (peer);
+
+  g_object_get (priv->connection, "contact-manager", &contact_mgr, NULL);
+  g_assert (contact_mgr != NULL);
+
+  contact = salut_contact_manager_get_contact (contact_mgr, handle);
+  g_object_unref (contact_mgr);
+  if (contact == NULL)
+    return FALSE;
+
+  result = salut_contact_has_address (contact, addr);
+  g_object_unref (contact);
+
+  return result;
+}
+
+
 /* callback when receiving a connection from the remote CM */
 static gboolean
 listener_io_in_cb (GIOChannel *source,
@@ -259,6 +299,10 @@ listener_io_in_cb (GIOChannel *source,
       "peer-id", data->contact->name,
       NULL);
 
+  gibber_bytestream_direct_set_check_addr_func (
+      GIBBER_BYTESTREAM_DIRECT (bytestream), check_bytestream_direct_peer_addr,
+      data->mgr);
+
   /* call this before accepting the socket, in order to let the opportunity to
    * register a callback for the "new-connection" bytestream's signal. */
   data->cb (bytestream, data->user_data);
diff --git a/tests/twisted/avahi/test-tube.py b/tests/twisted/avahi/test-tube.py
index 3a42e2f..9720b2b 100644
--- a/tests/twisted/avahi/test-tube.py
+++ b/tests/twisted/avahi/test-tube.py
@@ -118,8 +118,19 @@ def test(q, bus, conn):
                       'u': ('uint', '123'),
                      }, params
 
+    # find the right host/IP address because Salut checks it
+    self_handle = conn.GetSelfHandle()
+    self_handle_name =  conn.InspectHandles(HT_CONTACT, [self_handle])[0]
+    AvahiListener(q).listen_for_service("_presence._tcp")
+    e = q.expect('service-added', name = self_handle_name,
+        protocol = avahi.PROTO_INET)
+    service = e.service
+    service.resolve()
+    e = q.expect('service-resolved', service = service)
+    host_name = e.host_name
+
     client = ClientCreator(reactor, ClientGreeter)
-    client.connectTCP("localhost", port).addCallback(client_connected_cb)
+    client.connectTCP(host_name, port).addCallback(client_connected_cb)
 
     e = q.expect('client-connected')
     client_transport = e.transport
-- 
1.5.6.5




More information about the Telepathy-commits mailing list