Changeset 634

Show
Ignore:
Timestamp:
03/14/07 00:41:55 (18 months ago)
Author:
hyriand
Message:

Synced NewNet with r640. Downloadmanager now stores RefPtr?'s to Download classes. Logging is now sent to interfaces as IDebugMessage if EM_DEBUG is set.

Location:
branches/newnet/museekd
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • branches/newnet/museekd

    • Property svn:externals
      •  

        old new  
        1 NewNet -r566 https://svn.thegraveyard.org:8043/repos/NewNet/trunk/NewNet 
         1NewNet -r640 https://svn.thegraveyard.org:8043/repos/NewNet/trunk/NewNet 
  • branches/newnet/museekd/SConstruct

    r597 r634  
    33env.SConsignFile() 
    44env.Append(CCFLAGS = ['-Wall']) 
     5env.Append(LINKFLAGS = ['-Wall']) 
    56#env.Append(CPPDEFINES = ['NN_PTR_DEBUG']) 
    67env.Append(CPPDEFINES = ['NN_PTR_DEBUG', 'NN_PTR_DEBUG_ASSERT']) 
  • branches/newnet/museekd/museekd/downloadmanager.cpp

    r632 r634  
    3939{ 
    4040  // Check if this download already exits. 
    41   std::vector<Download>::iterator it = findDownload(user, path); 
    42   if(it == m_Downloads.end()) 
     41  Download * download = findDownload(user, path); 
     42  if(! download) 
    4343  { 
    4444    // Create new download object. 
    45     Download download; 
    46     download.ticket = m_Museekd->token(); 
    47     download.user = user; 
    48     download.path = path; 
    49     download.localPath = localPath; 
    50     download.state = TS_Offline; 
     45    download = new Download; 
     46    download->ticket = m_Museekd->token(); 
     47    download->user = user; 
     48    download->path = path; 
     49    download->localPath = localPath; 
     50    download->state = TS_Offline; 
    5151    m_Downloads.push_back(download); 
    52     it = m_Downloads.end() - 1; 
    53     NNLOG("museek.debug", "Created new download entry, user=%s, path=%s, ticket=%u.", user.c_str(), path.c_str(), (*it).ticket); 
    54   } 
    55  
    56   (*it).state = TS_Offline; 
     52    NNLOG("museek.debug", "Created new download entry, user=%s, path=%s, ticket=%u.", user.c_str(), path.c_str(), download->ticket); 
     53  } 
     54 
     55  download->state = TS_Offline; 
    5756 
    5857  /* If we have an active peer socket send the transfer request. If we don't 
     
    6261  { 
    6362    NNLOG("museek.debug", "Already have a socket for %s, sending download request.", user.c_str()); 
    64     PTransferRequest msg((*it).ticket, path); 
     63    PTransferRequest msg(download->ticket, path); 
    6564    socket->sendMessage(msg.make_network_packet()); 
    6665  } 
     
    103102} 
    104103 
    105 std::vector<Museek::DownloadManager::Download>::iterator 
     104Museek::DownloadManager::Download * 
    106105Museek::DownloadManager::findDownload(const std::string & user, const std::string & path) 
    107106{ 
    108107  // Iterate over m_Downloads until we find a match. 
    109   std::vector<Download>::iterator it, end = m_Downloads.end(); 
     108  std::vector<NewNet::RefPtr<Download> >::iterator it, end = m_Downloads.end(); 
    110109  for(it = m_Downloads.begin(); it != end; ++it) 
    111110  { 
    112     if(((*it).user == user) && ((*it).path == path)) 
    113       return it; 
    114   } 
    115   return end; 
    116 } 
    117  
    118 std::vector<Museek::DownloadManager::Download>::iterator 
     111    if(((*it)->user == user) && ((*it)->path == path)) 
     112      return *it; 
     113  } 
     114  return 0; 
     115} 
     116 
     117Museek::DownloadManager::Download * 
    119118Museek::DownloadManager::findDownload(const std::string & user, uint ticket) 
    120119{ 
    121120  // Iterate over m_Downloads until we find a match. 
    122   std::vector<Download>::iterator it, end = m_Downloads.end(); 
     121  std::vector<NewNet::RefPtr<Download> >::iterator it, end = m_Downloads.end(); 
    123122  for(it = m_Downloads.begin(); it != end; ++it) 
    124123  { 
    125     if(((*it).user == user) && ((*it).ticket == ticket)) 
    126       return it; 
    127   } 
    128   return end; 
     124    if(((*it)->user == user) && ((*it)->ticket == ticket)) 
     125      return *it; 
     126  } 
     127  return 0; 
    129128} 
    130129 
     
    152151  { 
    153152    // Server connection was severed. As are our chances to connect to a peer. 
    154     std::vector<Download>::iterator it, end = m_Downloads.end(); 
     153    std::vector<NewNet::RefPtr<Download> >::iterator it, end = m_Downloads.end(); 
    155154    for(it = m_Downloads.begin(); it != end; ++it) 
    156155    { 
    157       (*it).state = TS_Offline; 
     156      (*it)->state = TS_Offline; 
    158157    } 
    159158  } 
     
    172171  if(message->status > 0) 
    173172  { 
    174     std::vector<Download> downloads; 
     173    std::vector<Download *> downloads; 
    175174    // Check if we have any downloads with status user offline for this user. 
    176     std::vector<Download>::iterator dit, dend = m_Downloads.end(); 
     175    std::vector<NewNet::RefPtr<Download> >::iterator dit, dend = m_Downloads.end(); 
    177176    for(dit = m_Downloads.begin(); dit != dend; ++dit) 
    178177    { 
    179       if(((*dit).user == message->user) && ((*dit).state == TS_Offline)) 
     178      if(((*dit)->user == message->user) && ((*dit)->state == TS_Offline)) 
    180179      { 
    181180        // Yep. Push it on the list. 
     
    202201 
    203202    // Iterate of the downloads with status TS_Offline. 
    204     dend = downloads.end(); 
    205     for(dit = downloads.begin(); dit != dend; ++dit) 
    206     { 
    207       // Find the reference to the original download. 
    208       std::vector<Download>::iterator it = findDownload((*dit).user, (*dit).path); 
    209       NNLOG("museek.debug", "Requesting download from %s, path=%s, ticket=%u", (*it).user.c_str(), (*it).path.c_str(), (*it).ticket); 
     203    std::vector<Download *>::iterator sit, send = downloads.end(); 
     204    for(sit = downloads.begin(); sit != send; ++sit) 
     205    { 
     206      NNLOG("museek.debug", "Requesting download from %s, path=%s, ticket=%u", (*sit)->user.c_str(), (*sit)->path.c_str(), (*sit)->ticket); 
    210207      // Change the state to negotiating. 
    211       (*it).state = TS_Negotiating; 
     208      (*sit)->state = TS_Negotiating; 
    212209      // Send the transfer request. 
    213       PTransferRequest msg((*it).ticket, (*it).path); 
     210      PTransferRequest msg((*sit)->ticket, (*sit)->path); 
    214211      socket->sendMessage(msg.make_network_packet()); 
    215212    } 
     
    235232 
    236233  // Change status for pending transfers to 'cannot connect'. 
    237   std::vector<Download>::iterator dit, dend = m_Downloads.end(); 
     234  std::vector<NewNet::RefPtr<Download> >::iterator dit, dend = m_Downloads.end(); 
    238235  for(dit = m_Downloads.begin(); dit != dend; ++dit) 
    239236  { 
    240     if(((*dit).user == user) && ((*dit).state == TS_Negotiating)) 
    241       (*dit).state = TS_CannotConnect; 
     237    if(((*dit)->user == user) && ((*dit)->state == TS_Negotiating)) 
     238      (*dit)->state = TS_CannotConnect; 
    242239  } 
    243240} 
     
    248245  // Find the download this concerns. 
    249246  const std::string & user = message->peerSocket()->user(); 
    250   std::vector<Download>::iterator it = findDownload(user, message->ticket); 
    251   if(it == m_Downloads.end()) 
     247  Download * download = findDownload(user, message->ticket); 
     248  if(! download) 
    252249    return; // No such download, bail out. 
    253250 
     
    255252  { 
    256253    // Transfer can start immediately, no queue at remote end. 
    257     NNLOG("museek.debug", "Got transfer reply: user=%s,path=%s,ticket=%u,allowed=yes,filesize=%llu", user.c_str(), (*it).path.c_str(), (*it).ticket, message->filesize); 
     254    NNLOG("museek.debug", "Got transfer reply: user=%s,path=%s,ticket=%u,allowed=yes,filesize=%llu", user.c_str(), download->path.c_str(), download->ticket, message->filesize); 
    258255    NNLOG("museek.debug", "Ehm.. We're supposed to do something here: connect to %s and claim our prize...", user.c_str()); 
    259256  } 
     
    261258  { 
    262259    // Transfer (currently) not possible. 
    263     NNLOG("museek.debug", "Got transfer reply: user=%s,path=%s,ticket=%u,allowed=no,reason=%s", user.c_str(), (*it).path.c_str(), (*it).ticket, message->reason.c_str()); 
    264     (*it).state = TS_RemoteError; 
    265     (*it).error = message->reason; 
    266   } 
    267 } 
     260    NNLOG("museek.debug", "Got transfer reply: user=%s,path=%s,ticket=%u,allowed=no,reason=%s", user.c_str(), download->path.c_str(), download->ticket, message->reason.c_str()); 
     261    download->state = TS_RemoteError; 
     262    download->error = message->reason; 
     263  } 
     264} 
  • branches/newnet/museekd/museekd/downloadmanager.h

    r627 r634  
    2323#include <NewNet/nnobject.h> 
    2424#include <NewNet/nnweakrefptr.h> 
     25#include <NewNet/nnrefptr.h> 
    2526#include "mutypes.h" 
    2627 
     
    4445  public: 
    4546    /* Definition of the download structure. */ 
    46     typedef struct 
     47    class Download : public NewNet::Object 
    4748    { 
     49    public: 
    4850      uint ticket; // The download ticket with which this download is identified 
    4951      std::string user, path, localPath; 
    5052      TrState state; // Transfer state (see mutypes.h) 
    5153      std::string error; // Error message if state = TR_Error 
    52     } Download; 
     54    }; 
    5355 
    5456    DownloadManager(Museekd * museekd); 
     
    7072  protected: 
    7173    /* Find a download by it's path. */ 
    72     std::vector<Download>::iterator findDownload(const std::string & user, const std::string & path); 
     74    Download * findDownload(const std::string & user, const std::string & path); 
    7375    /* Find a download by it's ticket. */ 
    74     std::vector<Download>::iterator findDownload(const std::string & user, uint ticket); 
     76    Download * findDownload(const std::string & user, uint ticket); 
    7577 
    7678    /* Find or make a peer socket for the specified user. */ 
     
    8486 
    8587    NewNet::WeakRefPtr<Museekd> m_Museekd; 
    86     std::vector<Download> m_Downloads; 
     88    std::vector<NewNet::RefPtr<Download> > m_Downloads; 
    8789    std::map<std::string, NewNet::WeakRefPtr<PeerSocket> > m_Peers; 
    8890  }; 
  • branches/newnet/museekd/museekd/ifacemanager.cpp

    r631 r634  
    6666  m_AwayState = 0; 
    6767 
     68  NNLOG.logEvent.connect(this, &IfaceManager::onLog); 
     69 
    6870  museekd->config()->keySetEvent.connect(this, &IfaceManager::onConfigKeySet); 
    6971  museekd->config()->keyRemovedEvent.connect(this, &IfaceManager::onConfigKeyRemoved); 
     
    154156  m_ServerSockets.erase(it); 
    155157  m_Factories.erase(m_Factories.find(path)); 
     158} 
     159 
     160void 
     161Museek::IfaceManager::onLog(const NewNet::Log::LogNotify * log) 
     162{ 
     163  SEND_MASK(EM_DEBUG, IDebugMessage(log->domain, log->message)); 
    156164} 
    157165 
  • branches/newnet/museekd/museekd/ifacemanager.h

    r631 r634  
    5454      EM_USERSHARES = 16, 
    5555      EM_INTERESTS = 32, 
    56       EM_CONFIG = 64 
     56      EM_CONFIG = 64, 
     57      EM_DEBUG = 128 
    5758    }; 
    5859 
     
    6970 
    7071    void flushPrivateMessages(); 
     72 
     73    // Log event handler: 
     74    void onLog(const NewNet::Log::LogNotify * notice); 
    7175 
    7276    // Config changed listener events: 
     
    133137    void onServerItemSimilarUsersReceived(const SGetItemSimilarUsers * message); 
    134138    void onServerUserInterestsReceived(const SUserInterests * message); 
     139 
    135140    // Peer event handlers: 
    136141    void onPeerCannotConnect(NewNet::ClientSocket * socket); 
  • branches/newnet/museekd/museekd/ifacemessages.h

    r611 r634  
    284284        bool type; 
    285285        std::string message; 
     286END 
     287 
     288IFACEMESSAGE(IDebugMessage, 0x0011) 
     289/* 
     290        Debug Message -- Forward debug messages to the clients 
     291         
     292        *not sent* 
     293         
     294        string domain -- Contains the domain the debug message was emitted in 
     295        string message -- Contains the debug message 
     296*/ 
     297         
     298        IDebugMessage(const std::string& _d, const std::string& _m) : domain(_d), message(_m) { } 
     299 
     300        MAKE 
     301                pack(domain); 
     302                pack(message); 
     303        END_MAKE 
     304 
     305        std::string domain, message; 
    286306END 
    287307 
  • branches/newnet/museekd/museekd/main.cpp

    r633 r634  
    7474}; 
    7575 
     76class LogCallback : public NewNet::Event<const NewNet::Log::LogNotify *>::Callback 
     77{ 
     78public: 
     79  virtual void operator()(const NewNet::Log::LogNotify * notice) 
     80  { 
     81    std::cerr << "[" << notice->domain << "] " << notice->message << std::endl; 
     82  } 
     83}; 
     84 
    7685int main(int argc, char ** argv) 
    7786{ 
    7887  /* Enable various interesting logging domains. */ 
     88  NNLOG.logEvent.connect(new LogCallback); 
    7989  NNLOG.enable("ALL"); 
    8090