pidgin: b00671a2: A direct connection really has no need o...

qulogic at pidgin.im qulogic at pidgin.im
Tue Jan 4 04:15:52 EST 2011


----------------------------------------------------------------------
Revision: b00671a28695c8a525112a0558c2d546d6db9a48
Parent:   02cd528247060ac811ed7047c6ff2bcb34d0db5c
Author:   qulogic at pidgin.im
Date:     01/04/11 04:12:59
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b00671a28695c8a525112a0558c2d546d6db9a48

Changelog: 

A direct connection really has no need of the whole P2P packet header,
and there's no need to shoehorn the nonce negotiation into one either.

Changes against parent 02cd528247060ac811ed7047c6ff2bcb34d0db5c

  patched  libpurple/protocols/msn/directconn.c
  patched  libpurple/protocols/msn/directconn.h
  patched  libpurple/protocols/msn/p2p.h

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/directconn.c	eaf77bfcfdae39a3a7d86c4a1b6c9d88ae3d55f3
+++ libpurple/protocols/msn/directconn.c	f31662c261565b14d6e76406eb978d72930784b7
@@ -27,6 +27,7 @@
 #include "debug.h"
 
 #include "msn.h"
+#include "msnutils.h"
 #include "directconn.h"
 
 #include "slp.h"
@@ -442,48 +443,43 @@ msn_dc_send_foo(MsnDirectConn *dc)
 	msn_dc_enqueue_packet(dc, p);
 }
 
-static void
-msn_dc_send_handshake_with_nonce(MsnDirectConn *dc, MsnDirectConnPacket *p)
-{
-	const gchar *h;
+#if 0 /* We don't actually need this */
+typedef struct {
+	guint32 null;
+	guint32 id;
+	guint32 null[5];
+	guint32 flags;
+	guint8  nonce[16];
+} MsnDirectConnNoncePacket;
+#endif
+#define DC_NONCE_PACKET_SIZE (8 * 4 + 16)
+#define DC_NONCE_PACKET_NONCE (8 * 4)
 
-	h = msn_p2p_header_to_wire(&dc->header);
-
-	memcpy(p->data, h, P2P_PACKET_HEADER_SIZE);
-
-	memcpy(p->data + P2P_HEADER_ACK_ID_OFFSET, dc->nonce, 16);
-
-	msn_dc_enqueue_packet(dc, p);
-}
-
 static void
 msn_dc_send_handshake(MsnDirectConn *dc)
 {
 	MsnDirectConnPacket *p;
+	gchar *h;
 
-	p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
+	p = msn_dc_new_packet(DC_NONCE_PACKET_SIZE);
+	h = (gchar *)p->data;
 
-	dc->header.session_id = 0;
-	dc->header.id = dc->slpcall->slplink->slp_seq_id++;
-	dc->header.offset = 0;
-	dc->header.total_size = 0;
-	dc->header.length = 0;
-	dc->header.flags = 0x100;
+	msn_push32le(h, 0); /* NUL */
 
-	msn_dc_send_handshake_with_nonce(dc, p);
-}
+	msn_push32le(h, dc->slpcall->slplink->slp_seq_id++);
 
-static void
-msn_dc_send_handshake_reply(MsnDirectConn *dc)
-{
-	MsnDirectConnPacket *p;
+	/* More NUL stuff */
+	msn_push64le(h, 0);
+	msn_push64le(h, 0);
+	msn_push32le(h, 0);
 
-	p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
+	/* Flags */
+	msn_push32le(h, P2P_DC_HANDSHAKE);
 
-	dc->header.id = dc->slpcall->slplink->slp_seq_id++;
-	dc->header.length = 0;
+	/* The real Nonce, yay! */
+	memcpy(h, dc->nonce, 16);
 
-	msn_dc_send_handshake_with_nonce(dc, p);
+	msn_dc_enqueue_packet(dc, p);
 }
 
 static gboolean
@@ -492,10 +488,10 @@ msn_dc_verify_handshake(MsnDirectConn *d
 	guchar nonce[16];
 	gchar  nonce_hash[37];
 
-	if (packet_length != P2P_PACKET_HEADER_SIZE)
+	if (packet_length != DC_NONCE_PACKET_SIZE)
 		return FALSE;
 
-	memcpy(nonce, dc->in_buffer + 4 + P2P_HEADER_ACK_ID_OFFSET, 16);
+	memcpy(nonce, dc->in_buffer + 4 + DC_NONCE_PACKET_NONCE, 16);
 
 	if (dc->nonce_type == DC_NONCE_PLAIN) {
 		if (memcmp(dc->nonce, nonce, 16) == 0) {
@@ -580,7 +576,7 @@ msn_dc_process_packet(MsnDirectConn *dc,
 		if (!msn_dc_verify_handshake(dc, packet_length))
 			return DC_PROCESS_FALLBACK;
 
-		msn_dc_send_handshake_reply(dc);
+		msn_dc_send_handshake(dc);
 		dc->state = DC_STATE_ESTABLISHED;
 
 		msn_slpcall_session_init(dc->slpcall);
@@ -595,12 +591,12 @@ msn_dc_process_packet(MsnDirectConn *dc,
 
 		msn_slpcall_session_init(dc->slpcall);
 		dc->slpcall = NULL;
+		msn_dc_send_foo(dc);
 		break;
 
 	case DC_STATE_ESTABLISHED:
-
-		if (dc->header.length) {
-			part = msn_slpmsgpart_new_from_data(dc->in_buffer + 4, dc->header.length);
+		if (packet_length) {
+			part = msn_slpmsgpart_new_from_data(dc->in_buffer + 4, packet_length);
 			if (part) {
 				msn_slplink_process_msg(dc->slplink, part);
 				msn_slpmsgpart_unref(part);
@@ -676,15 +672,6 @@ msn_dc_recv_cb(gpointer data, gint fd, P
 		if (dc->in_pos < 4 + packet_length)
 			return;
 
-		if (dc->state != DC_STATE_FOO && packet_length >= P2P_PACKET_HEADER_SIZE) {
-			MsnP2PHeader *context;
-
-			/* Skip packet size */
-			context = msn_p2p_header_from_wire(dc->in_buffer + 4);
-			memcpy(&dc->header, context, P2P_PACKET_HEADER_SIZE);
-			g_free(context);
-		}
-
 		switch (msn_dc_process_packet(dc, packet_length)) {
 		case DC_PROCESS_CLOSE:
 			return;
============================================================
--- libpurple/protocols/msn/directconn.h	923ada12252e83e6cd10f0f0dac7bb4d557aaddb
+++ libpurple/protocols/msn/directconn.h	d9c7d7aab49519bbbe1ff8f232dc6e0df372799b
@@ -103,8 +103,6 @@ struct _MsnDirectConn
 	GQueue  *out_queue; /**< The outgoing packet queue */
 	int     msg_pos;    /**< The position of next byte to be sent in the actual packet */
 
-	MsnP2PHeader    header; /**< SLP header for parsing / serializing */
-
 	/** The callback used for sending information to the peer about the opened socket */
 	void (*send_connection_info_msg_cb)(MsnDirectConn *);
 
============================================================
--- libpurple/protocols/msn/p2p.h	0c62eb6798172049d9e43bc0ee4471fee08ab378
+++ libpurple/protocols/msn/p2p.h	03cb80ab4aebbc45cefb549907d3c1e732e8863c
@@ -45,9 +45,6 @@ typedef struct {
 } MsnP2PHeader;
 #define P2P_PACKET_HEADER_SIZE (6 * 4 + 3 * 8)
 
-/* Used for DCs to store nonces */
-#define P2P_HEADER_ACK_ID_OFFSET (2*4 + 2*8 + 2*4)
-
 typedef struct {
 	guint8  header_len;
 	guint8  opcode;


More information about the Commits mailing list