Official eMule-Board: [add] Hybrid's Shared Directories/files - Official eMule-Board

Jump to content


Page 1 of 1

[add] Hybrid's Shared Directories/files Implementation of Hybrid's opcodes

#1 User is offline   bluecow 

  • The Merciful
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1772
  • Joined: 27-December 02

Posted 15 February 2003 - 10:41 AM

Some of you may have noticed that eDonkey Hybrid and Overnet do no longer support the opcodes OP_ASKSHAREDFILES and OP_ASKSHAREDFILESANSWER, instead of this they are using a directory-based set of shared files messages.

Here is an (alpha) implementation of those new messages for eMule. I've tested the code with eDonkey Hybrid v0.44, Overnet v0.42 and Overnet v0.44 and it seems to work well. Although it's not a very important feature to support the "shared files" messages, someone may have a use for it ;)

Because the changes are a little wide-spread I've decided to post the code in "diff" format -- hope you like it. (No, you wont't like it, but maybe some of you can use it.) Apply the "diff" with 'patch -l < eMule0.26b2.diff'

The code is straight forward, nothing special to note. Just one thing: In ReGetClientSoftware I try to detect Overnet clients only with internal versions 44 and 441 -- this has no future but currently I don't know how to make this more properly.

TODO:
- Properly determination of eDonkeyHybrid and Overnet clients.

- Generally I don't like the idea of letting other clients see my *real* directory names. There should be some kind of "virtualization".

Real directory......Public directory (sent to clients)
------------------------------------------------------
C:\Data\Stuff.......Dir1
D:\Data\MoreStuff...Dir2

- I don't like the 'm_iFileListRequested' counter. I just used it to get the thing working. But there should be some other mechanism to properly determine if there's a directory- or filelist request pending.

- I would also suggest to be a little more paranoid and canonicalize the received directories. Although it should currently be no problem to receive directories with "." and ".." and "..\..\" and so on, it may become a potential security problem in future versions of eMule.
diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/opcodes.h eMule0.26b2/src/opcodes.h
--- eMule0.26b/src/opcodes.h	Sat Feb 15 10:16:44 2003
+++ eMule0.26b2/src/opcodes.h	Sat Feb 15 10:17:20 2003
@@ -147,6 +147,11 @@
 #define OP_FILEREQANSWER        0x59    // <HASH 16><len 4><NAME len>
 #define OP_CHANGE_SLOT          0x5B    // <HASH 16>
 #define OP_QUEUERANK            0x5C    // <wert  4> (slot index of the request)
+#define OP_ASKSHAREDDIRS        0x5D    // (null)
+#define OP_ASKSHAREDFILESDIR    0x5E    // <len 2><Directory len>
+#define OP_ASKSHAREDDIRSANS     0x5F    // <count 4>(<len 2><Directory len>)[count]
+#define OP_ASKSHAREDFILESDIRANS 0x60    // <len 2><Directory len><count 4>(<HASH 16><ID 4><PORT 2><1 Tag_set>)[count]
+#define OP_ASKSHAREDDENIEDANS   0x61    // (null)
 
 
 // extened prot client <-> extened prot client


diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/updownclient.h eMule0.26b2/src/updownclient.h
--- eMule0.26b/src/updownclient.h	Sat Feb 15 10:16:44 2003
+++ eMule0.26b2/src/updownclient.h	Sat Feb 15 10:17:20 2003
@@ -221,6 +221,8 @@ public:
     // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
     void ShowDownloadingParts(CString *partsYN);
     void UpdateDisplayedInfo(boolean force=false);
+    int             GetFileListRequested() { return m_iFileListRequested; }
+    void            SetFileListRequested(int iFileListRequested) { m_iFileListRequested = iFileListRequested; }
 private:
     // base
     void    Init();
@@ -252,7 +254,7 @@ private:
     uint8   m_clientSoft;
     uint32  m_dwLastSourceRequest;
     uint32  m_dwLastSourceAnswer;
-    bool    m_bFileListRequested;
+    int     m_iFileListRequested;
     bool    m_bFriendSlot;
     bool    m_bCommentDirty;
     uint32  m_byCompatableClient;


diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/BaseClient.cpp eMule0.26b2/src/BaseClient.cpp
--- eMule0.26b/src/BaseClient.cpp	Sat Feb 15 10:16:44 2003
+++ eMule0.26b2/src/BaseClient.cpp	Sat Feb 15 10:17:20 2003
@@ -73,7 +73,7 @@ void CUpDownClient::Init(){
     m_nUserID = 0;
     m_nServerPort = 0;
     m_bBanned = false;
-    m_bFileListRequested = false;
+    m_iFileListRequested = 0;
     m_dwLastUpRequest = 0;
     m_bEmuleProtocol = false;
     usedcompressiondown = false;
@@ -491,9 +491,9 @@ void CUpDownClient::Disconnected(){
         socket->Safe_Delete();
     }
     socket = 0;
-    if (m_bFileListRequested){
+    if (m_iFileListRequested){
         theApp.emuledlg->AddDebugLogLine(false,GetResString(IDS_SHAREDFILES_FAILED),GetUserName());
-        m_bFileListRequested = false;
+        m_iFileListRequested = 0;
     }
     if (m_Friend)
         theApp.friendlist->RefreshFriend(m_Friend);
@@ -604,8 +604,8 @@ void CUpDownClient::ConnectionEstablishe
                 socket->SendPacket(packet,true);
             }
     }
-    if (m_bFileListRequested){
-        Packet* packet = new Packet(OP_ASKSHAREDFILES,0);
+    if (m_iFileListRequested == 1){
+        Packet* packet = new Packet((GetClientSoft()==SO_EDONKEYHYBRID) ? OP_ASKSHAREDDIRS : OP_ASKSHAREDFILES,0);
         theApp.uploadqueue->AddUpDataOverheadOther(packet->size);
         socket->SendPacket(packet,true,true);
     }
@@ -625,7 +625,7 @@ void CUpDownClient::ReGetClientSoft(){
         }
     }
     if (m_achUserHash[5] == 'M' && m_achUserHash[14] == 'L') {m_clientSoft= SO_MLDONKEY;return;}
-    if( this->GetVersion() > 1040 )
+    if( this->GetVersion() > 1040 || this->GetVersion() == 44 || this->GetVersion() == 441 )
         m_clientSoft=SO_EDONKEYHYBRID;
     else
         m_clientSoft=SO_EDONKEY;
@@ -639,13 +639,13 @@ void CUpDownClient::SetUserName(char* ps
 
 void CUpDownClient::RequestSharedFileList(){
     theApp.emuledlg->AddDebugLogLine(true,GetResString(IDS_SHAREDFILES_REQUEST),GetUserName());
-    m_bFileListRequested = true;
+    m_iFileListRequested = 1;
     TryToConnect(true);
 }
 
 void CUpDownClient::ProcessSharedFileList(char* pachPacket, uint32 nSize){
-    if (m_bFileListRequested){
-        m_bFileListRequested = false;
+    if (m_iFileListRequested > 0){
+        m_iFileListRequested--;
         theApp.searchlist->ProcessSearchanswer(pachPacket,nSize,this);
     }
 }


diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/ListenSocket.cpp eMule0.26b2/src/ListenSocket.cpp
--- eMule0.26b/src/ListenSocket.cpp	Sat Feb 15 10:16:44 2003
+++ eMule0.26b2/src/ListenSocket.cpp	Sat Feb 15 10:17:20 2003
@@ -432,6 +432,140 @@ bool CClientReqSocket::ProcessPacket(cha
                     client->ProcessSharedFileList(packet,size);
                     break;
                 }
+                case OP_ASKSHAREDDIRS:{
+                    theApp.downloadqueue->AddDownDataOverheadOther(size);
+                    ASSERT( size == 0 );
+                    if (theApp.glob_prefs->CanSeeShares()==0 || (theApp.glob_prefs->CanSeeShares()==1 && client->IsFriend())){
+                        theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your shareddirectories-list -> %s",client->GetUserName(),client->GetUserID(),GetResString(IDS_ACCEPTED) );
+ 
+                        CSafeMemFile tempfile(80);
+                        uint32 uDirs = theApp.glob_prefs->shareddir_list.GetCount();
+                        tempfile.Write(&uDirs, 4);
+ 
+                        POSITION pos = theApp.glob_prefs->shareddir_list.GetHeadPosition();
+                        while (pos){
+                            CString strDir = theApp.glob_prefs->shareddir_list.GetNext(pos);
+                            PathRemoveBackslash(strDir.GetBuffer());
+                            strDir.ReleaseBuffer();
+                            uint16 cnt = strDir.GetLength();
+                            tempfile.Write(&cnt, 2);
+                            tempfile.Write((LPCTSTR)strDir, cnt);
+                        }
+ 
+                        Packet* replypacket = new Packet(&tempfile);
+                        replypacket->opcode = OP_ASKSHAREDDIRSANS;
+                        theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size);
+                        SendPacket(replypacket, true, true);
+                    }
+                    else{
+                        theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your shareddirectories-list -> %s",client->GetUserName(),client->GetUserID(),GetResString(IDS_DENIED) );
+                        Packet* replypacket = new Packet(OP_ASKSHAREDDENIEDANS, 0);
+                        theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size);
+                        SendPacket(replypacket, true, true);
+                    }
+                    break;
+                }
+                case OP_ASKSHAREDFILESDIR:{
+                    theApp.downloadqueue->AddDownDataOverheadOther(size);
+                    CSafeMemFile data((uchar*)packet, size, 0);
+                    uint16 cnt;
+                    data.Read(&cnt, 2);
+                    CString strReqDir;
+                    data.Read(strReqDir.GetBuffer(cnt), cnt);
+                    strReqDir.ReleaseBuffer(cnt);
+                    PathRemoveBackslash(strReqDir.GetBuffer());
+                    strReqDir.ReleaseBuffer();
+ 
+                    if (theApp.glob_prefs->CanSeeShares()==0 || (theApp.glob_prefs->CanSeeShares()==1 && client->IsFriend())){
+                        theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your sharedfiles-list for directory %s -> %s",client->GetUserName(),client->GetUserID(),strReqDir,GetResString(IDS_ACCEPTED) );
+                        ASSERT( data.GetPosition() == data.GetLength() );
+ 
+                        CTypedPtrList<CPtrList, CKnownFile*> list;
+                        for (POSITION pos = theApp.sharedfiles->m_Files_map.GetStartPosition();pos != 0;){
+                            CCKey bufKey;
+                            CKnownFile* cur_file;
+                            theApp.sharedfiles->m_Files_map.GetNextAssoc(pos, bufKey, cur_file);
+                            CString strSharedFile(cur_file->GetPath());
+                            PathRemoveFileSpec(strSharedFile.GetBuffer());
+                            strSharedFile.ReleaseBuffer();
+                            if (strReqDir.CompareNoCase(strSharedFile) == 0)
+                                list.AddTail(cur_file);
+                        }
+ 
+                        if (list.GetCount()){
+                            CSafeMemFile tempfile(80);
+                            uint16 cnt = strReqDir.GetLength();
+                            tempfile.Write(&cnt, 2);
+                            tempfile.Write((LPCTSTR)strReqDir, cnt);
+                            uint32 uFiles = list.GetCount();
+                            tempfile.Write(&uFiles, 4);
+                            while (list.GetCount()){
+                                theApp.sharedfiles->CreateOfferedFilePacket(list.GetHead(), &tempfile);
+                                list.RemoveHead();
+                            }
+ 
+                            Packet* replypacket = new Packet(&tempfile);
+                            replypacket->opcode = OP_ASKSHAREDFILESDIRANS;
+                            theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size);
+                            SendPacket(replypacket, true, true);
+                        }
+                    }
+                    else{
+                        theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your sharedfiles-list for directory %s -> %s",client->GetUserName(),client->GetUserID(),strReqDir,GetResString(IDS_DENIED) );
+                        Packet* replypacket = new Packet(OP_ASKSHAREDDENIEDANS, 0);
+                        theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size);
+                        SendPacket(replypacket, true, true);
+                    }
+                    break;
+                }
+                case OP_ASKSHAREDDIRSANS:{
+                    theApp.downloadqueue->AddDownDataOverheadOther(size);
+                    if (client->GetFileListRequested() == 1){
+                        CSafeMemFile data((uchar*)packet, size, 0);
+                        uint32 uDirs;
+                        data.Read(&uDirs, 4);
+                        for (UINT i = 0; i < uDirs; i++){
+                            uint16 cnt;
+                            data.Read(&cnt, 2);
+                            CString strDir;
+                            data.Read(strDir.GetBuffer(cnt), cnt);
+                            strDir.ReleaseBuffer(cnt);
+                            theApp.emuledlg->AddLogLine(true,"User %s (%u) shares directory %s",client->GetUserName(),client->GetUserID(),strDir);
+
+                            CSafeMemFile tempfile(80);
+                            cnt = strDir.GetLength();
+                            tempfile.Write(&cnt, 2);
+                            tempfile.Write((LPCTSTR)strDir, cnt);
+                            Packet* replypacket = new Packet(&tempfile);
+                            replypacket->opcode = OP_ASKSHAREDFILESDIR;
+                            theApp.uploadqueue->AddUpDataOverheadOther(replypacket->size);
+                            SendPacket(replypacket, true, true);
+                        }
+                        ASSERT( data.GetPosition() == data.GetLength() );
+                        client->SetFileListRequested(uDirs);
+                    }
+                    break;
+                }
+                case OP_ASKSHAREDFILESDIRANS:{
+                    theApp.downloadqueue->AddDownDataOverheadOther(size);
+                    if (client->GetFileListRequested() > 0){
+                        CSafeMemFile data((uchar*)packet, size, 0);
+                        uint16 cnt;
+                        data.Read(&cnt, 2);
+                        CString strDir;
+                        data.Read(strDir.GetBuffer(cnt), cnt);
+                        strDir.ReleaseBuffer(cnt);
+                        theApp.emuledlg->AddLogLine(true,"User %s (%u) sent sharedfiles-list for directory %s",client->GetUserName(),client->GetUserID(),strDir);
+                        client->ProcessSharedFileList(packet + data.GetPosition(), size - data.GetPosition());
+                    }
+                    break;
+                }
+                case OP_ASKSHAREDDENIEDANS:{
+                    theApp.downloadqueue->AddDownDataOverheadOther(size);
+                    ASSERT( size == 0 );
+                    theApp.emuledlg->AddLogLine(true,"User %s (%u) denied access to shareddirectories/files-list",client->GetUserName(),client->GetUserID());
+                    break;
+                }
                 default:
                     theApp.downloadqueue->AddDownDataOverheadOther(size);
                     theApp.emuledlg->AddDebugLogLine(false,"unknown opcode: %i %h",opcode,opcode);


diff -u -p -r -x *.vcproj -x *.sln -x *.ncb -x *.suo eMule0.26b/src/SearchDlg.cpp eMule0.26b2/src/SearchDlg.cpp
--- eMule0.26b/src/SearchDlg.cpp	Sat Feb 15 10:16:44 2003
+++ eMule0.26b2/src/SearchDlg.cpp	Sat Feb 15 10:17:20 2003
@@ -492,6 +492,13 @@ void CSearchDlg::StartNewSearch(){
 }
 
 void CSearchDlg::CreateNewTab(CString searchString,uint32 nSearchID){
+    int iTabItems = searchselect.GetItemCount();
+    for (int i = 0; i < iTabItems; i++){
+        TCITEM tci;
+        tci.mask = TCIF_PARAM;
+        if (searchselect.GetItem(i, &tci) && tci.lParam == nSearchID)
+            return;
+    }
     // add new tab
     TCITEM newitem;
     if (searchString.GetLength() == 0)

0

#2 User is offline   Lord KiRon 

  • eMule Plus Team member
  • PipPipPipPipPipPip
  • Group: Member_D
  • Posts: 339
  • Joined: 06-October 02

Posted 15 February 2003 - 01:16 PM

I did not spent a time reading your code yet :)
but eMules answers to any eDonkey (old or new Hybrid) with version 60 of eDonkey so they talk using v60 protocol ,
if you want to implement new protocol features you will have to change the replay version to at least 44 (1044) but then we will have to support this protocol fully .
Partual implementation will only lead to problems .

Anyway the thing I liked in new protocol most was OP_ASKSHAREDDENIEDANS :)

This post has been edited by Lord KiRon: 15 February 2003 - 01:31 PM

0

#3 User is offline   SlugFiller 

  • The one and only master slug
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 6988
  • Joined: 15-September 02

Posted 15 February 2003 - 02:11 PM

Finally! I was hoping for a directory-structure including ask-shared-files. My own file-names mean nothing without their appropriate directories, and I've seen this in many others. I'll be more than glad to see this(as well as the rest of the new protocol) implemented in eMule as soon as possible.
Why haven't you clicked yet?

SlugFiller rule #1: Unsolicited PMs is the second most efficient method to piss me off.
SlugFiller rule #2: The first most efficient method is unsolicited eMails.
SlugFiller rule #3: If it started in a thread, it should end in the same thread.
SlugFiller rule #4: There is absolutely no reason to perform the same discussion twice in parallel, especially if one side is done via PM.
SlugFiller rule #5: Does it say "Group: Moderators" under my name? No? Then stop telling me about who you want to ban! I really don't care! Go bother a moderator.
SlugFiller rule #6: I can understand English, Hebrew, and a bit of Japanese(standard) and Chinese(mandarin), but if you speak to me in anything but English, do expect to be utterly ignored, at best.
0

#4 User is offline   bluecow 

  • The Merciful
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1772
  • Joined: 27-December 02

Posted 15 February 2003 - 04:18 PM

Lord KiRon, on Feb 15 2003, 02:16 PM, said:

but eMules answers to any eDonkey (old or new Hybrid) with version 60 of eDonkey so they talk using v60 protocol

AFAIK they do not (concerning the shared files), although they should.
0

#5 User is offline   bluecow 

  • The Merciful
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1772
  • Joined: 27-December 02

Posted 14 March 2003 - 09:13 AM

I'm really surprised that my code was merged into the official -- because there was so few response :(

Anyway, there's bug in 0.27a. The nr. of category directories is also to be added to the total nr. of directories.

Quote

    case OP_ASKSHAREDDIRS:{
        theApp.downloadqueue->AddDownDataOverheadOther(size);
        ASSERT( size == 0 );
        if (theApp.glob_prefs->CanSeeShares()==0 || (theApp.glob_prefs->CanSeeShares()==1 && client->IsFriend())){
            theApp.emuledlg->AddLogLine(true,"User %s (%u) requested your shareddirectories-list -> %s",client->GetUserName(),client->GetUserID(),GetResString(IDS_ACCEPTED) );
   
            CSafeMemFile tempfile(80);
            uint32 uDirs = theApp.glob_prefs->shareddir_list.GetCount() + theApp.glob_prefs->GetCatCount();
            tempfile.Write(&uDirs, 4);
                       

0

#6 User is offline   basketor64 

  • Golden eMule
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2036
  • Joined: 07-October 02

Posted 14 March 2003 - 01:07 PM

yes that's great !
Combined with the emule that search on LAN by multicast, it would be better than windows file sharing and ftp !
0

  • Member Options

Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users