Changeset 634
- Timestamp:
- 03/14/07 00:41:55 (18 months ago)
- Location:
- branches/newnet/museekd
- Files:
-
- 8 modified
-
. (modified) (1 prop)
-
SConstruct (modified) (1 diff)
-
museekd/downloadmanager.cpp (modified) (10 diffs)
-
museekd/downloadmanager.h (modified) (4 diffs)
-
museekd/ifacemanager.cpp (modified) (2 diffs)
-
museekd/ifacemanager.h (modified) (3 diffs)
-
museekd/ifacemessages.h (modified) (1 diff)
-
museekd/main.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/newnet/museekd
- Property svn:externals
-
old new 1 NewNet -r 566https://svn.thegraveyard.org:8043/repos/NewNet/trunk/NewNet1 NewNet -r640 https://svn.thegraveyard.org:8043/repos/NewNet/trunk/NewNet
-
- Property svn:externals
-
branches/newnet/museekd/SConstruct
r597 r634 3 3 env.SConsignFile() 4 4 env.Append(CCFLAGS = ['-Wall']) 5 env.Append(LINKFLAGS = ['-Wall']) 5 6 #env.Append(CPPDEFINES = ['NN_PTR_DEBUG']) 6 7 env.Append(CPPDEFINES = ['NN_PTR_DEBUG', 'NN_PTR_DEBUG_ASSERT']) -
branches/newnet/museekd/museekd/downloadmanager.cpp
r632 r634 39 39 { 40 40 // 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) 43 43 { 44 44 // 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; 51 51 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; 57 56 58 57 /* If we have an active peer socket send the transfer request. If we don't … … 62 61 { 63 62 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); 65 64 socket->sendMessage(msg.make_network_packet()); 66 65 } … … 103 102 } 104 103 105 std::vector<Museek::DownloadManager::Download>::iterator 104 Museek::DownloadManager::Download * 106 105 Museek::DownloadManager::findDownload(const std::string & user, const std::string & path) 107 106 { 108 107 // 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(); 110 109 for(it = m_Downloads.begin(); it != end; ++it) 111 110 { 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 117 Museek::DownloadManager::Download * 119 118 Museek::DownloadManager::findDownload(const std::string & user, uint ticket) 120 119 { 121 120 // 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(); 123 122 for(it = m_Downloads.begin(); it != end; ++it) 124 123 { 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; 129 128 } 130 129 … … 152 151 { 153 152 // 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(); 155 154 for(it = m_Downloads.begin(); it != end; ++it) 156 155 { 157 (*it) .state = TS_Offline;156 (*it)->state = TS_Offline; 158 157 } 159 158 } … … 172 171 if(message->status > 0) 173 172 { 174 std::vector<Download > downloads;173 std::vector<Download *> downloads; 175 174 // 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(); 177 176 for(dit = m_Downloads.begin(); dit != dend; ++dit) 178 177 { 179 if(((*dit) .user == message->user) && ((*dit).state == TS_Offline))178 if(((*dit)->user == message->user) && ((*dit)->state == TS_Offline)) 180 179 { 181 180 // Yep. Push it on the list. … … 202 201 203 202 // 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); 210 207 // Change the state to negotiating. 211 (* it).state = TS_Negotiating;208 (*sit)->state = TS_Negotiating; 212 209 // Send the transfer request. 213 PTransferRequest msg((* it).ticket, (*it).path);210 PTransferRequest msg((*sit)->ticket, (*sit)->path); 214 211 socket->sendMessage(msg.make_network_packet()); 215 212 } … … 235 232 236 233 // 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(); 238 235 for(dit = m_Downloads.begin(); dit != dend; ++dit) 239 236 { 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; 242 239 } 243 240 } … … 248 245 // Find the download this concerns. 249 246 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) 252 249 return; // No such download, bail out. 253 250 … … 255 252 { 256 253 // 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); 258 255 NNLOG("museek.debug", "Ehm.. We're supposed to do something here: connect to %s and claim our prize...", user.c_str()); 259 256 } … … 261 258 { 262 259 // 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 23 23 #include <NewNet/nnobject.h> 24 24 #include <NewNet/nnweakrefptr.h> 25 #include <NewNet/nnrefptr.h> 25 26 #include "mutypes.h" 26 27 … … 44 45 public: 45 46 /* Definition of the download structure. */ 46 typedef struct47 class Download : public NewNet::Object 47 48 { 49 public: 48 50 uint ticket; // The download ticket with which this download is identified 49 51 std::string user, path, localPath; 50 52 TrState state; // Transfer state (see mutypes.h) 51 53 std::string error; // Error message if state = TR_Error 52 } Download;54 }; 53 55 54 56 DownloadManager(Museekd * museekd); … … 70 72 protected: 71 73 /* Find a download by it's path. */ 72 std::vector<Download>::iteratorfindDownload(const std::string & user, const std::string & path);74 Download * findDownload(const std::string & user, const std::string & path); 73 75 /* Find a download by it's ticket. */ 74 std::vector<Download>::iteratorfindDownload(const std::string & user, uint ticket);76 Download * findDownload(const std::string & user, uint ticket); 75 77 76 78 /* Find or make a peer socket for the specified user. */ … … 84 86 85 87 NewNet::WeakRefPtr<Museekd> m_Museekd; 86 std::vector< Download> m_Downloads;88 std::vector<NewNet::RefPtr<Download> > m_Downloads; 87 89 std::map<std::string, NewNet::WeakRefPtr<PeerSocket> > m_Peers; 88 90 }; -
branches/newnet/museekd/museekd/ifacemanager.cpp
r631 r634 66 66 m_AwayState = 0; 67 67 68 NNLOG.logEvent.connect(this, &IfaceManager::onLog); 69 68 70 museekd->config()->keySetEvent.connect(this, &IfaceManager::onConfigKeySet); 69 71 museekd->config()->keyRemovedEvent.connect(this, &IfaceManager::onConfigKeyRemoved); … … 154 156 m_ServerSockets.erase(it); 155 157 m_Factories.erase(m_Factories.find(path)); 158 } 159 160 void 161 Museek::IfaceManager::onLog(const NewNet::Log::LogNotify * log) 162 { 163 SEND_MASK(EM_DEBUG, IDebugMessage(log->domain, log->message)); 156 164 } 157 165 -
branches/newnet/museekd/museekd/ifacemanager.h
r631 r634 54 54 EM_USERSHARES = 16, 55 55 EM_INTERESTS = 32, 56 EM_CONFIG = 64 56 EM_CONFIG = 64, 57 EM_DEBUG = 128 57 58 }; 58 59 … … 69 70 70 71 void flushPrivateMessages(); 72 73 // Log event handler: 74 void onLog(const NewNet::Log::LogNotify * notice); 71 75 72 76 // Config changed listener events: … … 133 137 void onServerItemSimilarUsersReceived(const SGetItemSimilarUsers * message); 134 138 void onServerUserInterestsReceived(const SUserInterests * message); 139 135 140 // Peer event handlers: 136 141 void onPeerCannotConnect(NewNet::ClientSocket * socket); -
branches/newnet/museekd/museekd/ifacemessages.h
r611 r634 284 284 bool type; 285 285 std::string message; 286 END 287 288 IFACEMESSAGE(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; 286 306 END 287 307 -
branches/newnet/museekd/museekd/main.cpp
r633 r634 74 74 }; 75 75 76 class LogCallback : public NewNet::Event<const NewNet::Log::LogNotify *>::Callback 77 { 78 public: 79 virtual void operator()(const NewNet::Log::LogNotify * notice) 80 { 81 std::cerr << "[" << notice->domain << "] " << notice->message << std::endl; 82 } 83 }; 84 76 85 int main(int argc, char ** argv) 77 86 { 78 87 /* Enable various interesting logging domains. */ 88 NNLOG.logEvent.connect(new LogCallback); 79 89 NNLOG.enable("ALL"); 80 90
