Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

vmsg.c File Reference


Detailed Description

Vendor-specific messages.

Author:
Raphael Manfredi
Date:
2003

#include "common.h"
#include "vmsg.h"
#include "nodes.h"
#include "search.h"
#include "gmsg.h"
#include "routing.h"
#include "gnet_stats.h"
#include "dq.h"
#include "udp.h"
#include "settings.h"
#include "guid.h"
#include "inet.h"
#include "oob.h"
#include "mq.h"
#include "mq_udp.h"
#include "clock.h"
#include "tsync.h"
#include "hosts.h"
#include "pmsg.h"
#include "if/gnet_property_priv.h"
#include "lib/endian.h"
#include "lib/glib-missing.h"
#include "lib/tm.h"
#include "lib/vendors.h"
#include "lib/override.h"

Data Structures

struct  vmsg
 Definition of vendor messages. More...

struct  vms_item
 Items in the "Messages Supported" vector. More...

struct  vms_feature
 Items in the "Features Supported" vector. More...


Defines

#define VMS_ITEM_SIZE   8 /**< Each entry is 8 bytes (4+2+2) */
 Each entry is 8 bytes (4+2+2).

#define VMS_FEATURE_SIZE   6 /**< Each entry is 6 bytes (4+2) */
 Each entry is 6 bytes (4+2).

#define PAIR_CMP(x, y, a0, a1, b0, b1)
#define GET_KEY(i)   (&vmsg_map[(i)])
#define FOUND(i)
#define COMPARE(item, key)
#define COMPARE(it, o)

Typedefs

typedef void(* vmsg_handler_t )(struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)

Functions

 RCSID ("$Id:vmsg.c, v 1.52 2005/11/12 12:04:34 cbiere Exp $")
void handle_messages_supported (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle the "Messages Supported" message.

void handle_features_supported (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle the "Features Supported" message.

void handle_hops_flow (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle the "Hops Flow" message.

void handle_tcp_connect_back (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle the "TCP Connect Back" message.

void handle_udp_connect_back (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle the \"UDP Connect Back" message.

void handle_proxy_req (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of the "Push Proxy Request" message.

void handle_proxy_ack (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of the "Push Proxy Acknowledgment" message.

void handle_qstat_req (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of "Query Status Request", where the UP requests how many results the search filters of the leave (ourselves) let pass through.

void handle_qstat_answer (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle "Query Status Response" where the leave notifies us about the amount of results its search filters let pass through for the specified query.

void handle_proxy_cancel (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of "Push Proxy Cancel" request, when remote node no longer wishes to have us as a push-proxy.

void handle_oob_reply_ind (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of an "OOB Reply Indication" message, whereby the remote host informs us about the amount of query hits it has for us for a given query.

void handle_oob_reply_ack (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of an "OOB Reply Ack" message, whereby the remote host informs us about the amount of query hits it wants delivered for the query identified by the MUID of the message.

void handle_time_sync_req (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of a "Time Sync Request" message, indicating a request from another host about time synchronization.

void handle_time_sync_reply (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of a "Time Sync Reply" message, holding the reply from a previous time synchronization request.

void handle_udp_crawler_ping (struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 Handle reception of an UDP crawler ping.

const struct vmsgfind_message (union vendor_code vc, guint16 id, guint16 version)
 Find message, given vendor code, and id, version.

const gchar * vmsg_infostr (gconstpointer data, gint size)
 Decompiles vendor-message name given the data payload of the Gnutella message and its size.

void vmsg_handle (struct gnutella_node *n)
 Main entry point to handle reception of vendor-specific message.

guint32 vmsg_fill_header (struct gnutella_header *header, guint32 size, guint32 maxsize)
 Fill common message header part for all vendor-specific messages.

gchar * vmsg_fill_type (struct gnutella_vendor *base, guint32 vendor, guint16 id, guint16 version)
 Fill leading part of the payload data, containing the common part for all vendor-specific messages.

void vmsg_bad_payload (struct gnutella_node *n, const struct vmsg *vmsg, gint size, gint expected)
 Report a vendor-message with bad payload to the stats.

void vmsg_send_messages_supported (struct gnutella_node *n)
 Send a "Messages Supported" message to specified node, telling it which subset of the vendor messages we can understand.

void vmsg_send_hops_flow (struct gnutella_node *n, guint8 hops)
 Send an "Hops Flow" message to specified node.

void vmsg_send_tcp_connect_back (struct gnutella_node *n, guint16 port)
 Send a "TCP Connect Back" message to specified node, telling it to connect back to us on the specified port.

void vmsg_send_udp_connect_back (struct gnutella_node *n, guint16 port)
 Send a "UDP Connect Back" message to specified node, telling it to ping us back via UDP on the specified port.

void vmsg_send_proxy_ack (struct gnutella_node *n, gchar *muid, gint version)
 Send a "Push Proxy Acknowledgment" message to specified node, using supplied `muid' as the message ID (which is the target node's GUID).

void vmsg_send_proxy_req (struct gnutella_node *n, const gchar *muid)
 Send a "Push Proxy Request" message to specified node, using supplied `muid' as the message ID (which is our GUID).

void vmsg_send_qstat_req (struct gnutella_node *n, gchar *muid)
 Send a "Query Status Request" message to specified node, using supplied `muid' as the message ID (which is the query ID).

void vmsg_send_qstat_answer (struct gnutella_node *n, gchar *muid, guint16 hits)
 Send a "Query Status Response" message to specified node.

void vmsg_send_proxy_cancel (struct gnutella_node *n)
 Send a "Push Proxy Cancel" message to specified node.

pmsg_tvmsg_build_oob_reply_ind (gchar *muid, guint8 hits)
 Build an "OOB Reply Indication" message.

void vmsg_send_oob_reply_ack (struct gnutella_node *n, gchar *muid, guint8 want)
 Send an "OOB Reply Ack" message to specified node, informing it that we want the specified amount of hits delivered for the query identified by the MUID of the message we got (the "OOB Reply Indication").

gboolean vmsg_time_sync_req_stamp (pmsg_t *mb, const struct mqueue *unused_q)
 Callback invoked when "Time Sync Request" is about to be sent.

void vmsg_send_time_sync_req (struct gnutella_node *n, gboolean ntp, tm_t *sent)
 Send a "Time Sync Request" message, asking them to echo back their own time so that we can compute our clock differences and measure round trip times.

gboolean vmsg_time_sync_reply_stamp (pmsg_t *mb, const struct mqueue *unused_q)
 Callback invoked when "Time Sync Reply" is about to be sent.

void vmsg_send_time_sync_reply (struct gnutella_node *n, gboolean ntp, tm_t *got)
 Send a "Time Sync Reply" message to the node, including the time at which we send back the message in the second half of the MUID.

void vmsg_send_udp_crawler_pong (struct gnutella_node *n, pmsg_t *mb)
 Send UDP crawler pong, in reply to their ping.

void vmsg_map_is_sorted (void)
 Assert that the vmsg_map[] array is sorted.

void vmsg_init (void)
 Initialize vendor messages.


Variables

gchar v_tmp [4128]
 Large enough for a payload of 4K.

const struct vmsg vmsg_map []
 Known vendor-specific messages.


Define Documentation

#define COMPARE it,
 ) 
 

Value:

(0 != (c_vendor = VENDOR_CODE_CMP((it)->vendor, (o)->vendor)) \
        ? c_vendor \
        : PAIR_CMP(c_id, c_version, \
            (it)->id, (o)->id, (it)->version, (o)->version))

#define COMPARE item,
key   ) 
 

Value:

0 != (c_vendor = VENDOR_CODE_CMP((item)->key, key)) \
        ? c_vendor \
        : PAIR_CMP(c_id, c_version, (item)->id, id, (item)->version, version)

#define FOUND  ) 
 

Value:

G_STMT_START { \
    return &vmsg_map[(i)];      \
    /* NOTREACHED */            \
} G_STMT_END

#define GET_KEY  )     (&vmsg_map[(i)])
 

#define PAIR_CMP x,
y,
a0,
a1,
b0,
b1   ) 
 

Value:

( \
  (x = CMP(a0, a1)) \
    ? x \
    : (y = CMP(b0, b1)) \
            ? y \
            : 0 \
)

#define VMS_FEATURE_SIZE   6 /**< Each entry is 6 bytes (4+2) */
 

Each entry is 6 bytes (4+2).

#define VMS_ITEM_SIZE   8 /**< Each entry is 8 bytes (4+2+2) */
 

Each entry is 8 bytes (4+2+2).


Typedef Documentation

typedef void(* vmsg_handler_t)(struct gnutella_node *n, const struct vmsg *vmsg, gchar *payload, gint size)
 


Function Documentation

const struct vmsg* find_message union vendor_code  vc,
guint16  id,
guint16  version
[static]
 

Find message, given vendor code, and id, version.

Returns:
handler callback if found, NULL otherwise.

void handle_features_supported struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle the "Features Supported" message.

void handle_hops_flow struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle the "Hops Flow" message.

void handle_messages_supported struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle the "Messages Supported" message.

void handle_oob_reply_ack struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle reception of an "OOB Reply Ack" message, whereby the remote host informs us about the amount of query hits it wants delivered for the query identified by the MUID of the message.

void handle_oob_reply_ind struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle reception of an "OOB Reply Indication" message, whereby the remote host informs us about the amount of query hits it has for us for a given query.

The message bears the MUID of the query we sent out.

void handle_proxy_ack struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle reception of the "Push Proxy Acknowledgment" message.

Version 1 only bears the port. The IP address must be gathered from n->addr. Version 2 holds both the IP and port of our push-proxy.

void handle_proxy_cancel struct gnutella_node n,
const struct vmsg vmsg,
gchar *  unused_payload,
gint  size
[static]
 

Handle reception of "Push Proxy Cancel" request, when remote node no longer wishes to have us as a push-proxy.

This is an indication that the host determined it was not TCP-firewalled.

void handle_proxy_req struct gnutella_node n,
const struct vmsg vmsg,
gchar *  unused_payload,
gint  size
[static]
 

Handle reception of the "Push Proxy Request" message.

void handle_qstat_answer struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle "Query Status Response" where the leave notifies us about the amount of results its search filters let pass through for the specified query.

void handle_qstat_req struct gnutella_node n,
const struct vmsg vmsg,
gchar *  unused_payload,
gint  size
[static]
 

Handle reception of "Query Status Request", where the UP requests how many results the search filters of the leave (ourselves) let pass through.

void handle_tcp_connect_back struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle the "TCP Connect Back" message.

void handle_time_sync_reply struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle reception of a "Time Sync Reply" message, holding the reply from a previous time synchronization request.

void handle_time_sync_req struct gnutella_node n,
const struct vmsg vmsg,
gchar *  unused_payload,
gint  size
[static]
 

Handle reception of a "Time Sync Request" message, indicating a request from another host about time synchronization.

void handle_udp_connect_back struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle the \"UDP Connect Back" message.

void handle_udp_crawler_ping struct gnutella_node n,
const struct vmsg vmsg,
gchar *  payload,
gint  size
[static]
 

Handle reception of an UDP crawler ping.

RCSID "$Id:vmsg.  c,
v 1.52 2005/11/12 12:04:34 cbiere Exp $" 
 

void vmsg_bad_payload struct gnutella_node n,
const struct vmsg vmsg,
gint  size,
gint  expected
[static]
 

Report a vendor-message with bad payload to the stats.

pmsg_t* vmsg_build_oob_reply_ind gchar *  muid,
guint8  hits
 

Build an "OOB Reply Indication" message.

Parameters:
muid is the query ID
hits is the number of hits we have to deliver for that query

guint32 vmsg_fill_header struct gnutella_header header,
guint32  size,
guint32  maxsize
[static]
 

Fill common message header part for all vendor-specific messages.

The GUID is blanked (all zero bytes), TTL is set to 1 and hops to 0. Those common values can be superseded by the caller if needed.

`size' is only the size of the payload we filled so far. `maxsize' is the size of the already allocated vendor messsage.

Returns:
the total size of the whole Gnutella message.

gchar* vmsg_fill_type struct gnutella_vendor base,
guint32  vendor,
guint16  id,
guint16  version
[static]
 

Fill leading part of the payload data, containing the common part for all vendor-specific messages.

Returns:
start of payload after that common part.

void vmsg_handle struct gnutella_node n  ) 
 

Main entry point to handle reception of vendor-specific message.

const gchar* vmsg_infostr gconstpointer  data,
gint  size
 

Decompiles vendor-message name given the data payload of the Gnutella message and its size.

The leading bytes give us the identification unless it's too short.

Returns:
vendor message name in the form "NAME/1v1 'Known name'" as a static string.

void vmsg_init void   ) 
 

Initialize vendor messages.

void vmsg_map_is_sorted void   )  [static]
 

Assert that the vmsg_map[] array is sorted.

void vmsg_send_hops_flow struct gnutella_node n,
guint8  hops
 

Send an "Hops Flow" message to specified node.

void vmsg_send_messages_supported struct gnutella_node n  ) 
 

Send a "Messages Supported" message to specified node, telling it which subset of the vendor messages we can understand.

We don't send information about the "Messages Supported" message itself, since this one is guaranteed to be always understood

void vmsg_send_oob_reply_ack struct gnutella_node n,
gchar *  muid,
guint8  want
 

Send an "OOB Reply Ack" message to specified node, informing it that we want the specified amount of hits delivered for the query identified by the MUID of the message we got (the "OOB Reply Indication").

void vmsg_send_proxy_ack struct gnutella_node n,
gchar *  muid,
gint  version
[static]
 

Send a "Push Proxy Acknowledgment" message to specified node, using supplied `muid' as the message ID (which is the target node's GUID).

The version 1 of this message did not have the listening IP, only the port: the recipient was supposed to gather the IP address from the connected socket.

The version 2 includes both our IP and port.

void vmsg_send_proxy_cancel struct gnutella_node n  ) 
 

Send a "Push Proxy Cancel" message to specified node.

void vmsg_send_proxy_req struct gnutella_node n,
const gchar *  muid
 

Send a "Push Proxy Request" message to specified node, using supplied `muid' as the message ID (which is our GUID).

void vmsg_send_qstat_answer struct gnutella_node n,
gchar *  muid,
guint16  hits
 

Send a "Query Status Response" message to specified node.

Parameters:
n the Gnutella node to sent the message to
muid is the query ID
hits is the number of hits our filters did not drop.

void vmsg_send_qstat_req struct gnutella_node n,
gchar *  muid
 

Send a "Query Status Request" message to specified node, using supplied `muid' as the message ID (which is the query ID).

void vmsg_send_tcp_connect_back struct gnutella_node n,
guint16  port
 

Send a "TCP Connect Back" message to specified node, telling it to connect back to us on the specified port.

void vmsg_send_time_sync_reply struct gnutella_node n,
gboolean  ntp,
tm_t got
 

Send a "Time Sync Reply" message to the node, including the time at which we send back the message in the second half of the MUID.

The time in `got' is the time at which we received their request.

void vmsg_send_time_sync_req struct gnutella_node n,
gboolean  ntp,
tm_t sent
 

Send a "Time Sync Request" message, asking them to echo back their own time so that we can compute our clock differences and measure round trip times.

The time at which we send the message is included in the first half of the MUID.

If the node is an UDP node, its IP and port indicate to whom we shall send the message.

The `sent' parameter holds the initial "T1" timestamp markup.

void vmsg_send_udp_connect_back struct gnutella_node n,
guint16  port
 

Send a "UDP Connect Back" message to specified node, telling it to ping us back via UDP on the specified port.

XXX for now, we only send GTKG/7v1, although GTKG/7v2 is more compact.

void vmsg_send_udp_crawler_pong struct gnutella_node n,
pmsg_t mb
 

Send UDP crawler pong, in reply to their ping.

The supplied message block contains the payload to send back.

gboolean vmsg_time_sync_reply_stamp pmsg_t mb,
const struct mqueue unused_q
[static]
 

Callback invoked when "Time Sync Reply" is about to be sent.

Writes current time in the second half of the MUID.

gboolean vmsg_time_sync_req_stamp pmsg_t mb,
const struct mqueue unused_q
[static]
 

Callback invoked when "Time Sync Request" is about to be sent.

Writes current time in the first half of the MUID.


Variable Documentation

gchar v_tmp[4128] [static]
 

Large enough for a payload of 4K.

const struct vmsg vmsg_map[] [static]
 

Initial value:

 {
    

    { T_0000, 0x0000, 0x0000, handle_messages_supported, "Messages Supported" },
    { T_0000, 0x000a, 0x0000, handle_features_supported, "Features Supported" },
    { T_BEAR, 0x0004, 0x0001, handle_hops_flow, "Hops Flow" },
    { T_BEAR, 0x0007, 0x0001, handle_tcp_connect_back, "TCP Connect Back" },
    { T_BEAR, 0x000b, 0x0001, handle_qstat_req, "Query Status Request" },
    { T_BEAR, 0x000c, 0x0001, handle_qstat_answer, "Query Status Response" },
    { T_GTKG, 0x0007, 0x0001, handle_udp_connect_back, "UDP Connect Back" },
    { T_GTKG, 0x0007, 0x0002, handle_udp_connect_back, "UDP Connect Back" },
    { T_GTKG, 0x0009, 0x0001, handle_time_sync_req, "Time Sync Request" },
    { T_GTKG, 0x000a, 0x0001, handle_time_sync_reply, "Time Sync Reply" },
    { T_GTKG, 0x0015, 0x0001, handle_proxy_cancel, "Push-Proxy Cancel" },
    { T_LIME, 0x0005, 0x0001, handle_udp_crawler_ping, "UDP Crawler Ping" },
    { T_LIME, 0x000b, 0x0002, handle_oob_reply_ack, "OOB Reply Ack" },
    { T_LIME, 0x000c, 0x0001, handle_oob_reply_ind, "OOB Reply Indication" },
    { T_LIME, 0x000c, 0x0002, handle_oob_reply_ind, "OOB Reply Indication" },
    { T_LIME, 0x0015, 0x0001, handle_proxy_req, "Push-Proxy Request" },
    { T_LIME, 0x0015, 0x0002, handle_proxy_req, "Push-Proxy Request" },
    { T_LIME, 0x0016, 0x0001, handle_proxy_ack, "Push-Proxy Acknowledgment" },
    { T_LIME, 0x0016, 0x0002, handle_proxy_ack, "Push-Proxy Acknowledgment" },





    
}
Known vendor-specific messages.


Generated on Sun Feb 12 10:50:10 2006 for Gtk-Gnutella by doxygen 1.3.6