mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-18 04:14:28 -05:00
Improved the bootstrap Stun system.
* searching for STUN ID's continues until RS_STUN_FOUND_MIN are found (10). * abandon STUN search if Ext or Upnp mode. * add Bootstrap IDs to rear of mStunList. (bugfix) Force saving of certificates after "oldFormat" loading. Corrected printStunList() fn call. Added a notification system: (1) libretroshare System Notifications. - System notification if Firewall Status is bad. (2) PopUp messages. - Popup for a connected peer. - Popup for a new message. * New interface (to be revised). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@376 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
08860b25e6
commit
0bdc3522a6
@ -2079,6 +2079,7 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
|
||||
if (keyValueMap.size() > 0)
|
||||
{
|
||||
oldFormat = true;
|
||||
mToSaveCerts = true;
|
||||
}
|
||||
|
||||
mToSaveCerts = false;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "util/rsprint.h"
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsiface/rsnotify.h"
|
||||
|
||||
/* Network setup States */
|
||||
|
||||
@ -42,6 +43,7 @@ const uint32_t RS_NET_DONE = 0x0005;
|
||||
const uint32_t RS_STUN_DHT = 0x0001;
|
||||
const uint32_t RS_STUN_DONE = 0x0002;
|
||||
const uint32_t RS_STUN_LIST_MIN = 100;
|
||||
const uint32_t RS_STUN_FOUND_MIN = 10;
|
||||
|
||||
const uint32_t MAX_UPNP_INIT = 30; /* seconds UPnP timeout */
|
||||
|
||||
@ -100,7 +102,8 @@ peerConnectState::peerConnectState()
|
||||
p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
||||
:p3Config(CONFIG_TYPE_PEERS),
|
||||
mAuthMgr(am), mDhtMgr(NULL), mUpnpMgr(NULL), mNetStatus(RS_NET_UNKNOWN),
|
||||
mStunStatus(0), mStatusChanged(false)
|
||||
mStunStatus(0), mStunFound(0), mStunMoreRequired(true),
|
||||
mStatusChanged(false)
|
||||
{
|
||||
mUpnpAddrValid = false;
|
||||
mStunAddrValid = false;
|
||||
@ -262,6 +265,8 @@ void p3ConnectMgr::netStartup()
|
||||
std::cerr << "p3ConnectMgr::netStartup() disabling stunkeepalive() cos EXT" << std::endl;
|
||||
#endif
|
||||
tou_stunkeepalive(0);
|
||||
mStunMoreRequired = false; /* only need to validate address (EXT) */
|
||||
|
||||
break;
|
||||
|
||||
case RS_NET_MODE_TRY_UDP:
|
||||
@ -278,13 +283,11 @@ void p3ConnectMgr::netStartup()
|
||||
break;
|
||||
}
|
||||
|
||||
/* add Bootstrap Peers if we've got none from config */
|
||||
if (mStunList.size() < 1)
|
||||
{
|
||||
addBootstrapStunPeers();
|
||||
}
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
/* add Bootstrap Peers ALWAYs (get stuck on the end) */
|
||||
addBootstrapStunPeers();
|
||||
}
|
||||
|
||||
|
||||
@ -413,6 +416,7 @@ void p3ConnectMgr::netTick()
|
||||
#ifdef CONN_DEBUG
|
||||
//std::cerr << "p3ConnectMgr::netTick() STATUS: DONE" << std::endl;
|
||||
#endif
|
||||
stunCheck(); /* Keep on stunning until its happy */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -501,7 +505,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
mUpnpAddrValid = false;
|
||||
mNetStatus = RS_NET_UDP_SETUP;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() ensabling stunkeepalive() cos UDP" << std::endl;
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() enabling stunkeepalive() cos UDP" << std::endl;
|
||||
#endif
|
||||
tou_stunkeepalive(1);
|
||||
|
||||
@ -522,6 +526,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
std::cerr << "p3ConnectMgr::netUpnpCheck() disabling stunkeepalive() cos uPnP" << std::endl;
|
||||
#endif
|
||||
tou_stunkeepalive(0);
|
||||
mStunMoreRequired = false; /* only need to validate address (UPNP) */
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
}
|
||||
@ -532,15 +537,13 @@ void p3ConnectMgr::netUdpCheck()
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl;
|
||||
#endif
|
||||
if (stunCheck() || (mUpnpAddrValid))
|
||||
if (udpExtAddressCheck() || (mUpnpAddrValid))
|
||||
{
|
||||
bool extValid = false;
|
||||
bool extAddrStable = false;
|
||||
struct sockaddr_in extAddr;
|
||||
uint32_t mode = 0;
|
||||
|
||||
|
||||
|
||||
connMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
mNetStatus = RS_NET_DONE;
|
||||
@ -588,6 +591,30 @@ void p3ConnectMgr::netUdpCheck()
|
||||
ownState.netMode &= ~(RS_NET_MODE_ACTUAL);
|
||||
ownState.netMode |= RS_NET_MODE_UNREACHABLE;
|
||||
tou_stunkeepalive(0);
|
||||
mStunMoreRequired = false; /* no point -> unreachable (EXT) */
|
||||
|
||||
/* send a system warning message */
|
||||
if (rsNotify)
|
||||
{
|
||||
std::string title =
|
||||
"Warning: Bad Firewall Configuration";
|
||||
|
||||
std::string msg;
|
||||
msg += " **** WARNING **** \n";
|
||||
msg += "Retroshare has detected that you are behind";
|
||||
msg += " a restrictive Firewall\n";
|
||||
msg += "\n";
|
||||
msg += "You cannot connect to other firewalled peers\n";
|
||||
msg += "\n";
|
||||
msg += "You can fix this by:\n";
|
||||
msg += " (1) opening an External Port\n";
|
||||
msg += " (2) enabling UPnP, or\n";
|
||||
msg += " (3) get a new (approved) Firewall/Router\n";
|
||||
|
||||
rsNotify->AddSysMessage(0, RS_SYS_WARNING,
|
||||
title, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
@ -771,6 +798,8 @@ void p3ConnectMgr::stunInit()
|
||||
mDhtMgr->addStun(*it);
|
||||
}
|
||||
mStunStatus = RS_STUN_DHT;
|
||||
mStunFound = 0;
|
||||
mStunMoreRequired = true;
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
}
|
||||
@ -778,13 +807,30 @@ void p3ConnectMgr::stunInit()
|
||||
bool p3ConnectMgr::stunCheck()
|
||||
{
|
||||
/* check if we've got a Stun result */
|
||||
bool stunOk = false;
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::stunCheck()" << std::endl;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(connMtx); /********* LOCK STACK MUTEX ******/
|
||||
|
||||
if (udpExtAddressCheck())
|
||||
/* if DONE -> return */
|
||||
if (mStunStatus == RS_STUN_DONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mStunFound >= RS_STUN_FOUND_MIN)
|
||||
{
|
||||
mStunMoreRequired = false;
|
||||
}
|
||||
stunOk = (!mStunMoreRequired);
|
||||
}
|
||||
|
||||
|
||||
if (udpExtAddressCheck() && (stunOk))
|
||||
{
|
||||
/* set external UDP address */
|
||||
mDhtMgr->doneStun();
|
||||
@ -818,12 +864,16 @@ void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in raddr, uint3
|
||||
{
|
||||
if (stillStunning)
|
||||
{
|
||||
connMtx.lock(); /* LOCK MUTEX */
|
||||
mStunFound++;
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::stunStatus() Sending to UDP" << std::endl;
|
||||
#endif
|
||||
/* push to the UDP */
|
||||
udpStunPeer(id, raddr);
|
||||
|
||||
}
|
||||
|
||||
/* push to the stunCollect */
|
||||
@ -862,8 +912,7 @@ void p3ConnectMgr::stunCollect(std::string id, struct sockaddr_in addr, uint32_t
|
||||
/* add it in:
|
||||
* if FRIEND / ONLINE or if list is short.
|
||||
*/
|
||||
if ((flags & RS_STUN_ONLINE) || (flags & RS_STUN_FRIEND)
|
||||
|| (mStunList.size() < RS_STUN_LIST_MIN))
|
||||
if ((flags & RS_STUN_ONLINE) || (flags & RS_STUN_FRIEND))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::stunCollect() Id added to Front" << std::endl;
|
||||
@ -871,6 +920,16 @@ void p3ConnectMgr::stunCollect(std::string id, struct sockaddr_in addr, uint32_t
|
||||
/* push to the front */
|
||||
mStunList.push_front(id);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
else if (mStunList.size() < RS_STUN_LIST_MIN)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::stunCollect() Id added to Back" << std::endl;
|
||||
#endif
|
||||
/* push to the front */
|
||||
mStunList.push_back(id);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
}
|
||||
@ -989,6 +1048,15 @@ void p3ConnectMgr::tickMonitors()
|
||||
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* notify GUI */
|
||||
if ((peer.actions & RS_PEER_CONNECTED) &&
|
||||
(rsNotify))
|
||||
{
|
||||
rsNotify->AddPopupMessage(RS_POPUP_CONNECT,
|
||||
peer.id, "Peer Online: ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/* do the Others as well! */
|
||||
@ -1230,7 +1298,7 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
|
||||
std::cerr << "p3ConnectMgr::connectResult() Success: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " Success: " << success;
|
||||
@ -2703,14 +2771,17 @@ void printConnectState(peerConnectState &peer)
|
||||
bool p3ConnectMgr::addBootstrapStunPeers()
|
||||
{
|
||||
std::string id;
|
||||
struct sockaddr_in dummyaddr;
|
||||
uint32_t flags = 0;
|
||||
|
||||
// Two Defaults for The Initial Release.
|
||||
id = "7ad672ea4d4af8560d5230aff3c88b59";
|
||||
mStunList.push_back(RsUtil::HashId(id, false));
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
id = "8ad7c08e7778e0289de04843bf57a6ae";
|
||||
mStunList.push_back(RsUtil::HashId(id, false));
|
||||
stunCollect(RsUtil::HashId(id, false), dummyaddr, flags);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,7 +287,11 @@ private:
|
||||
|
||||
time_t mNetInitTS;
|
||||
uint32_t mNetStatus;
|
||||
|
||||
uint32_t mStunStatus;
|
||||
uint32_t mStunFound;
|
||||
bool mStunMoreRequired;
|
||||
|
||||
bool mStatusChanged;
|
||||
|
||||
std::list<pqiMonitor *> clients;
|
||||
|
@ -391,6 +391,8 @@ void p3DhtMgr::run()
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::run() state = ACTIVE -> do stuff" << std::endl;
|
||||
#endif
|
||||
doStun();
|
||||
|
||||
period = checkOwnDHTKeys();
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::run() checkOwnDHTKeys() period: " << period << std::endl;
|
||||
@ -792,18 +794,38 @@ int p3DhtMgr::checkNotifyDHT()
|
||||
|
||||
int p3DhtMgr::doStun()
|
||||
{
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::doStun()" << std::endl;
|
||||
#endif
|
||||
if (stunIds.size() < 1)
|
||||
{
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::doStun() Failed -> no Ids left" << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
bool stunRequired = mStunRequired;
|
||||
|
||||
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
/* now loop through the peers */
|
||||
if (!stunRequired)
|
||||
{
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::doStun() not Required" << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* pop the front one */
|
||||
std::string activeStunId = stunIds.front();
|
||||
|
||||
stunIds.pop_front();
|
||||
/* Don't recycle -> otherwise can end in an infinite (pointless) loop! */
|
||||
//stunIds.push_back(activeStunId);
|
||||
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::doStun() STUN: " << RsUtil::BinToHex(activeStunId);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* look it up! */
|
||||
dhtSearch(activeStunId, DHT_MODE_SEARCH);
|
||||
|
76
libretroshare/src/rsiface/rsnotify.h
Normal file
76
libretroshare/src/rsiface/rsnotify.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef RS_NOTIFY_GUI_INTERFACE_H
|
||||
#define RS_NOTIFY_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsnotify.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <map>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
class RsNotify;
|
||||
extern RsNotify *rsNotify;
|
||||
|
||||
const uint32_t RS_SYS_ERROR = 0x0001;
|
||||
const uint32_t RS_SYS_WARNING = 0x0002;
|
||||
const uint32_t RS_SYS_INFO = 0x0004;
|
||||
|
||||
const uint32_t RS_POPUP_MSG = 0x0001;
|
||||
const uint32_t RS_POPUP_CHAT = 0x0002;
|
||||
const uint32_t RS_POPUP_CALL = 0x0004;
|
||||
const uint32_t RS_POPUP_CONNECT = 0x0008;
|
||||
|
||||
|
||||
class RsNotify
|
||||
{
|
||||
public:
|
||||
|
||||
RsNotify() { return; }
|
||||
virtual ~RsNotify() { return; }
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
virtual bool NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg) = 0;
|
||||
virtual bool NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &msg) = 0;
|
||||
|
||||
/* Control over Messages */
|
||||
virtual bool GetSysMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
virtual bool GetPopupMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
|
||||
virtual bool SetSysMessageMode(uint32_t sysid, uint32_t mode) = 0;
|
||||
virtual bool SetPopupMessageMode(uint32_t ptype, uint32_t mode) = 0;
|
||||
|
||||
/* Input from libretroshare */
|
||||
virtual bool AddPopupMessage(uint32_t ptype, std::string name, std::string msg) = 0;
|
||||
virtual bool AddSysMessage(uint32_t sysid, uint32_t type,
|
||||
std::string title, std::string msg) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -11,6 +11,7 @@ RSOBJ = p3peers.o \
|
||||
p3rank.o \
|
||||
p3photo.o \
|
||||
p3msgs.o \
|
||||
p3notify.o \
|
||||
p3discovery.o \
|
||||
p3face-file.o \
|
||||
p3face-server.o \
|
||||
|
@ -58,6 +58,7 @@
|
||||
|
||||
/* Implemented Rs Interfaces */
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/p3notify.h"
|
||||
#include "rsserver/p3peers.h"
|
||||
#include "rsserver/p3rank.h"
|
||||
#include "rsserver/p3msgs.h"
|
||||
@ -482,6 +483,9 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
/* setup classes / structures */
|
||||
/**************************************************************************/
|
||||
|
||||
/* Setup Notify Early - So we can use it. */
|
||||
rsNotify = new p3Notify();
|
||||
|
||||
mConnMgr = new p3ConnectMgr(mAuthMgr);
|
||||
p3UpnpMgr *mUpnpMgr = new upnphandler();
|
||||
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, config->basedir);
|
||||
@ -675,6 +679,7 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
rsDisc = new p3Discovery(ad);
|
||||
rsPhoto = new p3Photo(photoService);
|
||||
|
||||
|
||||
/* put a welcome message in! */
|
||||
if (config->firsttime_run)
|
||||
{
|
||||
|
129
libretroshare/src/rsserver/p3notify.cc
Normal file
129
libretroshare/src/rsserver/p3notify.cc
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* libretroshare/src/rsserver: p3notify.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 "rsserver/p3notify.h"
|
||||
|
||||
/* external reference point */
|
||||
RsNotify *rsNotify = NULL;
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
bool p3Notify::NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg)
|
||||
{
|
||||
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
||||
if (pendingSysMsgs.size() > 0)
|
||||
{
|
||||
p3NotifySysMsg smsg = pendingSysMsgs.front();
|
||||
pendingSysMsgs.pop_front();
|
||||
|
||||
sysid = smsg.sysid;
|
||||
type = smsg.type;
|
||||
title = smsg.title;
|
||||
msg = smsg.msg;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool p3Notify::NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &msg)
|
||||
{
|
||||
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
||||
if (pendingPopupMsgs.size() > 0)
|
||||
{
|
||||
p3NotifyPopupMsg pmsg = pendingPopupMsgs.front();
|
||||
pendingPopupMsgs.pop_front();
|
||||
|
||||
ptype = pmsg.type;
|
||||
name = pmsg.name;
|
||||
msg = pmsg.msg;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Control over Messages */
|
||||
bool p3Notify::GetSysMessageList(std::map<uint32_t, std::string> &list)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3Notify::GetPopupMessageList(std::map<uint32_t, std::string> &list)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool p3Notify::SetSysMessageMode(uint32_t sysid, uint32_t mode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3Notify::SetPopupMessageMode(uint32_t ptype, uint32_t mode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Input from libretroshare */
|
||||
bool p3Notify::AddPopupMessage(uint32_t ptype, std::string name, std::string msg)
|
||||
{
|
||||
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
||||
|
||||
p3NotifyPopupMsg pmsg;
|
||||
|
||||
pmsg.type = ptype;
|
||||
pmsg.name = name;
|
||||
pmsg.msg = msg;
|
||||
|
||||
pendingPopupMsgs.push_back(pmsg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Notify::AddSysMessage(uint32_t sysid, uint32_t type,
|
||||
std::string title, std::string msg)
|
||||
{
|
||||
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
||||
|
||||
p3NotifySysMsg smsg;
|
||||
|
||||
smsg.sysid = sysid;
|
||||
smsg.type = type;
|
||||
smsg.title = title;
|
||||
smsg.msg = msg;
|
||||
|
||||
pendingSysMsgs.push_back(smsg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
85
libretroshare/src/rsserver/p3notify.h
Normal file
85
libretroshare/src/rsserver/p3notify.h
Normal file
@ -0,0 +1,85 @@
|
||||
#ifndef RS_P3_NOTIFY_INTERFACE_H
|
||||
#define RS_P3_NOTIFY_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsserver: p3notify.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 "rsiface/rsnotify.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
class p3NotifySysMsg
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t sysid;
|
||||
uint32_t type;
|
||||
std::string title;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
class p3NotifyPopupMsg
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t type;
|
||||
std::string name;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
class p3Notify: public RsNotify
|
||||
{
|
||||
public:
|
||||
|
||||
p3Notify() { return; }
|
||||
virtual ~p3Notify() { return; }
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
virtual bool NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg);
|
||||
virtual bool NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &msg);
|
||||
|
||||
/* Control over Messages */
|
||||
virtual bool GetSysMessageList(std::map<uint32_t, std::string> &list);
|
||||
virtual bool GetPopupMessageList(std::map<uint32_t, std::string> &list);
|
||||
|
||||
virtual bool SetSysMessageMode(uint32_t sysid, uint32_t mode);
|
||||
virtual bool SetPopupMessageMode(uint32_t ptype, uint32_t mode);
|
||||
|
||||
/* Input from libretroshare */
|
||||
virtual bool AddPopupMessage(uint32_t ptype, std::string name, std::string msg);
|
||||
virtual bool AddSysMessage(uint32_t sysid, uint32_t type,
|
||||
std::string title, std::string msg);
|
||||
|
||||
private:
|
||||
|
||||
RsMutex noteMtx;
|
||||
|
||||
std::list<p3NotifySysMsg> pendingSysMsgs;
|
||||
std::list<p3NotifyPopupMsg> pendingPopupMsgs;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -30,6 +30,7 @@
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "services/p3msgservice.h"
|
||||
#include "rsiface/rsnotify.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
@ -141,7 +142,13 @@ int p3MsgService::incomingMsgs()
|
||||
/* from a peer */
|
||||
MsgInfoSummary mis;
|
||||
initRsMIS(mi, mis);
|
||||
msgNotifications.push_back(mis);
|
||||
|
||||
// msgNotifications.push_back(mis);
|
||||
if (rsNotify)
|
||||
{
|
||||
rsNotify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(),
|
||||
"New Message from: ");
|
||||
}
|
||||
}
|
||||
|
||||
imsg[mi->msgId] = mi;
|
||||
|
@ -653,8 +653,6 @@ bool UdpSorter::locked_recvdStun(const struct sockaddr_in &remote, const stru
|
||||
std::cerr << out.str() << std::endl;
|
||||
#endif
|
||||
|
||||
locked_printStunList();
|
||||
|
||||
bool found = true;
|
||||
std::list<TouStunPeer>::iterator it;
|
||||
for(it = mStunList.begin(); it != mStunList.end(); it++)
|
||||
@ -671,6 +669,8 @@ bool UdpSorter::locked_recvdStun(const struct sockaddr_in &remote, const stru
|
||||
}
|
||||
}
|
||||
|
||||
locked_printStunList();
|
||||
|
||||
if (!eaddrKnown)
|
||||
{
|
||||
locked_checkExternalAddress();
|
||||
|
@ -1,5 +1,7 @@
|
||||
|
||||
#include "rsiface/notifyqt.h"
|
||||
#include "rsiface/rsnotify.h"
|
||||
#include "rsiface/rspeers.h"
|
||||
|
||||
#include "gui/NetworkDialog.h"
|
||||
#include "gui/PeersDialog.h"
|
||||
@ -10,6 +12,10 @@
|
||||
#include "gui/ChannelsDialog.h"
|
||||
#include "gui/MessengerWindow.h"
|
||||
|
||||
#include "gui/toaster/MessageToaster.h"
|
||||
#include "gui/toaster/ChatToaster.h"
|
||||
#include "gui/toaster/CallToaster.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@ -158,9 +164,79 @@ static time_t lastTs = 0;
|
||||
displayConfig();
|
||||
*/
|
||||
|
||||
/* Finally Check for PopupMessages / System Error Messages */
|
||||
|
||||
if (rsNotify)
|
||||
{
|
||||
uint32_t sysid;
|
||||
uint32_t type;
|
||||
std::string title, id, msg;
|
||||
|
||||
if (rsNotify->NotifyPopupMessage(type, id, msg))
|
||||
{
|
||||
/* id the name */
|
||||
std::string name = rsPeers->getPeerName(id);
|
||||
std::string realmsg = msg + name;
|
||||
switch(type)
|
||||
{
|
||||
case RS_POPUP_MSG:
|
||||
{
|
||||
MessageToaster * msgToaster = new MessageToaster();
|
||||
msgToaster->setMessage(QString::fromStdString(realmsg));
|
||||
msgToaster->show();
|
||||
break;
|
||||
}
|
||||
case RS_POPUP_CHAT:
|
||||
{
|
||||
ChatToaster * chatToaster = new ChatToaster();
|
||||
chatToaster->setMessage(QString::fromStdString(realmsg));
|
||||
chatToaster->show();
|
||||
break;
|
||||
}
|
||||
case RS_POPUP_CALL:
|
||||
{
|
||||
CallToaster * callToaster = new CallToaster();
|
||||
callToaster->setMessage(QString::fromStdString(realmsg));
|
||||
callToaster->show();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case RS_POPUP_CONNECT:
|
||||
{
|
||||
MessageToaster * msgToaster = new MessageToaster();
|
||||
msgToaster->setMessage(QString::fromStdString(realmsg));
|
||||
msgToaster->show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (rsNotify->NotifySysMessage(sysid, type, title, msg))
|
||||
{
|
||||
/* make a warning message */
|
||||
switch(type)
|
||||
{
|
||||
case RS_SYS_ERROR:
|
||||
QMessageBox::critical(0,
|
||||
QString::fromStdString(title),
|
||||
QString::fromStdString(msg));
|
||||
break;
|
||||
case RS_SYS_WARNING:
|
||||
QMessageBox::warning(0,
|
||||
QString::fromStdString(title),
|
||||
QString::fromStdString(msg));
|
||||
break;
|
||||
default:
|
||||
case RS_SYS_INFO:
|
||||
QMessageBox::information(0,
|
||||
QString::fromStdString(title),
|
||||
QString::fromStdString(msg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void NotifyQt::displayNeighbours()
|
||||
|
76
retroshare-gui/src/rsiface/rsnotify.h
Normal file
76
retroshare-gui/src/rsiface/rsnotify.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef RS_NOTIFY_GUI_INTERFACE_H
|
||||
#define RS_NOTIFY_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsnotify.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <map>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
class RsNotify;
|
||||
extern RsNotify *rsNotify;
|
||||
|
||||
const uint32_t RS_SYS_ERROR = 0x0001;
|
||||
const uint32_t RS_SYS_WARNING = 0x0002;
|
||||
const uint32_t RS_SYS_INFO = 0x0004;
|
||||
|
||||
const uint32_t RS_POPUP_MSG = 0x0001;
|
||||
const uint32_t RS_POPUP_CHAT = 0x0002;
|
||||
const uint32_t RS_POPUP_CALL = 0x0004;
|
||||
const uint32_t RS_POPUP_CONNECT = 0x0008;
|
||||
|
||||
|
||||
class RsNotify
|
||||
{
|
||||
public:
|
||||
|
||||
RsNotify() { return; }
|
||||
virtual ~RsNotify() { return; }
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
virtual bool NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg) = 0;
|
||||
virtual bool NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &msg) = 0;
|
||||
|
||||
/* Control over Messages */
|
||||
virtual bool GetSysMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
virtual bool GetPopupMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
|
||||
virtual bool SetSysMessageMode(uint32_t sysid, uint32_t mode) = 0;
|
||||
virtual bool SetPopupMessageMode(uint32_t ptype, uint32_t mode) = 0;
|
||||
|
||||
/* Input from libretroshare */
|
||||
virtual bool AddPopupMessage(uint32_t ptype, std::string name, std::string msg) = 0;
|
||||
virtual bool AddSysMessage(uint32_t sysid, uint32_t type,
|
||||
std::string title, std::string msg) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user