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?
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?