Client <-> hub handshake.

Technical discussion about the NMDC and <a href="http://dcpp.net/ADC.html">ADC</A> protocol. The NMDC protocol is documented in the <a href="http://dcpp.net/wiki/">Wiki</a>, so feel free to refer to it.

Moderator: Moderators

Locked
Moch
Posts: 71
Joined: 2003-03-21 22:29

Client <-> hub handshake.

Post by Moch » 2003-04-04 17:17

Allright... time to humble myself and ask WHAT THE FREAK IS WRONG? *L*

I am having emense problems trying to connect to a hub witht he client I am working on. With NMDCH I get temp banned and in the stauts messages it puts $Key <whatever I sent>. Thanks NMDCH!

When I connect to PtokacX Hub I get the $Hello username back and it appears if I am logged in, and I can send chat messages just fine.. but the problem there is that I don't register as a logged in user in the hub software, but I do show up on everyone's list as a user (it sends out $Hello username and $MyInfo out correctly to all the connected clients). However, I am "hidden" on the hub.

I have sniffed packets between DC++ and the hubs and it appears I am doing everything the same, except I am not requesting $GetINFO for all the users, do I need to do this before it considers me logged in? I am not sure what is wrong here, I think it could be that my key is being miscalculated.

Here is the code I am using for the key:

Code: Select all

void generateKey(unsigned char *lock, unsigned char **fkey)
{
   int count = 0, len = 0, offset = 0;
   unsigned char *key = 0, *tkey= 0;
   logit("About to do strlen");
   len = strlen(lock);
   logit("Allocating key");
   erealloc((void **)&key, sizeof(char)*(len + 1) );
   logit("About to while through key");

   while(lock[++count])
	key[count] = lock[count] ^ lock[count - 1];
   
   logit("Setting first bytes of Key");
   key[0] = lock[0] ^ lock[len - 1] ^ lock[len - 2] ^ 5;
   
   count = 0;
   logit("About to nibble swap keys");
   while(key[count++])
     key[count - 1] = ((key[count - 1]  << 4)) | ((key[count - 1] >> 4));
   
   count = 0;
   logit("Mallocing temp key");
   tkey = emalloc(sizeof(char)*(len + 1));
   logit("Whiling through scanning and translating codes");
   while(key[count++])
     {
	switch(key[count - 1])
	  {
	   case 0:
	   case 5:
	   case  36:
	   case 96:
	   case 124:
	   case 126:
	     erealloc((void **)&tkey, sizeof(char)*(len + offset + 11));
	     sprintf(&tkey[count - 1 + offset], "/%%DCN%.3d%%/", key[count - 1]);
	     
	     offset += 10;
	     break;
	     
	   default:
	     tkey[count - 1 + offset] = key[count - 1];
	     break;
	  }
     
     }
   tkey[len + offset] = 0;
   
   *fkey = tkey;
   
}
I have gone over it several times and it appears to be working right. The nibble swap works for sure (I have tested that part greatly)

I am not worried about optimizing that code at the moment, just that it is actually doing the right thing.

Any help would be appreciated.
Thanks,
~Moch

Moch
Posts: 71
Joined: 2003-03-21 22:29

Post by Moch » 2003-04-04 18:18

Well.. a nice soul from the developer hub helped me (aDe) out and we figured out that my key algo is working just fine, so there is something else that is wrong :/ If anyone has any ideas, let me know, but hopefully we will figure this problem out before to long.

Moch
Posts: 71
Joined: 2003-03-21 22:29

Post by Moch » 2003-04-04 18:45

I guess I like talking to myself, but for the sake of being right, we figured out that the problem was happening on escape coding... here is the correct version of the code I pasted earlier in case any C programmer needs an example of doing the locks to keys:

Code: Select all


void generateKey(unsigned char *lock, unsigned char **fkey)
{
   int count = 0, len = 0, offset = 0;
   unsigned char *key = 0, *tkey= 0;
   logit("About to do strlen");
   len = strlen(lock);
   logit("Allocating key");
   erealloc((void **)&key, sizeof(char)*(len + 1) );
   logit("About to while through key");

   while(lock[++count])
	key[count] = lock[count] ^ lock[count - 1];
   
   logit("Setting first bytes of Key");
   key[0] = lock[0] ^ lock[len - 1] ^ lock[len - 2] ^ 5;
   
   count = 0;
   logit("About to nibble swap keys");
   while(key[count++])
     key[count - 1] = ((key[count - 1]  << 4)) | ((key[count - 1] >> 4));
   
   count = 0;
   logit("Mallocing temp key");
   tkey = emalloc(sizeof(char)*(len + 1));
   logit("Whiling through scanning and translating codes");
   while(key[count++])
     {
	switch(key[count - 1])
	  {
	   case 0:
	   case 5:
	   case  36:
	   case 96:
	   case 124:
	   case 126:
	     erealloc((void **)&tkey, sizeof(char)*(len + offset + 11));
	     sprintf(&tkey[count - 1 + offset], "/%%DCN%.3d%%/", key[count - 1]);
	     //NOT 10 because count++
	     offset += 9;
	     break;
	     
	   default:
	     tkey[count - 1 + offset] = key[count - 1];
	     break;
	  }
     
     }
   tkey[len + offset] = 0;
   
   *fkey = tkey;
   
}
Please take note that the function erealloc, emalloc, and logit are custom functions. logit, is of course, is not needed. I am sure any decent programmer can figure out how to write erealloc, and emalloc using the standard realloc and malloc functions. (they do the same thing with error checking and filling the new space with nulls)

Share and Enjoy,
~Moch

TasMan
Posts: 196
Joined: 2003-01-03 08:31
Location: Canada
Contact:

Post by TasMan » 2003-04-04 19:36

Well I know little of C(++) (Still learning as is), but I can try and think of possible problems...

For example, do you stop making a key when you hit a space character?

The NMDC hub sends

Code: Select all

$Lock <string> pk=<string>|
You ONLY get a key from the FIRST string. Ignore the pk= and the second string.

Aside from that, your lock to key seems fine, but that's again coming from somebody who's still learning C himself.


By the way, nice to see I'm not the only one around here that goes on monologues....
Shadows Direct Connect Hub - Taking away the light from NMDCH, leaving only shadows.....

Moch
Posts: 71
Joined: 2003-03-21 22:29

Post by Moch » 2003-04-04 20:07

TasMan thanks for the response.

It seems like I have the handshake stuff working now. It was my key code, it was adding a null after my escape sequences, dumb mistake.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2003-04-04 20:47

There's nothing wrong with following up to yourself. I'm glad to see aDe helping you out in the scrollback of my DC++. :)

andlju
Posts: 27
Joined: 2003-02-28 12:58
Location: Stockholm, Sweden
Contact:

Post by andlju » 2003-04-07 06:41

Moch wrote:

Code: Select all

...
	     //NOT 10 because count++
...
Wow! I did the exact same thing when I did the Key->Lock algo in my C# client.. Sorry I didn't read the forum in time to help you out..

/Anders

Locked