Esempio n. 1
0
uint32 CRoutingZone::GetBootstrapContacts(ContactList *plistResult, uint32 uMaxRequired)
{
	ASSERT(m_pSuperZone == NULL);
	plistResult->clear();
	uint32 uRetVal = 0;
	try
	{
		ContactList top;
		TopDepth(LOG_BASE_EXPONENT, &top);
		if (top.size() > 0)
		{
			for (ContactList::const_iterator itContactList = top.begin(); itContactList != top.end(); ++itContactList)
			{
				plistResult->push_back(*itContactList);
				uRetVal++;
				if (uRetVal == uMaxRequired)
					break;
			}
		}
	}
	catch (...)
	{
		AddDebugLogLine(false, _T("Exception in CRoutingZone::getBoostStrapContacts"));
	}
	return uRetVal;
}
Esempio n. 2
0
void CRoutingZone::WriteFile()
{
	// don't overwrite a bootstrap nodes.dat with an empty one, if we didn't finished probing
	if (!CKademlia::s_liBootstapList.IsEmpty() && GetNumContacts() == 0){
		DebugLogWarning(_T("Skipped storing nodes.dat, because we have an unfinished bootstrap of the nodes.dat version and no contacts in our routing table"));
		return;
	}
	try
	{
		// Write a saved contact list.
		CUInt128 uID;
		CSafeBufferedFile file;
		CFileException fexp;
		if (file.Open(m_sFilename, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary|CFile::shareDenyWrite, &fexp))
		{
			setvbuf(file.m_pStream, NULL, _IOFBF, 32768);

			// The bootstrap method gets a very nice sample of contacts to save.
			ContactList listContacts;
			GetBootstrapContacts(&listContacts, 200);
			// Start file with 0 to prevent older clients from reading it.
			file.WriteUInt32(0);
			// Now tag it with a version which happens to be 2 (1 till 0.48a).
			file.WriteUInt32(2);
			// file.WriteUInt32(0) // if we would use version >=3, this would mean that this is a normal nodes.dat
			file.WriteUInt32((uint32_t)listContacts.size());
			for (ContactList::const_iterator itContactList = listContacts.begin(); itContactList != listContacts.end(); ++itContactList)
			{
				CContact* pContact = *itContactList;
				pContact->GetClientID(&uID);
				file.WriteUInt128(&uID);
				file.WriteUInt32(pContact->GetIPAddress());
				file.WriteUInt16(pContact->GetUDPPort());
				file.WriteUInt16(pContact->GetTCPPort());
				file.WriteUInt8(pContact->GetVersion());
				pContact->GetUDPKey().StoreToFile(file);
				file.WriteUInt8(pContact->IsIpVerified() ? 1 : 0);
			}
			file.Close();
			AddDebugLogLine( false, _T("Wrote %ld contact%s to file."), listContacts.size(), ((listContacts.size() == 1) ? _T("") : _T("s")));
		}
		else
			DebugLogError(_T("Unable to store Kad file: %s"), m_sFilename);
	}
	catch (CFileException* e)
	{
		e->Delete();
		AddDebugLogLine(false, _T("CFileException in CRoutingZone::writeFile"));
	}
}
void ContactsTreeWidget::loadAvatars() {
  appInstance->logEvent("ContactsTreeWidget::loadAvatars()", SEVERITY_DEBUG);
  GroupList *gl = appInstance->mUser->getGroupList();
  ContactList *cl;
  ContactList::iterator c**t;
  GroupList::iterator glIt;
  for(glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    for(c**t = cl->begin(); c**t != cl->end(); c**t++) {
      if (addedContacts[c**t->getIndex()]) {
        c**t->setAvatar(MrimUtils::prepareAvatar(c**t->getAddress()));
        addedContacts[c**t->getIndex()][columns.contactAvatar] = resizeAvatar(c**t->getAvatar());
      }
    }
  }
}
Esempio n. 4
0
void CRoutingZone::Split()
{
	StopTimer();

	m_pSubZones[0] = GenSubZone(0);
	m_pSubZones[1] = GenSubZone(1);

	ContactList listEntries;
	m_pBin->GetEntries(&listEntries);
	for (ContactList::const_iterator itContactList = listEntries.begin(); itContactList != listEntries.end(); ++itContactList)
	{
		int iSuperZone = (*itContactList)->m_uDistance.GetBitNumber(m_uLevel);
		m_pSubZones[iSuperZone]->m_pBin->AddContact(*itContactList);
	}
	m_pBin->m_bDontDeleteContacts = true;
	delete m_pBin;
	m_pBin = NULL;
}
Esempio n. 5
0
void WPclient::SignalServerContactEvent(ServerBasedContactEvent* ev) {
    log_debug(ZONE,"Got server based contact list, importing");
    ContactList l = ev->getContactList();
    ContactList::iterator curr = l.begin();
    while (curr != l.end()) {
      contact c = it_contact_get(sesja,(*curr)->getUIN());
      if (c == NULL) {
        /* new contact not yet in our list */
        c = it_contact_add(sesja,(*curr)->getUIN());
        if(c != NULL)
          it_contact_subscribe(c,(*curr)->getAlias().c_str());
        log_debug(ZONE,"Imported UIN %ul", (*curr)->getUIN());
      } else
        log_debug(ZONE,"Skipped UIN %ul (already in list)", (*curr)->getUIN());
      ++curr;
    }
    log_debug(ZONE,"Finished import");
}
Esempio n. 6
0
void CRoutingZone::Split()
{
    StopTimer();

    m_subZones[0] = GenSubZone(0);
    m_subZones[1] = GenSubZone(1);

    ContactList entries;
    m_bin->GetEntries(&entries);
    m_bin->m_dontDeleteContacts = true;
    delete m_bin;
    m_bin = NULL;

    for (ContactList::const_iterator it = entries.begin(); it != entries.end(); ++it) {
        if (!m_subZones[(*it)->GetDistance().GetBitNumber(m_level)]->m_bin->AddContact(*it)) {
            delete *it;
        }
    }
}
Esempio n. 7
0
void CRoutingZone::WriteFile()
{
	try
	{
		// Write a saved contact list.
		CUInt128 uID;
		//CSafeBufferedFile file;
		CBufferedFileIO file;
		CFileException fexp;
		if (file.Open(m_sFilename, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary|CFile::shareDenyWrite, &fexp))
		{
			setvbuf(file.m_pStream, NULL, _IOFBF, 32768);

			// The bootstrap method gets a very nice sample of contacts to save.
			ContactList listContacts;
			GetBootstrapContacts(&listContacts, 200);
			// Start file with 0 to prevent older clients from reading it.
			file.WriteUInt32(0);
			// Now tag it with a version which happens to be 1.
			file.WriteUInt32(1);
			file.WriteUInt32((uint32)listContacts.size());
			for (ContactList::const_iterator itContactList = listContacts.begin(); itContactList != listContacts.end(); ++itContactList)
			{
				CContact* pContact = *itContactList;
				pContact->GetClientID(&uID);
				file.WriteUInt128(&uID);
				file.WriteUInt32(pContact->GetIPAddress());
				file.WriteUInt16(pContact->GetUDPPort());
				file.WriteUInt16(pContact->GetTCPPort());
				file.WriteUInt8(pContact->GetVersion());
			}
			file.Close();
			//AddDebugLogLine( false, _T("Wrote %ld contact%s to file."), listContacts.size(), ((listContacts.size() == 1) ? _T("") : _T("s")));
			TRACE(_T("Wrote %ld contact%s to file.\n"), listContacts.size(), ((listContacts.size() == 1) ? _T("") : _T("s")));
		}
	}
	catch (CFileException* e)
	{
		e->Delete();
		AddDebugLogLine(false, _T("CFileException in CRoutingZone::writeFile"));
	}
}
Esempio n. 8
0
uint32_t CRoutingZone::GetBootstrapContacts(ContactList *results, uint32_t maxRequired) const
{
    ASSERT(m_superZone == NULL);

    results->clear();

    uint32_t count = 0;
    ContactList top;
    TopDepth(LOG_BASE_EXPONENT, &top);
    if (top.size() > 0) {
        for (ContactList::const_iterator it = top.begin(); it != top.end(); ++it) {
            results->push_back(*it);
            count++;
            if (count == maxRequired) {
                break;
            }
        }
    }

    return count;
}
void ContactsTreeWidget::loadContactList() {
  appInstance->logEvent("ContactsTreeWidget::loadContactList()", SEVERITY_DEBUG);
  GroupList *gl = appInstance->mUser->getGroupList();
  ContactList *cl;
  ContactList::iterator c**t;
  GroupList::iterator glIt;
  appInstance->mainWindow->contactsTree->treeModel->clear();
  for (glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    // prevent adding empty "Unauthorized" group
    if(glIt->first != GROUP_INDEX_NOT_AUTHORIZED || !cl->empty()) {
      appInstance->mainWindow->contactsTree->addGroup(glIt->first, glIt->second);
    }
  }
  for (glIt = gl->begin(); glIt != gl->end(); glIt++) {
    cl = glIt->second.contacts();
    for(c**t = cl->begin(); c**t != cl->end(); c**t++) {
      appInstance->mainWindow->contactsTree->addContact(*c**t);
    }
  }
  appInstance->mainWindow->contactsTree->loadAvatars();
}
Esempio n. 10
0
wxmailto_status Smtp::Sync()
{
	/*************************/
	if (TestDestroy())
		return CleanupAndAbort();
	/*************************/

	wxmailto_status status;
	OutgoingMessageList message_list;
	if (ID_OK!=(status=wxGetApp().GetAppModuleManager()->GetMessageStore()->GetOutgoingMessages(message_list)))
		return status;

	if (message_list.IsEmpty())
		return ID_OK;

	/*************************/
	if (TestDestroy())
		return CleanupAndAbort();
	/*************************/
	
	if (ID_OK!=(status=InitializeAndConnectSocket()) ||
	    ID_OK!=(status=ReadInitialGreeting()))
	{
		return status;
	}

	/*************************/
	if (TestDestroy())
		return CleanupAndAbort();
	/*************************/

	wxString read_string, write_string;

	wxString fqdn_idna_domain;
	wxASSERT(true==IdnaGlue::ToASCII(GetAccount()->GetFQDN(), fqdn_idna_domain));

	if (m_supported_ehlo_features.m_ehlo_supported)
	{
		if (ID_OK!=HandleEHLO(fqdn_idna_domain))
		{
			m_supported_ehlo_features.DisableEhloSupport();
			return Sync(); //Call self, but without EHLO support
		}
	} else {
		if (ID_OK!=(status=HandleHELO(fqdn_idna_domain)))
		{
			HandleQUIT();
			return status;
		}
	}

	/*************************/
	if (TestDestroy())
		return CleanupAndAbort();
	/*************************/

	OutgoingMessageList::iterator iter;
	for (iter=message_list.begin(); iter!=message_list.end(); ++iter)
	{
		/*************************/
		if (TestDestroy())
			return CleanupAndAbort();
		/*************************/

		OutgoingMessage* message = *iter;
		if (!message)
			continue;

		wxASSERT(message->HasTag(wxGetApp().GetAppModuleManager()->GetMessageStore()->GetOutboxTag()));
		wxASSERT(NULL!=message->GetFrom());

		ContactList recipients;
		if (ID_OK!=(status=message->GetAllRecipients(recipients)) ||
		    (iter!=message_list.begin() && ID_OK!=(status=HandleRSET())) || //RSET for all but the first message
		    ID_OK!=(status=HandleMAIL(message->GetFrom())))
		{
			HandleQUIT();
			return status;
		}

		if (recipients.IsEmpty())
			continue;

		ContactList::iterator iter;
		for (iter=recipients.begin(); iter!=recipients.end(); ++iter)
		{
			if (*iter && ID_OK!=(status=HandleRCPT(*iter)))
			{
				HandleQUIT();
				return status;
			}
		}

		/*************************/
		if (TestDestroy())
			return CleanupAndAbort();
		/*************************/

		if (ID_OK!=(status=HandleDATA(message)))
		{
			HandleQUIT();
			return status;
		}

		message->RemoveTag(wxGetApp().GetAppModuleManager()->GetMessageStore()->GetOutboxTag());
		message->AddTag(wxGetApp().GetAppModuleManager()->GetMessageStore()->GetSentTag());
	}

	HandleQUIT();

	return ID_OK;
}
Esempio n. 11
0
void CRoutingZone::OnSmallTimer()
{
	if (!IsLeaf())
		return;

	CContact *pContact = NULL;
	time_t tNow = time(NULL);
	ContactList listEntries;
	// Remove dead entries
	m_pBin->GetEntries(&listEntries);
	for (ContactList::iterator itContactList = listEntries.begin(); itContactList != listEntries.end(); ++itContactList)
	{
		pContact = *itContactList;
		if ( pContact->GetType() == 4)
		{
			if (((pContact->m_tExpires > 0) && (pContact->m_tExpires <= tNow)))
			{
				if(!pContact->InUse())
				{
					//-----------------------------------------------------------------
					CString strID;
					CUInt128 uId = pContact->GetClientID();
					uId.ToHexString(&strID);

					CString strIP;
					pContact->GetIPAddress(&strIP);

					TRACE(_T("DelContact id=%s ip=%s %u %u %u\n"), 
						strID, strIP, pContact->GetTCPPort(), pContact->GetUDPPort(),
						CKademlia::GetRoutingZone()->GetNumContacts());
					//-----------------------------------------------------------------

					m_pBin->RemoveContact(pContact);
					delete pContact;
				}
				continue;
			}
		}
		if(pContact->m_tExpires == 0)
			pContact->m_tExpires = tNow;
	}
	pContact = m_pBin->GetOldest();
	if( pContact != NULL )
	{
		if ( pContact->m_tExpires >= tNow || pContact->GetType() == 4)
		{
			m_pBin->RemoveContact(pContact);
			m_pBin->m_listEntries.push_back(pContact);
			pContact = NULL;
		}
	}
	if(pContact != NULL)
	{
		pContact->CheckingType();
		if (pContact->GetVersion() >= 2/*47a*/)
		{
//--->xt	if (thePrefs.GetDebugClientKadUDPLevel() > 0)
				//DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
			CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), true);
		}
		else
		{
//--->xt	if (thePrefs.GetDebugClientKadUDPLevel() > 0)
				//DebugSend("KADEMLIA_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
			CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), false);
			if (pContact->CheckIfKad2())
			{
//--->xt		if (thePrefs.GetDebugClientKadUDPLevel() > 0)
					//DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
				CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), true);
			}
		}
	}
}
Esempio n. 12
0
void CRoutingZone::OnSmallTimer()
{
    if (!IsLeaf()) {
        return;
    }

    CContact *c = NULL;
    time_t now = time(NULL);
    ContactList entries;

    // Remove dead entries
    m_bin->GetEntries(&entries);
    for (ContactList::iterator it = entries.begin(); it != entries.end(); ++it) {
        c = *it;
        if (c->GetType() == 4) {
            if ((c->GetExpireTime() > 0) && (c->GetExpireTime() <= now)) {
                if (!c->InUse()) {
                    m_bin->RemoveContact(c);
                    delete c;
                }
                continue;
            }
        }
        if(c->GetExpireTime() == 0) {
            c->SetExpireTime(now);
        }
    }

    c = m_bin->GetOldest();
    if (c != NULL) {
        if (c->GetExpireTime() >= now || c->GetType() == 4) {
            m_bin->PushToBottom(c);
            c = NULL;
        }
    }

    if (c != NULL) {
        c->CheckingType();
        if (c->GetVersion() >= 6) {
            DebugSend(L"Kad2HelloReq", c->GetIPAddress(), c->GetUDPPort());
            CUInt128 clientID = c->GetClientID();
            CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, c->GetIPAddress(), c->GetUDPPort(), c->GetVersion(), c->GetUDPKey(), &clientID, false);
            if (c->GetVersion() >= 8) {
                // FIXME:
                // This is a bit of a work around for statistic values. Normally we only count values from incoming HELLO_REQs for
                // the firewalled statistics in order to get numbers from nodes which have us on their routing table,
                // however if we send a HELLO due to the timer, the remote node won't send a HELLO_REQ itself anymore (but
                // a HELLO_RES which we don't count), so count those statistics here. This isn't really accurate, but it should
                // do fair enough. Maybe improve it later for example by putting a flag into the contact and make the answer count
                CKademlia::GetPrefs()->StatsIncUDPFirewalledNodes(false);
                CKademlia::GetPrefs()->StatsIncTCPFirewalledNodes(false);
            }
        } else if (c->GetVersion() >= 2) {
            DebugSend(L"Kad2HelloReq", c->GetIPAddress(), c->GetUDPPort());
            CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, c->GetIPAddress(), c->GetUDPPort(), c->GetVersion(), 0, NULL, false);
            ASSERT(c->GetUDPKey() == CKadUDPKey(0));
        } else {
            ASSERT(0);
        }
    }
}
Esempio n. 13
0
void CRoutingZone::OnSmallTimer()
{
	if (!IsLeaf())
		return;

	CContact *pContact = NULL;
	time_t tNow = time(NULL);
	ContactList listEntries;
	// Remove dead entries
	m_pBin->GetEntries(&listEntries);
	for (ContactList::iterator itContactList = listEntries.begin(); itContactList != listEntries.end(); ++itContactList)
	{
		pContact = *itContactList;
		if ( pContact->GetType() == 4)
		{
			if (((pContact->m_tExpires > 0) && (pContact->m_tExpires <= tNow)))
			{
				if(!pContact->InUse())
				{
					m_pBin->RemoveContact(pContact);
					delete pContact;
				}
				continue;
			}
		}
		if(pContact->m_tExpires == 0)
			pContact->m_tExpires = tNow;
	}
	pContact = m_pBin->GetOldest();
	if( pContact != NULL )
	{
		if ( pContact->m_tExpires >= tNow || pContact->GetType() == 4)
		{
			m_pBin->PushToBottom(pContact);
			pContact = NULL;
		}
	}
	if(pContact != NULL)
	{
		pContact->CheckingType();
		if (pContact->GetVersion() >= 6){ /*48b*/
			if (thePrefs.GetDebugClientKadUDPLevel() > 0)
				DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
			CUInt128 uClientID = pContact->GetClientID();
			CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), pContact->GetVersion(), pContact->GetUDPKey(), &uClientID, false);
			if (pContact->GetVersion() >= KADEMLIA_VERSION8_49b){
				// FIXME:
				// This is a bit of a work arround for statistic values. Normally we only count values from incoming HELLO_REQs for
				// the firewalled statistics in order to get numbers from nodes which have us on their routing table,
				// however if we send a HELLO due to the timer, the remote node won't send a HELLO_REQ itself anymore (but
				// a HELLO_RES which we don't count), so count those statistics here. This isn't really accurate, but it should
				// do fair enough. Maybe improve it later for example by putting a flag into the contact and make the answer count
				CKademlia::GetPrefs()->StatsIncUDPFirewalledNodes(false);
				CKademlia::GetPrefs()->StatsIncTCPFirewalledNodes(false);
			}
		}
		else if (pContact->GetVersion() >= 2/*47a*/){
			if (thePrefs.GetDebugClientKadUDPLevel() > 0)
				DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
			CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), pContact->GetVersion(), 0, NULL, false);
			ASSERT( CKadUDPKey(0) == pContact->GetUDPKey() );
		}
		else
		{
			if (thePrefs.GetDebugClientKadUDPLevel() > 0)
				DebugSend("KADEMLIA_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
			CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), 0, 0, NULL, false);
			if (pContact->CheckIfKad2())
			{
				if (thePrefs.GetDebugClientKadUDPLevel() > 0)
					DebugSend("KADEMLIA2_HELLO_REQ", pContact->GetIPAddress(), pContact->GetUDPPort());
				CKademlia::GetUDPListener()->SendMyDetails(KADEMLIA2_HELLO_REQ, pContact->GetIPAddress(), pContact->GetUDPPort(), 1, 0, NULL, false);
			}
		}
	}
}