mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
Final changes to add the new serialiser.
- added Chat / Msg and Disc services. - expanded rsiface to handle new serialiser. - mods to rsserver with new conversions etc. - added service directory to Makefile. - removed PROXY / CHANNELS from make.opt git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@276 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d9efb76b01
commit
46a001af47
@ -3,37 +3,40 @@
|
|||||||
|
|
||||||
all:
|
all:
|
||||||
make -C tcponudp
|
make -C tcponudp
|
||||||
make -C pqi
|
|
||||||
make -C util
|
make -C util
|
||||||
|
make -C serialiser
|
||||||
|
make -C pqi
|
||||||
make -C dbase
|
make -C dbase
|
||||||
|
make -C services
|
||||||
make -C server
|
make -C server
|
||||||
make -C dht
|
make -C dht
|
||||||
make -C upnp
|
make -C upnp
|
||||||
make -C rsserver
|
make -C rsserver
|
||||||
make -C rsiface
|
make -C rsiface
|
||||||
# make -C fltkgui
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
make -C tcponudp clean
|
make -C tcponudp clean
|
||||||
make -C pqi clean
|
|
||||||
make -C util clean
|
make -C util clean
|
||||||
|
make -C serialiser clean
|
||||||
|
make -C pqi clean
|
||||||
make -C dbase clean
|
make -C dbase clean
|
||||||
|
make -C services clean
|
||||||
make -C server clean
|
make -C server clean
|
||||||
make -C dht clean
|
make -C dht clean
|
||||||
make -C upnp clean
|
make -C upnp clean
|
||||||
make -C rsserver clean
|
make -C rsserver clean
|
||||||
make -C rsiface clean
|
make -C rsiface clean
|
||||||
# make -C fltkgui clean
|
|
||||||
|
|
||||||
clobber:
|
clobber:
|
||||||
make -C tcponudp clobber
|
make -C tcponudp clobber
|
||||||
make -C pqi clobber
|
|
||||||
make -C util clobber
|
make -C util clobber
|
||||||
|
make -C serialiser clobber
|
||||||
|
make -C pqi clobber
|
||||||
make -C dbase clobber
|
make -C dbase clobber
|
||||||
|
make -C services clobber
|
||||||
make -C server clobber
|
make -C server clobber
|
||||||
make -C dht clobber
|
make -C dht clobber
|
||||||
make -C upnp clobber
|
make -C upnp clobber
|
||||||
make -C rsserver clobber
|
make -C rsserver clobber
|
||||||
make -C rsiface clobber
|
make -C rsiface clobber
|
||||||
# make -C fltkgui clobber
|
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ CC = g++
|
|||||||
|
|
||||||
# flags for components....
|
# flags for components....
|
||||||
PQI_USE_XPGP = 1
|
PQI_USE_XPGP = 1
|
||||||
PQI_USE_PROXY = 1
|
#PQI_USE_PROXY = 1
|
||||||
#PQI_USE_CHANNELS = 1
|
#PQI_USE_CHANNELS = 1
|
||||||
USE_FILELOOK = 1
|
USE_FILELOOK = 1
|
||||||
|
|
||||||
|
@ -261,8 +261,8 @@ virtual int FileSetBandwidthTotals(float outkB, float inkB) = 0;
|
|||||||
/****************************************/
|
/****************************************/
|
||||||
/* Message Items */
|
/* Message Items */
|
||||||
virtual int MessageSend(MessageInfo &info) = 0;
|
virtual int MessageSend(MessageInfo &info) = 0;
|
||||||
virtual int MessageDelete(std::string id) = 0;
|
virtual int MessageDelete(std::string mid) = 0;
|
||||||
virtual int MessageRead(std::string id) = 0;
|
virtual int MessageRead(std::string mid) = 0;
|
||||||
|
|
||||||
/* Channel Items */
|
/* Channel Items */
|
||||||
virtual int ChannelCreateNew(ChannelInfo &info) = 0;
|
virtual int ChannelCreateNew(ChannelInfo &info) = 0;
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define RSCERTIDLEN 16
|
#define RSCERTIDLEN 16
|
||||||
|
|
||||||
class RsCertId
|
class RsCertId
|
||||||
@ -47,13 +49,11 @@ class RsCertId
|
|||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const RsCertId &id);
|
std::ostream &operator<<(std::ostream &out, const RsCertId &id);
|
||||||
|
|
||||||
/* use RsCertId, (not unsigned long) because the definition will change
|
#endif
|
||||||
typedef unsigned long RsCertId;
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef RsCertId RsChanId;
|
|
||||||
typedef RsCertId RsMsgId;
|
|
||||||
|
|
||||||
|
typedef std::string RsCertId;
|
||||||
|
typedef std::string RsChanId;
|
||||||
|
typedef std::string RsMsgId;
|
||||||
typedef std::string RsAuthId;
|
typedef std::string RsAuthId;
|
||||||
|
|
||||||
|
|
||||||
@ -192,6 +192,7 @@ class FileTransferInfo: public FileInfo
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string source;
|
std::string source;
|
||||||
|
std::list<std::string> peerIds;
|
||||||
int transfered;
|
int transfered;
|
||||||
double tfRate; /* kbytes */
|
double tfRate; /* kbytes */
|
||||||
bool download;
|
bool download;
|
||||||
@ -223,9 +224,16 @@ class MessageInfo: public BaseInfo
|
|||||||
|
|
||||||
unsigned int msgflags;
|
unsigned int msgflags;
|
||||||
std::string srcname;
|
std::string srcname;
|
||||||
|
|
||||||
|
std::list<PersonInfo> msgto;
|
||||||
|
std::list<PersonInfo> msgcc;
|
||||||
|
std::list<PersonInfo> msgbcc;
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string header;
|
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
|
std::string attach_title;
|
||||||
|
std::string attach_comment;
|
||||||
std::list<FileInfo> files;
|
std::list<FileInfo> files;
|
||||||
int size; /* total of files */
|
int size; /* total of files */
|
||||||
int count; /* file count */
|
int count; /* file count */
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#include "rsserver/p3face.h"
|
#include "rsserver/p3face.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
|
#include "serialiser/rsconfigitems.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -82,31 +84,48 @@ int RsServer::UpdateAllTransfers()
|
|||||||
std::list<FileTransferInfo> &transfers = iface.mTransferList;
|
std::list<FileTransferInfo> &transfers = iface.mTransferList;
|
||||||
transfers.clear();
|
transfers.clear();
|
||||||
|
|
||||||
std::list<FileTransferItem *> nTransList = server -> getTransfers();
|
std::list<RsFileTransfer *> nTransList = server -> getTransfers();
|
||||||
std::list<FileTransferItem *>::iterator it;
|
std::list<RsFileTransfer *>::iterator it;
|
||||||
|
|
||||||
for(it = nTransList.begin(); it != nTransList.end(); it++)
|
for(it = nTransList.begin(); it != nTransList.end(); it++)
|
||||||
{
|
{
|
||||||
FileTransferInfo ti;
|
FileTransferInfo ti;
|
||||||
if ((*it) -> p)
|
|
||||||
|
/* set it up */
|
||||||
|
certsign sign;
|
||||||
|
cert *c = NULL;
|
||||||
|
if (!convert_to_certsign((*it)->PeerId(), sign))
|
||||||
{
|
{
|
||||||
ti.source = (*it) -> p -> Name();
|
std::cerr << "CERTSIGN error!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* look it up */
|
||||||
|
c = getSSLRoot() -> findcertsign(sign);
|
||||||
|
if (c == NULL)
|
||||||
|
{
|
||||||
|
std::cerr << "CERTSIGN error! 2" << std::endl;
|
||||||
|
ti.source = "Unknown";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ti.source = "Unknown";
|
ti.source = c -> Name();
|
||||||
}
|
}
|
||||||
|
|
||||||
ti.id = intGetCertId((cert *) (*it) -> p);
|
ti.id = (*it)->PeerId();
|
||||||
ti.fname = (*it) -> name;
|
ti.peerIds = (*it) -> allPeerIds.ids;
|
||||||
ti.hash = (*it) -> hash;
|
|
||||||
ti.path = (*it) -> path;
|
ti.fname = (*it) -> file.name;
|
||||||
ti.size = (*it) -> size;
|
ti.hash = (*it) -> file.hash;
|
||||||
|
ti.path = (*it) -> file.path;
|
||||||
|
ti.size = (*it) -> file.filesize;
|
||||||
|
|
||||||
ti.transfered = (*it) -> transferred;
|
ti.transfered = (*it) -> transferred;
|
||||||
/* other ones!!! */
|
/* other ones!!! */
|
||||||
ti.tfRate = (*it) -> crate;
|
ti.tfRate = (*it) -> crate / 1000;
|
||||||
|
ti.download = (*it) -> in;
|
||||||
ti.downloadStatus = (*it) -> state;
|
ti.downloadStatus = (*it) -> state;
|
||||||
transfers.push_back(ti);
|
transfers.push_back(ti);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iface.setChanged(RsIface::Transfer);
|
iface.setChanged(RsIface::Transfer);
|
||||||
|
@ -37,6 +37,7 @@ const int p3facemsgzone = 11453;
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
unsigned long getMsgId(RsMsgId &id)
|
unsigned long getMsgId(RsMsgId &id)
|
||||||
{
|
{
|
||||||
@ -49,7 +50,7 @@ unsigned long getMsgId(RsMsgId &id)
|
|||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getRsMsgId(RsMsgId &rsmid, unsigned int mid)
|
void setMsgId(RsMsgId &rsmid, unsigned int mid)
|
||||||
{
|
{
|
||||||
/* version that uses the uniqueMsgId stored in sid */
|
/* version that uses the uniqueMsgId stored in sid */
|
||||||
/* 16 Bytes XXX Must be equal! */
|
/* 16 Bytes XXX Must be equal! */
|
||||||
@ -64,6 +65,8 @@ void getRsMsgId(RsMsgId &rsmid, unsigned int mid)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/****************************************/
|
/****************************************/
|
||||||
@ -73,31 +76,52 @@ int RsServer::MessageSend(MessageInfo &info)
|
|||||||
/* so we send this.... */
|
/* so we send this.... */
|
||||||
lockRsCore(); /* LOCK */
|
lockRsCore(); /* LOCK */
|
||||||
|
|
||||||
MsgItem *msg = new MsgItem();
|
RsMsgItem *msg = new RsMsgItem();
|
||||||
|
|
||||||
/* id who it is to */
|
/* id who it is to ???? handled lower */
|
||||||
msg -> p = intFindCert(info.id);
|
msg -> PeerId("");
|
||||||
msg -> cid = msg -> p -> cid;
|
|
||||||
|
|
||||||
msg -> title = info.title;
|
msg -> msgFlags = 0;
|
||||||
msg -> header = info.header;
|
msg -> msgId = 0;
|
||||||
msg -> msg = info.msg;
|
|
||||||
msg -> sendTime = time(NULL);
|
msg -> sendTime = time(NULL);
|
||||||
|
msg -> recvTime = 0;
|
||||||
|
|
||||||
|
msg -> subject = info.title;
|
||||||
|
msg -> message = info.msg;
|
||||||
|
|
||||||
|
std::list<PersonInfo>::iterator pit;
|
||||||
|
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
|
||||||
|
{
|
||||||
|
msg -> msgto.ids.push_back(pit->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
|
||||||
|
{
|
||||||
|
msg -> msgcc.ids.push_back(pit->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
||||||
|
{
|
||||||
|
msg -> msgbcc.ids.push_back(pit->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg -> attachment.title = info.attach_title;
|
||||||
|
msg -> attachment.comment = info.attach_comment;
|
||||||
|
|
||||||
std::list<FileInfo>::iterator it;
|
std::list<FileInfo>::iterator it;
|
||||||
for(it = info.files.begin(); it != info.files.end(); it++)
|
for(it = info.files.begin(); it != info.files.end(); it++)
|
||||||
{
|
{
|
||||||
MsgFileItem mfi;
|
RsTlvFileItem mfi;
|
||||||
mfi.hash = it -> hash;
|
mfi.hash = it -> hash;
|
||||||
mfi.name = it -> fname;
|
mfi.name = it -> fname;
|
||||||
mfi.size = it -> size;
|
mfi.filesize = it -> size;
|
||||||
msg -> files.push_back(mfi);
|
msg -> attachment.items.push_back(mfi);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "RsServer::MessageSend()" << std::endl;
|
std::cerr << "RsServer::MessageSend()" << std::endl;
|
||||||
msg->print(std::cerr);
|
msg->print(std::cerr);
|
||||||
|
|
||||||
server -> sendMessage(msg);
|
msgSrv -> sendMessage(msg);
|
||||||
|
|
||||||
unlockRsCore(); /* UNLOCK */
|
unlockRsCore(); /* UNLOCK */
|
||||||
|
|
||||||
@ -107,20 +131,14 @@ int RsServer::MessageSend(MessageInfo &info)
|
|||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/****************************************/
|
/****************************************/
|
||||||
int RsServer::MessageDelete(std::string id)
|
int RsServer::MessageDelete(std::string mid)
|
||||||
{
|
{
|
||||||
lockRsCore(); /* LOCK */
|
lockRsCore(); /* LOCK */
|
||||||
|
|
||||||
RsMsgId uid(id);
|
std::cerr << "RsServer::MessageDelete() ";
|
||||||
|
|
||||||
unsigned long mid = getMsgId(uid);
|
|
||||||
|
|
||||||
std::cerr << "RsServer::MessageDelete()" << std::endl;
|
|
||||||
std::cerr << "str: " << id << std::endl;
|
|
||||||
std::cerr << "uid: " << uid << std::endl;
|
|
||||||
std::cerr << "mid: " << mid << std::endl;
|
std::cerr << "mid: " << mid << std::endl;
|
||||||
|
|
||||||
server -> removeMsgId(mid);
|
msgSrv -> removeMsgId(atoi(mid.c_str()));
|
||||||
|
|
||||||
unlockRsCore(); /* UNLOCK */
|
unlockRsCore(); /* UNLOCK */
|
||||||
|
|
||||||
@ -128,20 +146,14 @@ int RsServer::MessageDelete(std::string id)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsServer::MessageRead(std::string id)
|
int RsServer::MessageRead(std::string mid)
|
||||||
{
|
{
|
||||||
lockRsCore(); /* LOCK */
|
lockRsCore(); /* LOCK */
|
||||||
|
|
||||||
RsMsgId uid(id);
|
std::cerr << "RsServer::MessageRead() ";
|
||||||
|
|
||||||
unsigned long mid = getMsgId(uid);
|
|
||||||
|
|
||||||
std::cerr << "RsServer::MessageRead()" << std::endl;
|
|
||||||
std::cerr << "str: " << id << std::endl;
|
|
||||||
std::cerr << "uid: " << uid << std::endl;
|
|
||||||
std::cerr << "mid: " << mid << std::endl;
|
std::cerr << "mid: " << mid << std::endl;
|
||||||
|
|
||||||
server -> markMsgIdRead(mid);
|
msgSrv -> markMsgIdRead(atoi(mid.c_str()));
|
||||||
|
|
||||||
unlockRsCore(); /* UNLOCK */
|
unlockRsCore(); /* UNLOCK */
|
||||||
|
|
||||||
@ -173,22 +185,12 @@ int RsServer::ChatSend(ChatInfo &ci)
|
|||||||
/* send a message to all for now */
|
/* send a message to all for now */
|
||||||
if (ci.chatflags & RS_CHAT_PRIVATE)
|
if (ci.chatflags & RS_CHAT_PRIVATE)
|
||||||
{
|
{
|
||||||
|
chatSrv -> sendPrivateChat(ci.msg, ci.rsid);
|
||||||
/* to only one person */
|
|
||||||
RsCertId id(ci.rsid);
|
|
||||||
cert *c = intFindCert(id);
|
|
||||||
ChatItem *item = new ChatItem();
|
|
||||||
item -> sid = getPQIsearchId();
|
|
||||||
item -> p = c;
|
|
||||||
item -> cid = c -> cid;
|
|
||||||
item -> msg = ci.msg;
|
|
||||||
item -> flags = PQI_ITEM_FLAG_PRIVATE;
|
|
||||||
server -> sendPrivateChat(item);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* global */
|
/* global */
|
||||||
server -> sendChat(ci.msg);
|
chatSrv -> sendChat(ci.msg);
|
||||||
}
|
}
|
||||||
unlockRsCore(); /* UNLOCK */
|
unlockRsCore(); /* UNLOCK */
|
||||||
|
|
||||||
@ -206,13 +208,9 @@ int RsServer::UpdateAllChat()
|
|||||||
|
|
||||||
/* get any messages and push them to iface */
|
/* get any messages and push them to iface */
|
||||||
|
|
||||||
#if 1
|
|
||||||
// at the end here, we handle chats.
|
|
||||||
if (server -> chatChanged.Changed(0))
|
|
||||||
{
|
|
||||||
// get the items from the list.
|
// get the items from the list.
|
||||||
std::list<ChatItem *> clist = server -> getChatQueue();
|
std::list<RsChatItem *> clist = chatSrv -> getChatQueue();
|
||||||
std::list<ChatItem *>::iterator it;
|
std::list<RsChatItem *>::iterator it;
|
||||||
for(it = clist.begin(); it != clist.end(); it++)
|
for(it = clist.begin(); it != clist.end(); it++)
|
||||||
{
|
{
|
||||||
ChatInfo ci;
|
ChatInfo ci;
|
||||||
@ -220,8 +218,7 @@ int RsServer::UpdateAllChat()
|
|||||||
iface.mChatList.push_back(ci);
|
iface.mChatList.push_back(ci);
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
iface.setChanged(RsIface::Chat);
|
iface.setChanged(RsIface::Chat);
|
||||||
|
|
||||||
/* unlock Mutexes */
|
/* unlock Mutexes */
|
||||||
@ -245,9 +242,9 @@ int RsServer::UpdateAllMsgs()
|
|||||||
iface.lockData(); /* LOCK */
|
iface.lockData(); /* LOCK */
|
||||||
|
|
||||||
/* do stuff */
|
/* do stuff */
|
||||||
std::list<MsgItem *> &msglist = server -> getMsgList();
|
std::list<RsMsgItem *> &msglist = msgSrv -> getMsgList();
|
||||||
std::list<MsgItem *> &msgOutlist = server -> getMsgOutList();
|
std::list<RsMsgItem *> &msgOutlist = msgSrv -> getMsgOutList();
|
||||||
std::list<MsgItem *>::iterator mit;
|
std::list<RsMsgItem *>::iterator mit;
|
||||||
|
|
||||||
std::list<MessageInfo> &msgs = iface.mMessageList;
|
std::list<MessageInfo> &msgs = iface.mMessageList;
|
||||||
|
|
||||||
@ -377,16 +374,17 @@ int RsServer::UpdateAllChannels()
|
|||||||
* for intAddChannel / intAddChannelMsg.
|
* for intAddChannel / intAddChannelMsg.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void RsServer::initRsChatInfo(ChatItem *c, ChatInfo &i)
|
void RsServer::initRsChatInfo(RsChatItem *c, ChatInfo &i)
|
||||||
{
|
{
|
||||||
RsCertId id = intGetCertId((cert *) c->p);
|
i.rsid = c -> PeerId();
|
||||||
std::ostringstream out;
|
cert *peer = intFindCert(c->PeerId());
|
||||||
out << id;
|
if (peer)
|
||||||
|
i.name = peer -> Name();
|
||||||
|
else
|
||||||
|
i.name = "Unknown";
|
||||||
|
|
||||||
i.name = c -> p -> Name();
|
i.msg = c -> message;
|
||||||
i.rsid = out.str();
|
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||||
i.msg = c -> msg;
|
|
||||||
if (c -> flags & PQI_ITEM_FLAG_PRIVATE)
|
|
||||||
{
|
{
|
||||||
std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
||||||
i.chatflags = RS_CHAT_PRIVATE;
|
i.chatflags = RS_CHAT_PRIVATE;
|
||||||
@ -509,71 +507,100 @@ void RsServer::intCheckFileStatus(FileInfo &file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RsServer::initRsMI(MsgItem *msg, MessageInfo &mi)
|
void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||||
{
|
{
|
||||||
mi.id = intGetCertId((cert *) msg->p);
|
|
||||||
|
|
||||||
mi.msgflags = 0;
|
mi.msgflags = 0;
|
||||||
|
|
||||||
/* translate flags, if we sent it... outgoing */
|
/* translate flags, if we sent it... outgoing */
|
||||||
if ((msg->msgflags & PQI_MI_FLAGS_OUTGOING)
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||||
|| (msg->p == sslr->getOwnCert()))
|
|| (msg->PeerId() == sslr->getOwnCert()->PeerId()))
|
||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_OUTGOING;
|
mi.msgflags |= RS_MSG_OUTGOING;
|
||||||
}
|
}
|
||||||
/* if it has a pending flag, then its in the outbox */
|
/* if it has a pending flag, then its in the outbox */
|
||||||
if (msg->msgflags & PQI_MI_FLAGS_PENDING)
|
if (msg->msgFlags & RS_MSG_FLAGS_PENDING)
|
||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_PENDING;
|
mi.msgflags |= RS_MSG_PENDING;
|
||||||
}
|
}
|
||||||
if (msg->msgflags & PQI_MI_FLAGS_NEW)
|
if (msg->msgFlags & RS_MSG_FLAGS_NEW)
|
||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_NEW;
|
mi.msgflags |= RS_MSG_NEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
mi.srcname = msg->p->Name();
|
mi.id = msg->PeerId();
|
||||||
|
cert *c = intFindCert(mi.id);
|
||||||
|
if (c)
|
||||||
|
mi.srcname = c->Name();
|
||||||
|
else
|
||||||
|
mi.srcname = "Unknown";
|
||||||
|
|
||||||
|
std::list<std::string>::iterator pit;
|
||||||
|
|
||||||
|
for(pit = msg->msgto.ids.begin();
|
||||||
|
pit != msg->msgto.ids.end(); pit++)
|
||||||
|
{
|
||||||
|
PersonInfo pi;
|
||||||
|
pi.id = (*pit);
|
||||||
|
cert *peer = intFindCert(pi.id);
|
||||||
|
if (peer)
|
||||||
|
pi.name = peer->Name();
|
||||||
|
else
|
||||||
|
pi.name = "Unknown";
|
||||||
|
mi.msgto.push_back(pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pit = msg->msgcc.ids.begin();
|
||||||
|
pit != msg->msgcc.ids.end(); pit++)
|
||||||
|
{
|
||||||
|
PersonInfo pi;
|
||||||
|
pi.id = (*pit);
|
||||||
|
cert *peer = intFindCert(pi.id);
|
||||||
|
if (peer)
|
||||||
|
pi.name = peer->Name();
|
||||||
|
else
|
||||||
|
pi.name = "Unknown";
|
||||||
|
mi.msgcc.push_back(pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pit = msg->msgbcc.ids.begin();
|
||||||
|
pit != msg->msgbcc.ids.end(); pit++)
|
||||||
|
{
|
||||||
|
PersonInfo pi;
|
||||||
|
pi.id = (*pit);
|
||||||
|
cert *peer = intFindCert(pi.id);
|
||||||
|
if (peer)
|
||||||
|
pi.name = peer->Name();
|
||||||
|
else
|
||||||
|
pi.name = "Unknown";
|
||||||
|
mi.msgbcc.push_back(pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
mi.title = msg->subject;
|
||||||
|
mi.msg = msg->message;
|
||||||
|
|
||||||
|
mi.attach_title = msg->attachment.title;
|
||||||
|
mi.attach_comment = msg->attachment.comment;
|
||||||
|
|
||||||
mi.title = msg->title;
|
|
||||||
mi.header = msg->header;
|
|
||||||
mi.msg = msg->msg;
|
|
||||||
mi.count = 0;
|
mi.count = 0;
|
||||||
mi.size = 0;
|
mi.size = 0;
|
||||||
|
|
||||||
std::list<MsgFileItem>::iterator it;
|
std::list<RsTlvFileItem>::iterator it;
|
||||||
for(it = msg->files.begin(); it != msg->files.end(); it++)
|
for(it = msg->attachment.items.begin();
|
||||||
|
it != msg->attachment.items.end(); it++)
|
||||||
{
|
{
|
||||||
FileInfo fi;
|
FileInfo fi;
|
||||||
fi.fname = RsDirUtil::getTopDir(it->name);
|
fi.fname = RsDirUtil::getTopDir(it->name);
|
||||||
fi.size = it->size;
|
fi.size = it->filesize;
|
||||||
fi.hash = it->hash;
|
fi.hash = it->hash;
|
||||||
fi.path = it->name;
|
fi.path = it->path;
|
||||||
mi.files.push_back(fi);
|
mi.files.push_back(fi);
|
||||||
mi.count++;
|
mi.count++;
|
||||||
mi.size += fi.size;
|
mi.size += fi.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
mi.ts = msg->sendTime;
|
mi.ts = msg->sendTime;
|
||||||
|
mi.msgId = msg->msgId;
|
||||||
#if 0
|
|
||||||
/* hash the message (nasty to put here!) */
|
|
||||||
std::ostringstream out;
|
|
||||||
msg->print(out);
|
|
||||||
char *data = strdup(out.str().c_str());
|
|
||||||
unsigned int dlen = strlen(data);
|
|
||||||
unsigned int hashsize = 1024;
|
|
||||||
unsigned char hash[hashsize];
|
|
||||||
|
|
||||||
int hsize = sslr -> hashDigest(data, dlen, hash, hashsize);
|
|
||||||
if (hsize >= CHAN_SIGN_SIZE)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < CHAN_SIGN_SIZE; i++) /* 16 Bytes XXX Must be equal! */
|
|
||||||
mi.msgId.data[i] = hash[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
#else
|
|
||||||
getRsMsgId(mi.msgId, msg->sid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
|
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
|
||||||
|
@ -45,25 +45,18 @@ RsServer::~RsServer()
|
|||||||
----> MUST BE LOCKED!
|
----> MUST BE LOCKED!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cert *RsServer::intFindCert(RsCertId &id)
|
cert *RsServer::intFindCert(RsCertId id)
|
||||||
{
|
{
|
||||||
certsign cs;
|
certsign cs;
|
||||||
for(int i = 0; i < RSCERTIDLEN; i++)
|
convert_to_certsign(id, cs);
|
||||||
{
|
|
||||||
cs.data[i] = id.data[i];
|
|
||||||
}
|
|
||||||
return sslr -> findcertsign(cs);
|
return sslr -> findcertsign(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsChanId RsServer::intGetCertId(cert *c)
|
RsCertId RsServer::intGetCertId(cert *c)
|
||||||
{
|
{
|
||||||
certsign cs;
|
certsign cs;
|
||||||
RsChanId id;
|
|
||||||
sslr -> getcertsign(c, cs);
|
sslr -> getcertsign(c, cs);
|
||||||
for(int i = 0; i < RSCERTIDLEN; i++)
|
RsCertId id = convert_to_str(cs);
|
||||||
{
|
|
||||||
id.data[i] = cs.data[i];
|
|
||||||
}
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +27,15 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
//#include <getopt.h>
|
//#include <getopt.h>
|
||||||
|
|
||||||
#include "dbase/filedex.h"
|
|
||||||
#include "server/filedexserver.h"
|
#include "server/filedexserver.h"
|
||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
#include "pqi/pqiloopback.h"
|
#include "pqi/pqiloopback.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
|
#include "services/p3disc.h"
|
||||||
|
#include "services/p3msgservice.h"
|
||||||
|
#include "services/p3chatservice.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -455,9 +458,6 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
/* sslroot does further checks */
|
/* sslroot does further checks */
|
||||||
sslr -> loadInitialTrustedPeer(config->load_trustedpeer_file);
|
sslr -> loadInitialTrustedPeer(config->load_trustedpeer_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
server->loadWelcomeMsg();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long flags = 0;
|
unsigned long flags = 0;
|
||||||
@ -476,10 +476,11 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
|
|
||||||
// create loopback device, and add to pqisslgrp.
|
// create loopback device, and add to pqisslgrp.
|
||||||
|
|
||||||
|
std::string ownPeerId = sslr->getOwnCert()->PeerId();
|
||||||
SearchModule *mod = new SearchModule();
|
SearchModule *mod = new SearchModule();
|
||||||
pqiloopback *ploop = new pqiloopback();
|
pqiloopback *ploop = new pqiloopback(ownPeerId);
|
||||||
|
|
||||||
mod -> smi = 1;
|
mod -> peerid = ownPeerId;
|
||||||
mod -> pqi = ploop;
|
mod -> pqi = ploop;
|
||||||
mod -> sp = secpolicy_create();
|
mod -> sp = secpolicy_create();
|
||||||
|
|
||||||
@ -491,7 +492,21 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
|
|
||||||
server->load_config();
|
server->load_config();
|
||||||
|
|
||||||
ad = pqih->getP3Disc();
|
/* create Services */
|
||||||
|
ad = new p3disc(sslr);
|
||||||
|
msgSrv = new p3MsgService();
|
||||||
|
chatSrv = new p3ChatService();
|
||||||
|
|
||||||
|
pqih -> addService(ad);
|
||||||
|
pqih -> addService(msgSrv);
|
||||||
|
pqih -> addService(chatSrv);
|
||||||
|
|
||||||
|
/* put a welcome message in! */
|
||||||
|
if (config->firsttime_run)
|
||||||
|
{
|
||||||
|
msgSrv->loadWelcomeMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// load up the help page
|
// load up the help page
|
||||||
std::string helppage = config->basedir + config->dirSeperator;
|
std::string helppage = config->basedir + config->dirSeperator;
|
||||||
|
@ -30,12 +30,14 @@
|
|||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
#include "pqi/pqissl.h"
|
#include "pqi/pqissl.h"
|
||||||
|
|
||||||
#include "pqi/p3disc.h"
|
|
||||||
|
|
||||||
#include "rsiface/rsiface.h"
|
#include "rsiface/rsiface.h"
|
||||||
#include "rsiface/rstypes.h"
|
#include "rsiface/rstypes.h"
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
|
#include "services/p3disc.h"
|
||||||
|
#include "services/p3msgservice.h"
|
||||||
|
#include "services/p3chatservice.h"
|
||||||
|
|
||||||
/* The Main Interface Class - for controlling the server */
|
/* The Main Interface Class - for controlling the server */
|
||||||
|
|
||||||
/* The init functions are actually Defined in p3face-startup.cc
|
/* The init functions are actually Defined in p3face-startup.cc
|
||||||
@ -48,6 +50,8 @@ int LoadCertificates(RsInit *config);
|
|||||||
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify);
|
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify);
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
class PendingDirectory
|
class PendingDirectory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -60,6 +64,9 @@ void addEntry(PQFileItem *item);
|
|||||||
DirInfo data;
|
DirInfo data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RsServer: public RsControl, public RsThread
|
class RsServer: public RsControl, public RsThread
|
||||||
{
|
{
|
||||||
@ -99,7 +106,7 @@ void unlockRsCore()
|
|||||||
(Must be Locked)
|
(Must be Locked)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cert *intFindCert(RsCertId &id);
|
cert *intFindCert(RsCertId id);
|
||||||
RsCertId intGetCertId(cert *c);
|
RsCertId intGetCertId(cert *c);
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
@ -190,9 +197,8 @@ int UpdateRemotePeople();
|
|||||||
public:
|
public:
|
||||||
/* Message Items */
|
/* Message Items */
|
||||||
virtual int MessageSend(MessageInfo &info);
|
virtual int MessageSend(MessageInfo &info);
|
||||||
virtual int MessageDelete(std::string id);
|
virtual int MessageDelete(std::string mid);
|
||||||
virtual int MessageRead(std::string id);
|
virtual int MessageRead(std::string mid);
|
||||||
|
|
||||||
|
|
||||||
/* Channel Items */
|
/* Channel Items */
|
||||||
virtual int ChannelCreateNew(ChannelInfo &info);
|
virtual int ChannelCreateNew(ChannelInfo &info);
|
||||||
@ -221,7 +227,7 @@ int UpdateAllChat();
|
|||||||
int UpdateAllMsgs();
|
int UpdateAllMsgs();
|
||||||
int UpdateAllChannels();
|
int UpdateAllChannels();
|
||||||
|
|
||||||
void initRsChatInfo(ChatItem *c, ChatInfo &i);
|
void initRsChatInfo(RsChatItem *c, ChatInfo &i);
|
||||||
|
|
||||||
|
|
||||||
#ifdef PQI_USE_CHANNELS
|
#ifdef PQI_USE_CHANNELS
|
||||||
@ -242,7 +248,7 @@ void initRsCMFI(pqichannel *chan, chanMsgSummary *msg,
|
|||||||
|
|
||||||
void intCheckFileStatus(FileInfo &file);
|
void intCheckFileStatus(FileInfo &file);
|
||||||
|
|
||||||
void initRsMI(MsgItem *msg, MessageInfo &mi);
|
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/****************************************/
|
/****************************************/
|
||||||
@ -300,7 +306,11 @@ int UpdateAllConfig();
|
|||||||
filedexserver *server;
|
filedexserver *server;
|
||||||
pqipersongrp *pqih;
|
pqipersongrp *pqih;
|
||||||
sslroot *sslr;
|
sslroot *sslr;
|
||||||
|
|
||||||
|
/* services */
|
||||||
p3disc *ad;
|
p3disc *ad;
|
||||||
|
p3MsgService *msgSrv;
|
||||||
|
p3ChatService *chatSrv;
|
||||||
|
|
||||||
// Worker Data.....
|
// Worker Data.....
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
/****************************************/
|
/****************************************/
|
||||||
RsCertId::RsCertId()
|
RsCertId::RsCertId()
|
||||||
{
|
{
|
||||||
@ -115,6 +116,8 @@ std::ostream &operator<<(std::ostream &out, const RsCertId &id)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* Print Functions for Info Classes */
|
/* Print Functions for Info Classes */
|
||||||
|
25
libretroshare/src/services/Makefile
Normal file
25
libretroshare/src/services/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
RS_TOP_DIR = ..
|
||||||
|
##### Define any flags that are needed for this section #######
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
include $(RS_TOP_DIR)/scripts/config.mk
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
RSOBJ = p3service.o p3disc.o p3chatservice.o p3msgservice.o
|
||||||
|
|
||||||
|
#TESTOBJ =
|
||||||
|
|
||||||
|
#TESTS =
|
||||||
|
|
||||||
|
all: librs tests
|
||||||
|
|
||||||
|
#tlvbase_test : tlvbase_test.o
|
||||||
|
# $(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||||
|
###############################################################
|
||||||
|
|
145
libretroshare/src/services/p3chatservice.cc
Normal file
145
libretroshare/src/services/p3chatservice.cc
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* "$Id: p3ChatService.cc,v 1.24 2007-05-05 16:10:06 rmf24 Exp $"
|
||||||
|
*
|
||||||
|
* Other Bits for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2006 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "services/p3chatservice.h"
|
||||||
|
#include "pqi/pqidebug.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
#if defined(PQI_USE_XPGP)
|
||||||
|
|
||||||
|
#include "pqi/xpgpcert.h"
|
||||||
|
|
||||||
|
#else /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
#include "pqi/sslcert.h"
|
||||||
|
|
||||||
|
#endif /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const int p3chatzone = 1745;
|
||||||
|
|
||||||
|
p3ChatService::p3ChatService()
|
||||||
|
:p3Service(RS_SERVICE_TYPE_CHAT)
|
||||||
|
{
|
||||||
|
addSerialType(new RsChatSerialiser());
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3ChatService::tick()
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone,
|
||||||
|
"p3ChatService::tick()");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3ChatService::status()
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone,
|
||||||
|
"p3ChatService::status()");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************** Chat Stuff **********************/
|
||||||
|
|
||||||
|
int p3ChatService::sendChat(std::string msg)
|
||||||
|
{
|
||||||
|
/* go through all the peers */
|
||||||
|
sslroot *sslr = getSSLRoot();
|
||||||
|
|
||||||
|
std::list<cert *>::iterator it;
|
||||||
|
std::list<cert *> &certs = sslr -> getCertList();
|
||||||
|
|
||||||
|
for(it = certs.begin(); it != certs.end(); it++)
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone,
|
||||||
|
"p3ChatService::sendChat()");
|
||||||
|
|
||||||
|
RsChatItem *ci = new RsChatItem();
|
||||||
|
|
||||||
|
ci->PeerId((*it)->PeerId());
|
||||||
|
ci->chatFlags = 0;
|
||||||
|
ci->sendTime = time(NULL);
|
||||||
|
ci->message = msg;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "Chat Item we are sending:" << std::endl;
|
||||||
|
ci -> print(out);
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone, out.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
sendItem(ci);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3ChatService::sendPrivateChat(std::string msg, std::string id)
|
||||||
|
{
|
||||||
|
// make chat item....
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone,
|
||||||
|
"p3ChatService::sendPrivateChat()");
|
||||||
|
|
||||||
|
RsChatItem *ci = new RsChatItem();
|
||||||
|
|
||||||
|
ci->PeerId(id);
|
||||||
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE;
|
||||||
|
ci->sendTime = time(NULL);
|
||||||
|
ci->message = msg;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "Private Chat Item we are sending:" << std::endl;
|
||||||
|
ci -> print(out);
|
||||||
|
out << "Sending to:" << id << std::endl;
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, p3chatzone, out.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
sendItem(ci);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<RsChatItem *> p3ChatService::getChatQueue()
|
||||||
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
RsChatItem *ci = NULL;
|
||||||
|
std::list<RsChatItem *> ilist;
|
||||||
|
|
||||||
|
while(NULL != (ci = (RsChatItem *) recvItem()))
|
||||||
|
{
|
||||||
|
ci->recvTime = now;
|
||||||
|
ilist.push_back(ci);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ilist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
57
libretroshare/src/services/p3chatservice.h
Normal file
57
libretroshare/src/services/p3chatservice.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services chatservice.h
|
||||||
|
*
|
||||||
|
* Services for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SERVICE_CHAT_HEADER
|
||||||
|
#define SERVICE_CHAT_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The basic Chat service.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "serialiser/rsmsgitems.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
|
||||||
|
|
||||||
|
class p3ChatService: public p3Service
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
p3ChatService();
|
||||||
|
|
||||||
|
/* overloaded */
|
||||||
|
virtual int tick();
|
||||||
|
virtual int status();
|
||||||
|
|
||||||
|
int sendChat(std::string msg);
|
||||||
|
int sendPrivateChat(std::string msg, std::string id);
|
||||||
|
|
||||||
|
std::list<RsChatItem *> getChatQueue();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERVICE_CHAT_HEADER
|
2229
libretroshare/src/services/p3disc.cc
Normal file
2229
libretroshare/src/services/p3disc.cc
Normal file
File diff suppressed because it is too large
Load Diff
169
libretroshare/src/services/p3disc.h
Normal file
169
libretroshare/src/services/p3disc.h
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services: p3disc.h
|
||||||
|
*
|
||||||
|
* Services for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MRK_PQI_AUTODISC_H
|
||||||
|
#define MRK_PQI_AUTODISC_H
|
||||||
|
|
||||||
|
// The AutoDiscovery Class
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
// system specific network headers
|
||||||
|
#include "pqi/pqinetwork.h"
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
#if defined(PQI_USE_XPGP)
|
||||||
|
|
||||||
|
#include "pqi/xpgpcert.h"
|
||||||
|
|
||||||
|
#else /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
#include "pqi/sslcert.h"
|
||||||
|
|
||||||
|
#endif /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "serialiser/rsdiscitems.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
|
||||||
|
class autoserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
autoserver()
|
||||||
|
:id(NULL), ca(NULL), connect(false), c_ts(0),
|
||||||
|
listen(false), l_ts(0), discFlags(0) { return;}
|
||||||
|
|
||||||
|
Person *id;
|
||||||
|
Person *ca;
|
||||||
|
bool connect;
|
||||||
|
unsigned int c_ts; // this is connect_tf converted to timestamp, 0 invalid.
|
||||||
|
|
||||||
|
bool listen;
|
||||||
|
unsigned int l_ts; // this is receive_tf converted to timestamp, 0 invalid.
|
||||||
|
|
||||||
|
struct sockaddr_in local_addr;
|
||||||
|
struct sockaddr_in server_addr;
|
||||||
|
unsigned long discFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class autoneighbour: public autoserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
autoneighbour()
|
||||||
|
:autoserver(), local(false), active(false) {}
|
||||||
|
|
||||||
|
bool local;
|
||||||
|
bool active; // meaning in ssl's list.
|
||||||
|
std::list<autoserver *> neighbour_of;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class p3disc: public p3Service
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool local_disc;
|
||||||
|
bool remote_disc;
|
||||||
|
//sslroot *sslbase;
|
||||||
|
|
||||||
|
p3disc(sslroot *r);
|
||||||
|
virtual ~p3disc();
|
||||||
|
|
||||||
|
// Overloaded from p3Service functions.
|
||||||
|
virtual int tick();
|
||||||
|
|
||||||
|
|
||||||
|
// For Proxy Information.
|
||||||
|
std::list<sockaddr_in> requestStunServers();
|
||||||
|
std::list<cert *> potentialproxy(cert *target);
|
||||||
|
|
||||||
|
// load and save configuration to sslroot.
|
||||||
|
int save_configuration();
|
||||||
|
int load_configuration();
|
||||||
|
|
||||||
|
int ts_lastcheck;
|
||||||
|
|
||||||
|
int idServers();
|
||||||
|
|
||||||
|
// Handle Local Discovery.
|
||||||
|
int localListen();
|
||||||
|
int localSetup();
|
||||||
|
|
||||||
|
int lsock; // local discovery socket.
|
||||||
|
struct sockaddr_in laddr; // local addr
|
||||||
|
struct sockaddr_in baddr; // local broadcast addr.
|
||||||
|
struct sockaddr_in saddr; // pqi ssl server addr.
|
||||||
|
|
||||||
|
// bonus configuration flags.
|
||||||
|
bool local_firewalled;
|
||||||
|
bool local_forwarded;
|
||||||
|
|
||||||
|
|
||||||
|
// local message construction/destruction.
|
||||||
|
void *ldata;
|
||||||
|
int ldlen;
|
||||||
|
int ldlenmax;
|
||||||
|
|
||||||
|
|
||||||
|
bool std_port; // if we have bound to default.
|
||||||
|
int ts_nextlp; // -1 for never (if on default)
|
||||||
|
|
||||||
|
// helper functions.
|
||||||
|
int setLocalAddress(struct sockaddr_in srvaddr);
|
||||||
|
int determineLocalNetAddr();
|
||||||
|
int setupLocalPacket(int type, struct sockaddr_in *home,
|
||||||
|
struct sockaddr_in *server);
|
||||||
|
int localPing(struct sockaddr_in);
|
||||||
|
int localReply(struct sockaddr_in);
|
||||||
|
int addLocalNeighbour(struct sockaddr_in*, struct sockaddr_in*);
|
||||||
|
|
||||||
|
// remote discovery function.
|
||||||
|
int newRequests();
|
||||||
|
int handleReplies();
|
||||||
|
|
||||||
|
int handleDiscoveryData(RsDiscReply *di);
|
||||||
|
int handleDiscoveryPing(RsDiscItem *di);
|
||||||
|
int sendDiscoveryReply(cert *);
|
||||||
|
int collectCerts();
|
||||||
|
int distillData();
|
||||||
|
|
||||||
|
//cert *checkDuplicateX509(X509 *x509);
|
||||||
|
std::list<cert *> &getDiscovered();
|
||||||
|
|
||||||
|
// Main Storage
|
||||||
|
std::list<autoneighbour *> neighbours;
|
||||||
|
std::list<cert *> ad_init;
|
||||||
|
|
||||||
|
std::list<cert *> discovered;
|
||||||
|
sslroot *sroot;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MRK_PQI_AUTODISC_H
|
383
libretroshare/src/services/p3msgservice.cc
Normal file
383
libretroshare/src/services/p3msgservice.cc
Normal file
@ -0,0 +1,383 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services msgservice.cc
|
||||||
|
*
|
||||||
|
* Services for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "pqi/pqibin.h"
|
||||||
|
#include "pqi/pqiarchive.h"
|
||||||
|
#include "pqi/pqidebug.h"
|
||||||
|
|
||||||
|
#include "services/p3msgservice.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
#if defined(PQI_USE_XPGP)
|
||||||
|
|
||||||
|
#include "pqi/xpgpcert.h"
|
||||||
|
|
||||||
|
#else /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
#include "pqi/sslcert.h"
|
||||||
|
|
||||||
|
#endif /* X509 Certificates */
|
||||||
|
/**************** PQI_USE_XPGP ******************/
|
||||||
|
|
||||||
|
|
||||||
|
const int msgservicezone = 54319;
|
||||||
|
|
||||||
|
|
||||||
|
/* Another little hack ..... unique message Ids
|
||||||
|
* will be handled in this class.....
|
||||||
|
* These are unique within this run of the server,
|
||||||
|
* and are not stored long term....
|
||||||
|
*
|
||||||
|
* Only 3 entry points:
|
||||||
|
* (1) from network....
|
||||||
|
* (2) from local send
|
||||||
|
* (3) from storage...
|
||||||
|
*/
|
||||||
|
|
||||||
|
static unsigned int msgUniqueId = 1;
|
||||||
|
unsigned int getNewUniqueMsgId()
|
||||||
|
{
|
||||||
|
return msgUniqueId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
p3MsgService::p3MsgService()
|
||||||
|
:p3Service(RS_SERVICE_TYPE_MSG),
|
||||||
|
msgChanged(1), msgMajorChanged(1)
|
||||||
|
{
|
||||||
|
sslr = getSSLRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int p3MsgService::tick()
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
||||||
|
"p3MsgService::tick()");
|
||||||
|
|
||||||
|
/* don't worry about increasing tick rate!
|
||||||
|
* (handled by p3service)
|
||||||
|
*/
|
||||||
|
|
||||||
|
incomingMsgs();
|
||||||
|
checkOutgoingMessages();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int p3MsgService::status()
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
||||||
|
"p3MsgService::status()");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3MsgService::incomingMsgs()
|
||||||
|
{
|
||||||
|
RsMsgItem *mi;
|
||||||
|
int i = 0;
|
||||||
|
while((mi = (RsMsgItem *) recvItem()) != NULL)
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
mi -> recvTime = time(NULL);
|
||||||
|
std::string mesg;
|
||||||
|
|
||||||
|
if (mi -> PeerId() == sslr->getOwnCert()->PeerId())
|
||||||
|
{
|
||||||
|
/* from the loopback device */
|
||||||
|
mi -> msgFlags = RS_MSG_FLAGS_OUTGOING;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* from a peer */
|
||||||
|
mi -> msgFlags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* new as well! */
|
||||||
|
mi -> msgFlags |= RS_MSG_FLAGS_NEW;
|
||||||
|
|
||||||
|
/* STORE MsgID */
|
||||||
|
mi -> msgId = getNewUniqueMsgId();
|
||||||
|
|
||||||
|
imsg.push_back(mi);
|
||||||
|
msgChanged.IndicateChanged();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::list<RsMsgItem *> &p3MsgService::getMsgList()
|
||||||
|
{
|
||||||
|
return imsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<RsMsgItem *> &p3MsgService::getMsgOutList()
|
||||||
|
{
|
||||||
|
return msgOutgoing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove based on the unique mid (stored in sid) */
|
||||||
|
int p3MsgService::removeMsgId(uint32_t mid)
|
||||||
|
{
|
||||||
|
std::list<RsMsgItem *>::iterator it;
|
||||||
|
|
||||||
|
for(it = imsg.begin(); it != imsg.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it)->msgId == mid)
|
||||||
|
{
|
||||||
|
RsMsgItem *mi = (*it);
|
||||||
|
imsg.erase(it);
|
||||||
|
delete mi;
|
||||||
|
msgChanged.IndicateChanged();
|
||||||
|
msgMajorChanged.IndicateChanged();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* try with outgoing messages otherwise */
|
||||||
|
for(it = msgOutgoing.begin(); it != msgOutgoing.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it)->msgId == mid)
|
||||||
|
{
|
||||||
|
RsMsgItem *mi = (*it);
|
||||||
|
msgOutgoing.erase(it);
|
||||||
|
delete mi;
|
||||||
|
msgChanged.IndicateChanged();
|
||||||
|
msgMajorChanged.IndicateChanged();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3MsgService::markMsgIdRead(uint32_t mid)
|
||||||
|
{
|
||||||
|
std::list<RsMsgItem *>::iterator it;
|
||||||
|
|
||||||
|
for(it = imsg.begin(); it != imsg.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it)->msgId == mid)
|
||||||
|
{
|
||||||
|
RsMsgItem *mi = (*it);
|
||||||
|
mi -> msgFlags &= ~(RS_MSG_FLAGS_NEW);
|
||||||
|
msgChanged.IndicateChanged();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3MsgService::sendMessage(RsMsgItem *item)
|
||||||
|
{
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
||||||
|
"p3MsgService::sendMessage()");
|
||||||
|
|
||||||
|
/* add pending flag */
|
||||||
|
item->msgFlags |=
|
||||||
|
(RS_MSG_FLAGS_OUTGOING |
|
||||||
|
RS_MSG_FLAGS_PENDING);
|
||||||
|
/* STORE MsgID */
|
||||||
|
item -> msgId = getNewUniqueMsgId();
|
||||||
|
msgOutgoing.push_back(item);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3MsgService::checkOutgoingMessages()
|
||||||
|
{
|
||||||
|
/* iterate through the outgoing queue
|
||||||
|
*
|
||||||
|
* if online, send
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::list<RsMsgItem *>::iterator it;
|
||||||
|
for(it = msgOutgoing.begin(); it != msgOutgoing.end();)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* find the certificate */
|
||||||
|
certsign sign;
|
||||||
|
convert_to_certsign((*it)->PeerId(), sign);
|
||||||
|
cert *peer = sslr -> findcertsign(sign);
|
||||||
|
|
||||||
|
/* if online, send it */
|
||||||
|
if ((peer -> Status() & PERSON_STATUS_CONNECTED)
|
||||||
|
|| (peer == sslr->getOwnCert()))
|
||||||
|
{
|
||||||
|
/* send msg */
|
||||||
|
pqioutput(PQL_ALERT, msgservicezone,
|
||||||
|
"p3MsgService::checkOutGoingMessages() Sending out message");
|
||||||
|
/* remove the pending flag */
|
||||||
|
(*it)->msgFlags &= ~RS_MSG_FLAGS_PENDING;
|
||||||
|
|
||||||
|
sendItem(*it);
|
||||||
|
it = msgOutgoing.erase(it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pqioutput(PQL_ALERT, msgservicezone,
|
||||||
|
"p3MsgService::checkOutGoingMessages() Delaying until available...");
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int p3MsgService::save_config()
|
||||||
|
{
|
||||||
|
std::list<std::string>::iterator it;
|
||||||
|
std::string empty("");
|
||||||
|
|
||||||
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
||||||
|
"p3MsgService::save_config()");
|
||||||
|
|
||||||
|
/* now we create a pqiarchive, and stream all the msgs into it
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::string statelog = config_dir + "/msgs.rst";
|
||||||
|
RsSerialiser *rss = new RsSerialiser();
|
||||||
|
rss->addSerialType(new RsMsgSerialiser());
|
||||||
|
|
||||||
|
BinFileInterface *out = new BinFileInterface((char *) statelog.c_str(), BIN_FLAGS_WRITEABLE);
|
||||||
|
pqiarchive *pa_out = new pqiarchive(rss, out, BIN_FLAGS_WRITEABLE | BIN_FLAGS_NO_DELETE);
|
||||||
|
bool written = false;
|
||||||
|
|
||||||
|
std::list<RsMsgItem *>::iterator mit;
|
||||||
|
for(mit = imsg.begin(); mit != imsg.end(); mit++)
|
||||||
|
{
|
||||||
|
//RsMsgItem *mi = (*mit)->clone();
|
||||||
|
if (pa_out -> SendItem(*mit))
|
||||||
|
{
|
||||||
|
written = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
||||||
|
{
|
||||||
|
//RsMsgItem *mi = (*mit)->clone();
|
||||||
|
//mi -> msgFlags |= RS_MSG_FLAGS_PENDING;
|
||||||
|
if (pa_out -> SendItem(*mit))
|
||||||
|
{
|
||||||
|
written = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!written)
|
||||||
|
{
|
||||||
|
/* need to push something out to overwrite old data! (For WINDOWS ONLY) */
|
||||||
|
}
|
||||||
|
|
||||||
|
delete pa_out;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3MsgService::load_config()
|
||||||
|
{
|
||||||
|
std::list<std::string>::iterator it;
|
||||||
|
|
||||||
|
std::string empty("");
|
||||||
|
std::string dir("notempty");
|
||||||
|
std::string str_true("true");
|
||||||
|
|
||||||
|
/* load msg/ft */
|
||||||
|
std::string statelog = config_dir + "/msgs.rst";
|
||||||
|
|
||||||
|
RsSerialiser *rss = new RsSerialiser();
|
||||||
|
rss->addSerialType(new RsMsgSerialiser());
|
||||||
|
|
||||||
|
BinFileInterface *in = new BinFileInterface((char *) statelog.c_str(), BIN_FLAGS_READABLE);
|
||||||
|
pqiarchive *pa_in = new pqiarchive(rss, in, BIN_FLAGS_READABLE);
|
||||||
|
RsItem *item;
|
||||||
|
RsMsgItem *mitem;
|
||||||
|
|
||||||
|
while((item = pa_in -> GetItem()))
|
||||||
|
{
|
||||||
|
if (NULL != (mitem = dynamic_cast<RsMsgItem *>(item)))
|
||||||
|
{
|
||||||
|
/* switch depending on the PENDING
|
||||||
|
* flags
|
||||||
|
*/
|
||||||
|
/* STORE MsgID */
|
||||||
|
mitem->msgId = getNewUniqueMsgId();
|
||||||
|
if (mitem -> msgFlags & RS_MSG_FLAGS_PENDING)
|
||||||
|
{
|
||||||
|
std::cerr << "MSG_PENDING";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
mitem->print(std::cerr);
|
||||||
|
msgOutgoing.push_back(mitem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imsg.push_back(mitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete pa_in;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void p3MsgService::loadWelcomeMsg()
|
||||||
|
{
|
||||||
|
/* Load Welcome Message */
|
||||||
|
RsMsgItem *msg = new RsMsgItem();
|
||||||
|
|
||||||
|
msg -> PeerId(sslr->getOwnCert()->PeerId());
|
||||||
|
|
||||||
|
msg -> sendTime = 0;
|
||||||
|
|
||||||
|
msg -> subject = "Welcome to Retroshare";
|
||||||
|
|
||||||
|
msg -> message = "Send and receive messages\n";
|
||||||
|
msg -> message += "with your friends...\n\n";
|
||||||
|
|
||||||
|
msg -> message += "These can hold recommendations\n";
|
||||||
|
msg -> message += "from your local shared files\n\n";
|
||||||
|
|
||||||
|
msg -> message += "Add recommendations through\n";
|
||||||
|
msg -> message += "the Local Files Dialog\n\n";
|
||||||
|
|
||||||
|
msg -> message += "Enjoy.\n";
|
||||||
|
|
||||||
|
imsg.push_back(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
84
libretroshare/src/services/p3msgservice.h
Normal file
84
libretroshare/src/services/p3msgservice.h
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services msgservice.h
|
||||||
|
*
|
||||||
|
* Services for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MESSAGE_SERVICE_HEADER
|
||||||
|
#define MESSAGE_SERVICE_HEADER
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
#include "pqi/pqiindic.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
#include "serialiser/rsmsgitems.h"
|
||||||
|
|
||||||
|
#include "rsiface/rsiface.h"
|
||||||
|
class pqimonitor;
|
||||||
|
class sslroot;
|
||||||
|
|
||||||
|
class p3MsgService: public p3Service
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
p3MsgService();
|
||||||
|
|
||||||
|
void loadWelcomeMsg(); /* startup message */
|
||||||
|
|
||||||
|
int sendMessage(RsMsgItem *item);
|
||||||
|
int checkOutgoingMessages();
|
||||||
|
|
||||||
|
std::list<RsMsgItem *> &getMsgList();
|
||||||
|
std::list<RsMsgItem *> &getMsgOutList();
|
||||||
|
|
||||||
|
// cleaning up....
|
||||||
|
int removeMsgId(uint32_t mid); /* id stored in sid */
|
||||||
|
int markMsgIdRead(uint32_t mid);
|
||||||
|
|
||||||
|
int load_config();
|
||||||
|
int save_config();
|
||||||
|
|
||||||
|
int tick();
|
||||||
|
int status();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int incomingMsgs();
|
||||||
|
|
||||||
|
|
||||||
|
std::list<RsMsgItem *> imsg;
|
||||||
|
std::list<RsMsgItem *> msgOutgoing; /* ones that haven't made it out yet! */
|
||||||
|
|
||||||
|
// bool state flags.
|
||||||
|
public:
|
||||||
|
Indicator msgChanged;
|
||||||
|
Indicator msgMajorChanged;
|
||||||
|
|
||||||
|
sslroot *sslr;
|
||||||
|
std::string config_dir;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MESSAGE_SERVICE_HEADER
|
163
libretroshare/src/services/p3service.cc
Normal file
163
libretroshare/src/services/p3service.cc
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services p3service.cc
|
||||||
|
*
|
||||||
|
* 3P/PQI network interface for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
#include "services/p3service.h"
|
||||||
|
|
||||||
|
void p3Service::addSerialType(RsSerialType *st)
|
||||||
|
{
|
||||||
|
rsSerialiser->addSerialType(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
RsItem *p3Service::recvItem()
|
||||||
|
{
|
||||||
|
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||||
|
|
||||||
|
if (recv_queue.size() == 0)
|
||||||
|
{
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
return NULL; /* nothing there! */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get something off front */
|
||||||
|
RsItem *item = recv_queue.front();
|
||||||
|
recv_queue.pop_front();
|
||||||
|
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3Service::receivedItems()
|
||||||
|
{
|
||||||
|
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||||
|
|
||||||
|
bool moreData = (recv_queue.size() != 0);
|
||||||
|
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
|
||||||
|
return moreData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int p3Service::sendItem(RsItem *item)
|
||||||
|
{
|
||||||
|
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||||
|
|
||||||
|
send_queue.push_back(item);
|
||||||
|
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// overloaded pqiService interface.
|
||||||
|
int p3Service::receive(RsRawItem *raw)
|
||||||
|
{
|
||||||
|
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||||
|
|
||||||
|
std::cerr << "p3Service::receive()" << std::endl;
|
||||||
|
|
||||||
|
/* convert to RsServiceItem */
|
||||||
|
uint32_t size = raw->getRawLength();
|
||||||
|
RsItem *item = rsSerialiser->deserialise(raw->getRawData(), &size);
|
||||||
|
if ((!item) || (size != raw->getRawLength()))
|
||||||
|
{
|
||||||
|
/* error in conversion */
|
||||||
|
std::cerr << "p3Service::receive() Error" << std::endl;
|
||||||
|
std::cerr << "p3Service::receive() Size: " << size << std::endl;
|
||||||
|
std::cerr << "p3Service::receive() RawLength: " << raw->getRawLength() << std::endl;
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* if we have something - pass it on */
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
/* ensure PeerId is transferred */
|
||||||
|
item->PeerId(raw->PeerId());
|
||||||
|
recv_queue.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* cleanup input */
|
||||||
|
delete raw;
|
||||||
|
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
|
||||||
|
return (item != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
RsRawItem *p3Service::send()
|
||||||
|
{
|
||||||
|
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||||
|
|
||||||
|
if (send_queue.size() == 0)
|
||||||
|
{
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
return NULL; /* nothing there! */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get something off front */
|
||||||
|
RsItem *si = send_queue.front();
|
||||||
|
send_queue.pop_front();
|
||||||
|
|
||||||
|
/* try to convert */
|
||||||
|
uint32_t size = rsSerialiser->size(si);
|
||||||
|
if (!size)
|
||||||
|
{
|
||||||
|
/* can't convert! */
|
||||||
|
delete si;
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsRawItem *raw = new RsRawItem(si->PacketId(), size);
|
||||||
|
if (!rsSerialiser->serialise(si, raw->getRawData(), &size))
|
||||||
|
{
|
||||||
|
delete raw;
|
||||||
|
raw = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((raw) && (size != raw->getRawLength()))
|
||||||
|
{
|
||||||
|
delete raw;
|
||||||
|
raw = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ensure PeerId is transferred */
|
||||||
|
raw->PeerId(si->PeerId());
|
||||||
|
|
||||||
|
/* cleanup */
|
||||||
|
delete si;
|
||||||
|
|
||||||
|
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
116
libretroshare/src/services/p3service.h
Normal file
116
libretroshare/src/services/p3service.h
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services p3service.h
|
||||||
|
*
|
||||||
|
* 3P/PQI network interface for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2004-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef P3_GENERIC_SERVICE_HEADER
|
||||||
|
#define P3_GENERIC_SERVICE_HEADER
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
#include "pqi/pqiservice.h"
|
||||||
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
|
/* This provides easy to use extensions to the pqiservice class provided in src/pqi.
|
||||||
|
*
|
||||||
|
* We will have a number of different strains.
|
||||||
|
*
|
||||||
|
* (1) p3Service -> pqiService
|
||||||
|
*
|
||||||
|
* Basic service with serialisation handled by a RsSerialiser.
|
||||||
|
*
|
||||||
|
* (2) p3ThreadedService -> p3service.
|
||||||
|
*
|
||||||
|
* Independent thread with mutex locks for i/o Queues.
|
||||||
|
* ideal for games etc.
|
||||||
|
*
|
||||||
|
* (3) p3CacheService -> p3service + CacheSource + CacheStore.
|
||||||
|
*
|
||||||
|
* For both Cached and Messages.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class p3Service: public pqiService
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
p3Service(uint16_t type)
|
||||||
|
:pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8)),
|
||||||
|
rsSerialiser(NULL)
|
||||||
|
{
|
||||||
|
rsSerialiser = new RsSerialiser();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~p3Service() { delete rsSerialiser; return; }
|
||||||
|
|
||||||
|
/*************** INTERFACE ******************************/
|
||||||
|
/* called from Thread/tick/GUI */
|
||||||
|
int sendItem(RsItem *);
|
||||||
|
RsItem * recvItem();
|
||||||
|
bool receivedItems();
|
||||||
|
|
||||||
|
virtual int tick() { return 0; }
|
||||||
|
/*************** INTERFACE ******************************/
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
// overloaded pqiService interface.
|
||||||
|
virtual int receive(RsRawItem *);
|
||||||
|
virtual RsRawItem * send();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void addSerialType(RsSerialType *);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
RsMutex srvMtx;
|
||||||
|
/* below locked by Mutex */
|
||||||
|
|
||||||
|
RsSerialiser *rsSerialiser;
|
||||||
|
std::list<RsItem *> recv_queue, send_queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
class p3ThreadedService: public p3Service, public RsThread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
p3ThreadedService(RsSerialiser *rss, uint32_t type)
|
||||||
|
:p3Service(rss, type) { return; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~p3ThreadedService() { return; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // P3_GENERIC_SERVICE_HEADER
|
||||||
|
|
Loading…
Reference in New Issue
Block a user