#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <list>
#include <unistd.h>
#include <ctype.h>
#include <map>
#include <openssl/sha.h>
#include <stdlib.h>
#include <string.h>
#include <set>
#include <queue>
#define HEADER_SIZE 27
#define SHA_DIGEST_LENGTH 20
using namespace std ;
//keeps the join responses
extern set<struct joinResNode> joinResponse ;
//keeps the status messgae
extern set< set<struct node> > statusResponse ;
extern map<struct node, list<string> > statusResponseTypeFiles ;
struct node{
unsigned short int portNo;
unsigned char hostname[256];
bool operator<(const struct node& node1) const{
return node1.portNo < portNo ;
}
bool operator==(const struct node& node1) const{
return ((node1.portNo == portNo) && !strcmp((char *)node1.hostname, (char *)hostname)) ;
}
};
struct joinResNode{
unsigned short int portNo;
unsigned char hostname[256];
uint32_t location ;
bool operator<(const struct joinResNode& node1) const{
return node1.location > location ;
}
bool operator==(const struct joinResNode& node1) const{
return ((node1.portNo == portNo) && !strcmp((char *)node1.hostname, (char *)hostname) && (node1.location == location)) ;
}
};
extern map<struct node, int> nodeConnectionMap ; // To store all the neighboring nodes
extern pthread_mutex_t nodeConnectionMapLock ;
struct metaData
{
unsigned int fileNumber;
unsigned char fileID[20];
unsigned char fileName[256];
unsigned long int fileSize;
unsigned char sha1[20];
unsigned char nonce[20];
list<string > *keywords;
//map<string, int> keywords;
unsigned char bitVector[128];
};
//message structure that goes into the messgae queues
struct Message{
uint8_t type;
unsigned char *buffer ;
unsigned char *query ;
unsigned char *metadata;
unsigned char *fileName ;
uint8_t ttl ;
uint32_t location ;
int status ; // 0 - originated from here
unsigned char uoid[SHA_DIGEST_LENGTH] ;
bool fromConnect ; // 1 - The message was created by the node which
// initiated the connection
int buffer_len ;
uint8_t status_type ;
unsigned char query_type ;
uint8_t errorCode;
} ;
//information for the neighbors stored in this structures
struct connectionNode{
list<struct Message> MessageQ ;
pthread_mutex_t mesQLock ;
pthread_cond_t mesQCv ;
int shutDown ;
unsigned int keepAliveTimer;
int keepAliveTimeOut;
int myReadId;
int myWriteId;
int isReady;
bool joinFlag;
struct node n;
};
struct parsedDeleteMessage
{
unsigned char fileName[256];
unsigned char sha1[20];
unsigned char nonce[20];
unsigned char password[20];
};
extern unsigned char tempLogFile[512], tempInitFile[512];
extern bool shutDown ;
extern int accept_pid;
extern int nSocket_accept;
extern int keepAlive_pid;
extern int toBeClosed;
extern int joinTimeOutFlag;
extern int inJoinNetwork;
extern int statusTimerFlag ;
extern int checkTimerFlag ;
extern int searchTimerFlag ;
extern int node_pid;
extern int softRestartFlag ;
//extern int globalFileNumber ;
extern int globalSearchCount ;
extern int currentCacheSize;
extern unsigned char extFile[256];
extern unsigned char filesDir[256];
extern FILE *f_log;
extern map<int, struct connectionNode> connectionMap ; // Stores all the info related to a connection
extern list<pthread_t > childThreadList ;
extern map<pthread_t , bool > myConnectThread ;
extern map<string, list<int> > bitVectorIndexMap;
extern map<string, list<int> > fileNameIndexMap;
extern map<string, list<int> > sha1IndexMap;
extern map<string, int> fileIDMap;
extern map<int, struct metaData> getFileIDMap;
extern list<int > cacheLRU;
//extern list<struct metaData> metadataList;
extern pthread_mutex_t connectionMapLock ;
extern pthread_mutex_t statusMsgLock ;
extern pthread_mutex_t searchMsgLock ;
extern pthread_mutex_t getMsgLock ;
extern pthread_mutex_t logEntryLock ;
extern pthread_cond_t statusMsgCV;
extern pthread_cond_t searchMsgCV;
extern pthread_cond_t getMsgCV;
extern list<string> tmpFileNameList ;
//pakcet structre stored in the cache at the nodes
struct Packet{
struct node receivedFrom ;
int status; // 0 - originally Sent from here,
// 1 - Forwarded from here, route back, else -1
int sockfd ;
int msgLifeTime;
int status_type ;
};
extern map<string, struct Packet> MessageDB ; // Keeps a track of all the messages it sends/forwards
extern pthread_mutex_t MessageDBLock ;
// Thread function declarations
void *keyboard_thread(void *) ;
void *timer_thread(void *) ;
void *accept_connectionsT(void *); // Waits for other nodes to connect
void *read_thread(void *) ;
void *write_thread(void *) ;
void *connectBeacon(void *);
// Function declarations
int isBeaconNode(struct node n);
int connectTo(unsigned char *, unsigned int) ;
extern pthread_t k_thread;
void notifyMessageSend(int resSock, uint8_t errorCode);
void pushMessageinQ(int, struct Message ) ;
void closeConnection(int) ;
void joinNetwork() ;
void getStatus() ;
void writeToStatusFile() ;
void getStatusTypeFiles() ;
void writeToStatusFile_TypeFiles() ;
unsigned char *createLogEntry(unsigned char mode, int origin, unsigned char header[HEADER_SIZE], unsigned char *buffer);
void writeLogEntry(unsigned char *logEntry);
void eraseValueInMap(int val);
extern unsigned char *GetUOID(char *, unsigned char *, long unsigned int) ;
void initiateCheck() ;
void init() ;
void cleanup() ;
void writeMetaData(struct metaData metadata, int globalFileNumber);
int updateGlobalFileNumber();
void writeData(struct metaData, int globalFileNumber);
void populateBitVectorIndexMap(unsigned char*, unsigned int);
void populateSha1IndexMap(unsigned char*, unsigned int);
void populateFileNameIndexMap(unsigned char*, unsigned int);
unsigned char* toHex(unsigned char *str, int len);
struct metaData populateMetaData(int fileNumber);
void initiateSearch(unsigned char, unsigned char *) ;
string MetaDataToStr(struct metaData) ;
struct metaData populateMetaDataFromString(unsigned char *input);
struct metaData populateMetaDataFromCPPString(string);
int searchResponseDisplay(list<struct metaData> metadataList, int count);
void writeLRUToFile();
void readLRUFromFile();
void updateLRU(int fileNumber);
void removeFromLRU();
int storeInLRU(struct metaData metadata, unsigned int fileNumber);
list<int> getAllFiles() ;
struct parsedDeleteMessage parseDeleteMessage(unsigned char *message);
void deleteFile(struct parsedDeleteMessage pd);
int getFileNumberFromIndex(unsigned char *fileName, unsigned char *nonce);
void deleteFromIndex(int);
void deleteAllFiles();
void initiateDelete(unsigned char *) ;
void initiateStore(string, string) ;
void writeFileToCache(unsigned char *metadata_str, unsigned char *fileName);
void writeFileToPermanent(unsigned char *metadata_str, unsigned char *fileName);
void initiateGet(struct metaData) ;
struct metaData populateMetaDataFromString_noFileID(unsigned char *input1);
int doesFileExist(struct metaData );
void writeToFileFromData(unsigned char fileName[], int fileNumber);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
p2p-C++.zip (21个子文件)
p2p-master
main.cc 23KB
indexSearch.cc 21KB
logEntry.cc 8KB
startnode.ini 508B
keepAliveTimer.h 104B
outgoing_connections.cc 35KB
connectBeacon.cc 4KB
timer.cc 4KB
iniParser.cc 11KB
metaData.cc 23KB
Makefile 2KB
keyboard.cc 22KB
signalHandler.h 110B
indexSearch.h 784B
main.h 7KB
signalHandler.cc 2KB
keepAliveTimer.cc 1KB
README 9KB
iniParser.h 2KB
incoming_connections.cc 46KB
statusResponseTimeout 16KB
共 21 条
- 1
资源评论
- 秋刀鱼之味2016-12-05不是很有价值。
huangyueranbbc
- 粉丝: 587
- 资源: 214
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- htmlzwbjq_downyi.com.zip
- 无头单向非循环链表的实现(Test.c)
- 无头单向非循环链表的实现(SList.c)
- 浏览器重定向插件更新文件
- SSA-BP麻雀算法优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
- 粒子群算法优化BP神经网络PSO-BP的MATLAB代码(数值预测)
- 基于Springboot的一起看书平台.zip
- 无头单向非循环链表的实现(SList.h)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功