From: <bo...@us...> - 2004-01-12 21:39:58
|
Update of /cvsroot/sharedaemon/core/src In directory sc8-pr-cvs1:/tmp/cvs-serv30982 Modified Files: Ed2kConnection.h test.cpp Log Message: Cleaned up a function by splitting it down to two, added new state CLIENT_TCP_WAITING_FOR_HASHSET_ANSWER and added initial support to load known.met and preferences.dat (pref_met_ps) Index: Ed2kConnection.h =================================================================== RCS file: /cvsroot/sharedaemon/core/src/Ed2kConnection.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Ed2kConnection.h 26 Nov 2003 01:22:56 -0000 1.4 +++ Ed2kConnection.h 12 Jan 2004 21:39:55 -0000 1.5 @@ -49,6 +49,7 @@ // we are contacting a client: CLIENT_TCP_SENDING_HELLO_PACKET, CLIENT_TCP_WAITING_FOR_HELLO_ANSWER, + CLIENT_TCP_WAITING_FOR_HASHSET_ANSWER, // Unused ILLEGAL }; Index: test.cpp =================================================================== RCS file: /cvsroot/sharedaemon/core/src/test.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- test.cpp 6 Jan 2004 05:59:55 -0000 1.31 +++ test.cpp 12 Jan 2004 21:39:55 -0000 1.32 @@ -362,7 +362,7 @@ for (num=PNUM;num;) bitmap[--num]=0; - for (long i=0;i<0x7fffffff;++i) { + for (long i=0;i<0x7fffffffLU;++i) { int r=rand(); r=(int)(((4.0*num)*rand())/RAND_MAX); @@ -371,7 +371,7 @@ // BitmapX.DebugPrint(); unsigned long rc=BitmapX->Alloc(); printf("=%lx\n",rc); - if (rc==0xffffffff) { + if (rc==0xffffffffLU) { if (NUM && num!=NUM) { printf("Error: Couldn't allocate entry while at least one was still free.\n"); exit(2); @@ -588,6 +588,9 @@ struct parsestruct * server_met_ps; struct parsestruct * part_met_ps; +struct parsestruct * known_met_ps; +struct parsestruct * pref_met_ps; + int num_partfiles=0; int max_partfiles=0; std::string IncomingDirectory="/mnt/Fat_C/gesaugt/Internet/eMule/Incoming"; @@ -674,13 +677,41 @@ "<BYTE>magic<DWORD>date<HASH>filehash" /* * According to eDonkey-protocol-0.6.1, there are existing - * broken clients, which doubles the list of chunkhashs. + * broken clients, which doubles the list of chunkhashes. * So, numchunks may be 2*real_num_chunks. Keep this in mind. */ "<WORD>chunkcount<HASH>chunkhash[chunkcount]" "<DWORD>tagcount<TAG>tag[tagcount]" ); + known_met_ps=parse_line( + /* + * According to eDonkey-protocol-0.6.1, the field magic is + * 0x0e. + */ + "<BYTE>magic<DWORD>numfiles{" + "<DWORD>date<HASH>file" + "<WORD>chunkcount<HASH>chunkhash[chunkcount]" + "<DWORD>tagcount<TAG>tag[tagcount]" + "}file[numfiles]" + ); + + pref_met_ps=parse_line( + /* + * The following entry shows, how stupid the one developing + * ed2k must be, to store the IP address in the preferences + * file. What shall this be good for? + */ + "<IPPORT>address<HASH>user" + /* + * There are two tagsets, I called the first 'sometags' and + * the other 'preftags', as I didn't get better names for + * them. As I know what the meaning of that is, I can get + * them better names ... + */ + "<DWORD>sometagcount<TAG>sometag[sometagcount]" + "<DWORD>preftagcount<TAG>preftag[preftagcount]" + ); /* print_parsestruct(server_met_ps,0); */ @@ -801,6 +832,32 @@ return PClist[proto_opcode]=new ParseClass(ps); } +void Client_Tcp_Sending_Hashset_Request(u32 id,hash file) { + Ed2kPacket p; + + ParseClass * PC=GetParseClass("HASHSETREQUEST"); + PC->Set(file,"file_hash"); + PC->Write(p,0xe3,HASHSETREQUEST); + + printf( + "Sending packet (id=%lu; ip:port=%lu:%u. Protocol=0x%02x, Opcode=0x%02x, Size=0x%08x\n", + (long unsigned)id,(long unsigned)Connection::GetSocket(id).GetIP(), + (unsigned)Connection::GetSocket(id).GetPort(),p.GetProtocol(), + p.GetOpcode(),(int)p.GetSize() + ); + printf("%s:%i: \n",__FILE__,__LINE__); HexDump(p.GetPtr(),p.GetSize(),true); + + if (!Connection::GetSocket(id).EnqueuePacket(p)) { + if (get_errno()!=SOCKET_EWOULDBLOCK) { + Connection::GetSocket(id).Close(); + Connection::SetStatus(id,ILLEGAL); + Connection::Free(id); + return; + } + } + Connection::SetStatus(id,CLIENT_TCP_WAITING_FOR_HASHSET_ANSWER); +} + void Client_Tcp_Sending_Hello_Packet(u32 id) { bool rc; Ed2kPacket p; @@ -870,19 +927,7 @@ } Connection::SetStatus(id,CLIENT_TCP_WAITING_FOR_HELLO_ANSWER); - p.BuildHashsetRequestPacket(filehash); - printf( - "Sending packet (id=%lu; ip:port=%lu:%u. Protocol=0x%02x, Opcode=0x%02x, Size=0x%08x\n", - (long unsigned)id,(long unsigned)Connection::GetSocket(id).GetIP(), - (unsigned)Connection::GetSocket(id).GetPort(),p.GetProtocol(), - p.GetOpcode(),(int)p.GetSize() - ); - printf("%s:%i: \n",__FILE__,__LINE__); HexDump(p.GetPtr(),p.GetSize(),true); - rc=Connection::GetSocket(id).EnqueuePacket(p); - if (!rc) { - printf("error sending hashset request.\n"); - } - rc=true; + Client_Tcp_Sending_Hashset_Request(id,filehash); } void Server_Tcp_Sending_Login_Request(u32 id) { @@ -973,10 +1018,7 @@ u16 msglen,i; char * msg; - printf("Servermessage:\n"); - // Log Message. PC->Get(msglen,"message_len"); - printf("msglen=%u\n",msglen); msg=new char[msglen+1]; for (i=0;i<msglen;++i) { PC->GetF(msg[i],"message[%u]",i); @@ -1009,6 +1051,7 @@ "Out of memory.\n" ,__FILE__,__FUNCTION__,__LINE__ ); + exit(2); } } connection_id[num_connected]=id; @@ -1098,7 +1141,7 @@ void Serve(u32 id) { bool again; - static u32 nc=0xffffffff; + static u32 nc=0xffffffffLU; bool rc; |