mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	adress book added
This commit is contained in:
		
							parent
							
								
									06088ff7a2
								
							
						
					
					
						commit
						94a23be9d9
					
				
					 4 changed files with 88 additions and 0 deletions
				
			
		
							
								
								
									
										73
									
								
								AddressBook.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								AddressBook.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
#ifndef ADDRESS_BOOK_H__
 | 
			
		||||
#define ADDRESS_BOOK_H__
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include "base64.h"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
#include "Identity.h"
 | 
			
		||||
#include "Log.h"
 | 
			
		||||
 | 
			
		||||
namespace i2p
 | 
			
		||||
{
 | 
			
		||||
namespace data
 | 
			
		||||
{
 | 
			
		||||
	class AddressBook
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			AddressBook (): m_IsLoaded (false) {};
 | 
			
		||||
	
 | 
			
		||||
			const IdentHash * FindAddress (const std::string& address)
 | 
			
		||||
			{
 | 
			
		||||
				if (!m_IsLoaded)
 | 
			
		||||
					LoadHosts ();
 | 
			
		||||
				auto it = m_Addresses.find (address);
 | 
			
		||||
				if (it != m_Addresses.end ())
 | 
			
		||||
					return &it->second;
 | 
			
		||||
				else
 | 
			
		||||
					return nullptr;	
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
		private:
 | 
			
		||||
	
 | 
			
		||||
			void LoadHosts ()
 | 
			
		||||
			{
 | 
			
		||||
				m_IsLoaded = true;
 | 
			
		||||
				std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode
 | 
			
		||||
				if (!f.is_open ())	
 | 
			
		||||
				{
 | 
			
		||||
					LogPrint ("hosts.txt not found");
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				int numAddresses = 0;
 | 
			
		||||
				char str[1024];
 | 
			
		||||
				while (!f.eof ())
 | 
			
		||||
				{
 | 
			
		||||
					f.getline (str, 1024);
 | 
			
		||||
					char * key = strchr (str, '=');
 | 
			
		||||
					if (key)
 | 
			
		||||
					{
 | 
			
		||||
						*key = 0;
 | 
			
		||||
						key++;
 | 
			
		||||
						Identity ident;
 | 
			
		||||
						Base64ToByteStream (key, strlen(key), (uint8_t *)&ident, sizeof (ident));
 | 
			
		||||
						m_Addresses[str] = CalculateIdentHash (ident);	
 | 
			
		||||
						numAddresses++;
 | 
			
		||||
					}		
 | 
			
		||||
				}
 | 
			
		||||
				LogPrint (numAddresses, " addresses loaded");
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
 | 
			
		||||
			std::map<std::string, IdentHash>  m_Addresses;
 | 
			
		||||
			bool m_IsLoaded;
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								NetDb.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								NetDb.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -12,6 +12,7 @@
 | 
			
		|||
#include "RouterInfo.h"
 | 
			
		||||
#include "LeaseSet.h"
 | 
			
		||||
#include "Tunnel.h"
 | 
			
		||||
#include "AddressBook.h"
 | 
			
		||||
 | 
			
		||||
namespace i2p
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -104,6 +105,7 @@ namespace data
 | 
			
		|||
			int m_ReseedRetries;
 | 
			
		||||
			std::thread * m_Thread;	
 | 
			
		||||
			i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg
 | 
			
		||||
			AddressBook m_AddressBook;
 | 
			
		||||
 | 
			
		||||
			static const char m_NetDbPath[];
 | 
			
		||||
	};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								util.cpp
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								util.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -121,6 +121,18 @@ namespace filesystem
 | 
			
		|||
		return path;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::string GetFullPath (const std::string& filename)
 | 
			
		||||
	{
 | 
			
		||||
		std::string fullPath = GetDataDir ().string ();
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
		fullPath.append ("/");
 | 
			
		||||
#else
 | 
			
		||||
		fullPath.append ("\\");
 | 
			
		||||
#endif
 | 
			
		||||
		fullPath.append (filename);
 | 
			
		||||
		return fullPath;
 | 
			
		||||
	}		
 | 
			
		||||
 | 
			
		||||
	boost::filesystem::path GetConfigFile()
 | 
			
		||||
	{
 | 
			
		||||
		boost::filesystem::path pathConfigFile(i2p::util::config::GetArg("-conf", "i2p.conf"));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								util.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								util.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -25,6 +25,7 @@ namespace util
 | 
			
		|||
	namespace filesystem
 | 
			
		||||
	{
 | 
			
		||||
		const boost::filesystem::path &GetDataDir();
 | 
			
		||||
		std::string GetFullPath (const std::string& filename);	
 | 
			
		||||
		boost::filesystem::path GetDefaultDataDir();
 | 
			
		||||
		boost::filesystem::path GetConfigFile();
 | 
			
		||||
		void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue