CKadInterface Class Reference

#include <kademlia_interface.h>

Inheritance diagram for CKadInterface:

CGossip List of all members.

Public Types

typedef std::deque< CFileTransfer * > FileTransfer

Public Member Functions

 CKadInterface (std::string sFilename)
virtual ~CKadInterface ()
int Run ()
void StartKad ()
void StopKad ()
void BootstrapKad ()
void GetAllContacts ()
void FindNodeByID (const uint8_t *nodeID)
uint32_t GetPublicIP (bool ignorelocal)
int GetSockFd ()
int GetDaemonSockFd ()
int GetClientTcpSockFd ()
int GetPeerSockFd ()
void SetPeerSockFd (int iFd)
void CleanUp ()
void SearchSrcKad (CSearchFile *toadd)
void KademliaSearchFile (uint32_t searchID, const Kademlia::CUInt128 *pcontactID, const Kademlia::CUInt128 *pbuddyID, uint8_t type, uint32_t ip, uint16_t tcp, uint16_t udp, uint32_t buddyip, uint16_t buddyport, uint8_t byCryptOptions)
CPartFile * GetFileByID (const CMD4Hash &filehash) const
std::string GetSharedDir ()
std::string GetDownloadDir ()
const int * GetSocketPair ()
void PublishFile (const std::string &sFile)
void SearchKeyKad (const std::string &sSearchStr)
void AddSource (uint32_t searchID, uint32_t ip, uint16_t port)
int CheckFileTransferStatus (int iFd)
std::string MakeAbsPath (const std::string &sPath)
void SetDownloadDir (const std::string &sPath)
CMulticastGetMulticastInstance ()
bool IsGossipEnable ()
bool IsMulticastEnable ()
void BootstrapKad (uint32_t ip, uint16_t port)

Public Attributes

FileTransfer m_filetrans
CSharedFileList * sharedfiles
CSearchList * searchlist

Private Types

typedef std::deque< CPartFile * > FileQueue

Private Member Functions

void StartNetworkThread ()
void SetLogger ()
int CreateSocket ()
int CreateDaemonSocket ()
int CreateClientTcpSocket ()
void CheckEvent (int iFd)
int CheckDaemonEvent (int iFd)
void DestroySocket ()
int ParseConfig ()
std::string GetString (const std::vector< std::string > &vConf, const std::string &sLine)
void StrTrim (std::string &) const
void OnTimer ()
void SetSharedDir (const std::string &sPath)
virtual void OnPacketReceived (uint32_t ip, uint16_t port, byte *buffer, size_t length)
virtual int OnCommandReceived (int iFd)
virtual void NotifyApp (const std::string &sFileName, uint8_t filetype, uint8_t relatedModule)
virtual void ProcessTcpGossipPacket (const std::string &sFileName, uint32 ip, uint16 port, uint8_t module)
CPartFile * GetFileByKadFileSearchID (uint32 id) const
CFileTransferCheckFileTransByID (const int iSearchID) const
CFileTransferCheckFileTransByHash (const CMD4Hash &fHash) const
int InitSocketPair ()
void RetrySource (int iSearchID)
void MakeDirs ()
void ShutdownNetworkThread ()

Static Private Member Functions

static void * ThreadCallback (void *arg)

Private Attributes

int m_iSockFd
int m_iDaemonSockFd
int m_iPeerSockFd
int m_iClientTcpSockFd
std::string m_sConfigFileName
std::string m_sClientName
bool m_bBootstrapEnable
bool m_bKadLogEnable
uint32_t m_uClientIP
uint16_t m_uClientPort
uint32_t m_uBootIP
uint16_t m_uBootPort
pthread_t m_Thread
uint16_t m_uDaemonTcpPort
uint16_t m_uClientTcpPort
CKnownFileList * knownfiles
FileQueue m_filelist
std::string m_sSharedDir
std::string m_sDownloadDir
int m_iSockPairFd [2]
std::map< int, std::vector<
AddrPortPair > > 
m_SourceMap
bool m_bMulticastEnable
bool m_bGossipEnable
std::string m_sMulticastInterface
uint32_t m_uMulticastIP
uint16_t m_uMulticastPort
CMulticastm_pMulticast
bool m_bInit

Detailed Description

Placement of Communication component in TCP/IP stack
c2_system_arch.jpg

C2 System Architecture


Constructor & Destructor Documentation

CKadInterface::CKadInterface ( std::string  sFilename  ) 

Constructor of the class. Takes configuration file name of the communication component as its argument. An example of such configuration file is:

#Name is not important; should be removed later
client_name = client_2

#IP address of the node
client_ip = 130.55.115.201

#Kademlia UDP port
client_port =  4672

#Kademlia TCP port
client_tcp_port = 5672

#Kademlia logging should enabled?
kad_log_enable = yes

#Port on which Communication component listens for Policy component.
daemon_tcp_port = 7772

#Should enable bootstrap?
#This are only for testing since bootstrapping is done
#by policy component now.
bootstrap_enable = yes
bootstrap_ip = 130.55.115.201
bootstrap_port =  4671


#Name of the directory where communication component stores the certificates
#collected from the p2p network and republishes.
shared_dir = shared_dir

#Name of the directory where communication component stores all gossip
#messages.
download_dir = download_dir

#Is multicast module enabled?
multicast_enable = yes

#Multicast interface name
multicast_interface = eth0

#Multicast IP address
multicast_ip = 239.192.0.1

#Multicast Port number
multicast_port = 7500

#Is Kademlia module enabled?
gossip_enable = yes

CKadInterface::~CKadInterface (  )  [virtual]

Destructor of the class.


Member Function Documentation

void CKadInterface::AddSource ( uint32_t  searchID,
uint32_t  ip,
uint16_t  port 
)

Stores the source ip and port for a specific kad search ID.

void CKadInterface::BootstrapKad ( uint32_t  ip,
uint16_t  port 
)

Asks kademlia to bootstrap the specified ip and port.

void CKadInterface::BootstrapKad (  ) 

Asks kademlia to bootstrap on some specific ip and port in kad network.

int CKadInterface::CheckFileTransferStatus ( int  iFd  ) 

After file transfer notifies the network thread, this function checks the file transfer status result and invokes corresponding action.

void CKadInterface::CleanUp (  ) 

Cleans up any allocated resource such as sockets, threads, etc.

int CKadInterface::CreateClientTcpSocket (  )  [private]

Creates a TCP socket for kademlia.

int CKadInterface::CreateDaemonSocket (  )  [private]

Creates a TCP socket for communicating with policy component.

int CKadInterface::CreateSocket (  )  [private]

Creates a UDP socket for kademlia.

void CKadInterface::GetAllContacts (  ) 

Retrieves contact list of neighbor from kademlia protocol. This contact list is useful for gossiping.

std::string CKadInterface::GetDownloadDir (  )  [inline]

Retrieves the download directory. Any gossip file is stored in this directory.

CMulticast* CKadInterface::GetMulticastInstance (  )  [inline]

Returns the multicasting instance.

std::string CKadInterface::GetSharedDir (  )  [inline]

Retrieves the name of the shared directory. Kademlia publishes files who are located in this shared directory. After searching a file in the kad network and downloading it, the file is also stored in this shared directory for further publishing.

bool CKadInterface::IsGossipEnable (  )  [inline]

Checks whether the gossip module is enabled or not. In the configurationfile, it is possible to enable or disable gossip module and multicast module.

bool CKadInterface::IsMulticastEnable (  )  [inline]

Checks whether the multicast module is enabled or not. In the configurationfile, it is possible to enable or disable gossip module and multicast module.

void CKadInterface::KademliaSearchFile ( uint32_t  searchID,
const Kademlia::CUInt128 *  pcontactID,
const Kademlia::CUInt128 *  pbuddyID,
uint8_t  type,
uint32_t  ip,
uint16_t  tcp,
uint16_t  udp,
uint32_t  buddyip,
uint16_t  buddyport,
uint8_t  byCryptOptions 
)

This function is called after a source of a file is found.

void CKadInterface::MakeDirs (  )  [private]

Creates Shared Dir, Download Dir and .tmp Dir.

void CKadInterface::NotifyApp ( const std::string &  sFileName,
uint8_t  filetype,
uint8_t  relatedModule 
) [private, virtual]

It sends EventMessage to the Policy component. sFileName, filetype and relatedModule are encoded in the EventMessage.

Reimplemented in CGossip.

virtual int CKadInterface::OnCommandReceived ( int  iFd  )  [inline, private, virtual]

Invoked after a command from policy component is received. Override by the CGossip class. Communication is done using EventMessage class.

Reimplemented in CGossip.

virtual void CKadInterface::OnPacketReceived ( uint32_t  ip,
uint16_t  port,
byte *  buffer,
size_t  length 
) [private, virtual]

Invoked after a Kademlia packet is arrived.

void CKadInterface::OnTimer (  )  [private]

Executes on timeout in the network thread. The interval is 1 sec. Calls Kademlia::Process()

int CKadInterface::ParseConfig (  )  [private]

Parse the configuration file. Returns -1 on error in the configuration file.

void CKadInterface::ProcessTcpGossipPacket ( const std::string &  sFileName,
uint32  ip,
uint16  port,
uint8_t  module 
) [private, virtual]

After receiving a Gossip Message on TCP, this method is invoked.

Reimplemented in CGossip.

void CKadInterface::PublishFile ( const std::string &  sFile  ) 

Asks kademlia to publish the sFile in the KAD network.

void CKadInterface::RetrySource ( int  iSearchID  )  [private]

If a file tranfer is failed for downloading a file from the KAD network, retry is done by invoking this function.

int CKadInterface::Run (  ) 

Main function to run the communication component. Returns -1 on failure in running the component. It runs Kademlia, multicast and network modules.

void CKadInterface::SearchKeyKad ( const std::string &  sSearchStr  ) 

Asks kademlia to search any keyword in the kad network.

The filename extension. May be empty.

The smallest filesize in bytes to accept, zero for any.

The largest filesize in bytes to accept, zero for any.

void CKadInterface::SearchSrcKad ( CSearchFile *  toadd  ) 

Search source of a file in the KAD network.

void CKadInterface::SetDownloadDir ( const std::string &  sPath  ) 

Sets the path of the download directory as specified in the configuration file.

void CKadInterface::StartKad (  ) 

Asks kademlia to startup.

void CKadInterface::StartNetworkThread (  )  [private]

Starts the networking thread. It listens for any : Kademlia message, Gossip file transfer message, socket pair for communicating with the main thread, policy component message

void CKadInterface::StopKad (  ) 

Asks kademlia to stop.


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 11:51:45 2010 for Communication Component by  doxygen 1.4.7