PDA

View Full Version : Sending Queries to the Network...


C_Lover
February 7th, 2009, 01:56 PM
Hey people,
I am currently coding a small gnutella client for educational purpose in C++.
I have several questions regarding the sending of Queries.

If I send a query, then I must define a Query String, the TTL (0x07), the Payload (0x80) and the MinimumSpeed.

Do I also have to define the "Hops" value, or is this automatically done by the Node receiving my command?

I currently got this snippets:
(-> definition of the query struct)

typedef struct QUERY{

unsigned short MinSpeed;
char *string;
char payload;
char TTL;
char Hops;
int Length;

}query;


int sendQuery(char *Text, SOCKET s)
{

query *q;
int bytes;
q = (query*)malloc(sizeof(struct QUERY));
strcpy(q->string, Text);
q->Hops=0x00;

q->Length=0x00;
q->TTL=0x10;
q->payload=0x80;
q->MinSpeed = 1;


bytes = send(s,(char*)q, sizeof((char*)q) ,0);

free(q);

return bytes;
}

I am converting this struct to a char for sending it (with (char*)), is the order of the values in my struct definition important?
(if not then
unsigned short MinSpeed;
char *string;

is the same as
char *string;
unsigned short MinSpeed;
).

Do I need some more stuff, or can I issue commands like that? The GDF got no samples at that point (could manage all the other stuff with help of the GDF and RFC).

Hope that you ol' gnutella rabbits can help me out ;)

C_Lover

EDIT:
Is there any Max_Length of a query string or can it have an unlimited length?

C_Lover
February 20th, 2009, 08:00 AM
*bump*


:-)

C_Lover
March 14th, 2009, 10:55 AM
*bump*

:-d

Aaron.Walkhouse
March 14th, 2009, 11:40 AM
I don't think there are many C programmers in this Java shop. Have you tried the Shareaza crew (https://pantheraproject.net/forum/index.php)?

nascentmind
April 29th, 2009, 06:50 AM
In my case in java I fill the values in a bytebuffer. In your case I am not sure but shouldn't you not send a structure across the wire as there might be padding added in the structure?
Also what would happen if the size of the integer is different in other machines? Wasn't that the reason of putting the size of various datatypes in rfc?
One solution is to put the values in a char array buffer and send it.