Logo Search packages:      
Sourcecode: verlihub version File versions

int nDirectConnect::cServerDC::DoRegisterInHublist ( string  host,
int  port,
string  NickForReply 
)

does the registration on given hublist

Definition at line 1180 of file cserverdc.cpp.

References nServer::cAsyncConn::Close(), DCPublicHS(), GetTotalShareSize(), nDirectConnect::nTables::cDCConf::hub_desc, nDirectConnect::nTables::cDCConf::hub_host, nDirectConnect::nTables::cDCConf::hub_name, nDirectConnect::nTables::cDCConf::hublist_send_minshare, cObj::Log(), cObj::LogStream(), nDirectConnect::nTables::cDCConf::min_share, nDirectConnect::nTables::cDCConf::min_share_use_hub, nDirectConnect::cUser::mxConn, nServer::cAsyncConn::ok, nServer::cAsyncConn::ReadAll(), nServer::cAsyncConn::ReadLineLocal(), nServer::cAsyncConn::SetLineToRead(), and nServer::cAsyncConn::Write().

Referenced by RegisterInHublist().

{
      ostringstream os, os2;
      char pipe='|';
#ifndef _WIN32
      unsigned long long buf = GetTotalShareSize();
#else
      char buf[32];
      sprintf(buf,"%ui64d",GetTotalShareSize());
#endif

      istringstream is(host);
      string CurHost;
      string lock, key;
      size_t pos_space;
      cAsyncConn *pHubList;

      os2 << "Hublist Register results: \r\n";
      while (CurHost = "", is >> CurHost, CurHost.size() > 0)
      {
            os2 << "Sending to " << CurHost << ":" << port;
            pHubList = new cAsyncConn(CurHost,port);

            if(!pHubList->ok)
            {
                  os2 << " ..connection not established\r\n";
                  pHubList->Close();
                  delete pHubList;
                  pHubList = 0;
                  continue;
            }

            key = "";
            pHubList->SetLineToRead(&lock,pipe,1024);
            pHubList->ReadAll();
            pHubList->ReadLineLocal();
            if(lock.size() > 6) {
                  pos_space = lock.find(' ',6);
                  if (pos_space != lock.npos) pos_space -= 6;
                  lock = lock.substr(6,pos_space);
                  cDCProto::Lock2Key(lock, key);
            }
            
            // Create the registration string
            os.str(mEmpty);
            os << "$Key " << key << pipe <<  mC.hub_name // removed pipe before name
                  << pipe << mC.hub_host
                  << pipe;
            __int64 hl_minshare = mC.min_share;
            if (mC.min_share_use_hub > hl_minshare) hl_minshare = mC.min_share_use_hub;
            if (mC.hublist_send_minshare) os << "[MINSHARE:" << StringFrom(hl_minshare) << "MB] ";
            os << mC.hub_desc
                  << pipe << mUserList.size()
                  << pipe << buf
                  << pipe;


            // send it
            if(Log(2)) LogStream() << os.str() << endl;
            pHubList->Write(os.str(), true);
            if(!pHubList->ok) os2 << " ..Error in sending \r\n" << endl;
            pHubList->Close();
            delete pHubList;
            pHubList = NULL;
            os2 << " .. ok\r\n";
      }

      os2 << "Done";
      CurHost = os2.str();
      if (NickForReply.size() > 0) {
            cUser * user = mUserList.GetUserByNick(NickForReply);
            if (user && user->mxConn) DCPublicHS(CurHost, user->mxConn);
      }
      return 1;
}


Generated by  Doxygen 1.6.0   Back to index