mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 15:39:27 -05:00
* Added rstlvimage.cc to serialiser (missed in other checkin).
* Added Forum ID to configuration Manager. * added proper startup for p3Forums. * updated forums/distrib interfaces. * Switch Auto-Login on by default. * switched out lots of debugging. * add RM libretroshare.a to top-level Makefile. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@594 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
14dac82c85
commit
fe284b628a
@ -1,5 +1,7 @@
|
|||||||
# FLTKGUI is not required for the Qt4,0 gui.
|
RS_TOP_DIR = .
|
||||||
#
|
###############################################################
|
||||||
|
include $(RS_TOP_DIR)/scripts/config.mk
|
||||||
|
###############################################################
|
||||||
|
|
||||||
all: librs tests
|
all: librs tests
|
||||||
|
|
||||||
@ -55,4 +57,5 @@ clobber:
|
|||||||
make -C server clobber
|
make -C server clobber
|
||||||
make -C rsserver clobber
|
make -C rsserver clobber
|
||||||
make -C rsiface clobber
|
make -C rsiface clobber
|
||||||
|
-$(RM) lib/libretroshare.a
|
||||||
|
|
||||||
|
@ -36,7 +36,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
#define FIM_DEBUG 1
|
/***********
|
||||||
|
* #define FIM_DEBUG 1
|
||||||
|
***********/
|
||||||
|
|
||||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid)
|
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid)
|
||||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
||||||
@ -62,7 +64,9 @@ bool FileIndexMonitor::findLocalFile(std::string hash,
|
|||||||
|
|
||||||
fiMutex.lock(); { /* LOCKED DIRS */
|
fiMutex.lock(); { /* LOCKED DIRS */
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile() Hash: " << hash << std::endl;
|
std::cerr << "FileIndexMonitor::findLocalFile() Hash: " << hash << std::endl;
|
||||||
|
#endif
|
||||||
/* search through the fileIndex */
|
/* search through the fileIndex */
|
||||||
fi.searchHash(hash, results);
|
fi.searchHash(hash, results);
|
||||||
if (results.size() > 0)
|
if (results.size() > 0)
|
||||||
@ -71,7 +75,9 @@ bool FileIndexMonitor::findLocalFile(std::string hash,
|
|||||||
FileEntry *fe = results.front();
|
FileEntry *fe = results.front();
|
||||||
DirEntry *de = fe->parent; /* all files must have a valid parent! */
|
DirEntry *de = fe->parent; /* all files must have a valid parent! */
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
|
std::cerr << "FileIndexMonitor::findLocalFile() Found Name: " << fe->name << std::endl;
|
||||||
|
#endif
|
||||||
std::string shpath = RsDirUtil::removeRootDir(de->path);
|
std::string shpath = RsDirUtil::removeRootDir(de->path);
|
||||||
std::string basedir = RsDirUtil::getRootDir(de->path);
|
std::string basedir = RsDirUtil::getRootDir(de->path);
|
||||||
std::string realroot = findRealRoot(basedir);
|
std::string realroot = findRealRoot(basedir);
|
||||||
@ -89,8 +95,10 @@ bool FileIndexMonitor::findLocalFile(std::string hash,
|
|||||||
size = fe->size;
|
size = fe->size;
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile() Found Path: " << fullpath << std::endl;
|
std::cerr << "FileIndexMonitor::findLocalFile() Found Path: " << fullpath << std::endl;
|
||||||
std::cerr << "FileIndexMonitor::findLocalFile() Found Size: " << size << std::endl;
|
std::cerr << "FileIndexMonitor::findLocalFile() Found Size: " << size << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +113,9 @@ bool FileIndexMonitor::convertSharedFilePath(std::string path, std::string &f
|
|||||||
|
|
||||||
fiMutex.lock(); { /* LOCKED DIRS */
|
fiMutex.lock(); { /* LOCKED DIRS */
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::convertSharedFilePath() path: " << path << std::endl;
|
std::cerr << "FileIndexMonitor::convertSharedFilePath() path: " << path << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string shpath = RsDirUtil::removeRootDir(path);
|
std::string shpath = RsDirUtil::removeRootDir(path);
|
||||||
std::string basedir = RsDirUtil::getRootDir(path);
|
std::string basedir = RsDirUtil::getRootDir(path);
|
||||||
@ -116,7 +126,9 @@ bool FileIndexMonitor::convertSharedFilePath(std::string path, std::string &f
|
|||||||
{
|
{
|
||||||
fullpath = realroot + "/";
|
fullpath = realroot + "/";
|
||||||
fullpath += shpath;
|
fullpath += shpath;
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::convertSharedFilePath() Found Path: " << fullpath << std::endl;
|
std::cerr << "FileIndexMonitor::convertSharedFilePath() Found Path: " << fullpath << std::endl;
|
||||||
|
#endif
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,13 +150,17 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
|||||||
if ((ok = fi.loadIndex(data.path + '/' + data.name,
|
if ((ok = fi.loadIndex(data.path + '/' + data.name,
|
||||||
data.hash, data.size)))
|
data.hash, data.size)))
|
||||||
{
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::loadCache() Success!";
|
std::cerr << "FileIndexMonitor::loadCache() Success!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::loadCache() Failed!";
|
std::cerr << "FileIndexMonitor::loadCache() Failed!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
@ -273,6 +289,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::updateCycle()";
|
std::cerr << "FileIndexMonitor::updateCycle()";
|
||||||
std::cerr << " RealPath: " << realpath << std::endl;
|
std::cerr << " RealPath: " << realpath << std::endl;
|
||||||
@ -282,8 +299,10 @@ void FileIndexMonitor::updateCycle()
|
|||||||
DIR *dir = opendir(realpath.c_str());
|
DIR *dir = opendir(realpath.c_str());
|
||||||
if (!dir)
|
if (!dir)
|
||||||
{
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "FileIndexMonitor::updateCycle()";
|
std::cerr << "FileIndexMonitor::updateCycle()";
|
||||||
std::cerr << " Missing Dir: " << realpath << std::endl;
|
std::cerr << " Missing Dir: " << realpath << std::endl;
|
||||||
|
#endif
|
||||||
/* bad directory - delete */
|
/* bad directory - delete */
|
||||||
if (!fi.removeOldDirectory(olddir->parent->path, olddir->name, stamp))
|
if (!fi.removeOldDirectory(olddir->parent->path, olddir->name, stamp))
|
||||||
{
|
{
|
||||||
@ -433,10 +452,13 @@ void FileIndexMonitor::updateCycle()
|
|||||||
|
|
||||||
if (filesToHash.size() > 0)
|
if (filesToHash.size() > 0)
|
||||||
{
|
{
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "List of Files to rehash in: " << dirpath << std::endl;
|
std::cerr << "List of Files to rehash in: " << dirpath << std::endl;
|
||||||
|
#endif
|
||||||
fiMods = true;
|
fiMods = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
||||||
{
|
{
|
||||||
std::cerr << "\t" << hit->name << std::endl;
|
std::cerr << "\t" << hit->name << std::endl;
|
||||||
@ -446,6 +468,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
{
|
{
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* update files */
|
/* update files */
|
||||||
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
||||||
@ -703,7 +726,9 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
|
|||||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||||
unsigned char gblBuf[512];
|
unsigned char gblBuf[512];
|
||||||
|
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "File to hash = " << f_hash << std::endl;
|
std::cerr << "File to hash = " << f_hash << std::endl;
|
||||||
|
#endif
|
||||||
if (NULL == (fd = fopen(f_hash.c_str(), "rb"))) return false;
|
if (NULL == (fd = fopen(f_hash.c_str(), "rb"))) return false;
|
||||||
|
|
||||||
SHA1_Init(sha_ctx);
|
SHA1_Init(sha_ctx);
|
||||||
|
@ -65,8 +65,11 @@ const uint32_t CONFIG_TYPE_MSGS = 0x0004;
|
|||||||
const uint32_t CONFIG_TYPE_CACHE = 0x0005;
|
const uint32_t CONFIG_TYPE_CACHE = 0x0005;
|
||||||
|
|
||||||
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
const uint32_t CONFIG_TYPE_RANK_LINK = 0x0011;
|
||||||
|
|
||||||
const uint32_t CONFIG_TYPE_QBLOG = 0x0012;
|
const uint32_t CONFIG_TYPE_QBLOG = 0x0012;
|
||||||
|
|
||||||
|
const uint32_t CONFIG_TYPE_FORUMS = 0x0013;
|
||||||
|
|
||||||
class p3ConfigMgr;
|
class p3ConfigMgr;
|
||||||
class p3AuthMgr;
|
class p3AuthMgr;
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ const uint32_t MAX_UPNP_INIT = 10; /* seconds UPnP timeout */
|
|||||||
* #define P3CONNMGR_NO_AUTO_CONNECTION 1
|
* #define P3CONNMGR_NO_AUTO_CONNECTION 1
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#define CONN_DEBUG 1
|
|
||||||
|
|
||||||
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||||
const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
|
const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
|
||||||
|
@ -574,17 +574,17 @@ int pqihandler::UpdateRates()
|
|||||||
extra_bw_out += crate_out - avg_rate_out;
|
extra_bw_out += crate_out - avg_rate_out;
|
||||||
}
|
}
|
||||||
//std::cerr << "\tSM(" << mod -> smi << ")";
|
//std::cerr << "\tSM(" << mod -> smi << ")";
|
||||||
std::cerr << "In A: " << mod -> pqi -> getMaxRate(true);
|
//std::cerr << "In A: " << mod -> pqi -> getMaxRate(true);
|
||||||
std::cerr << " C: " << crate_in;
|
//std::cerr << " C: " << crate_in;
|
||||||
std::cerr << " && Out A: " << mod -> pqi -> getMaxRate(false);
|
//std::cerr << " && Out A: " << mod -> pqi -> getMaxRate(false);
|
||||||
std::cerr << " C: " << crate_out << std::endl;
|
//std::cerr << " C: " << crate_out << std::endl;
|
||||||
}
|
}
|
||||||
std::cerr << "Totals (In) Used B/W " << used_bw_in;
|
//std::cerr << "Totals (In) Used B/W " << used_bw_in;
|
||||||
std::cerr << " Excess B/W " << extra_bw_in;
|
//std::cerr << " Excess B/W " << extra_bw_in;
|
||||||
std::cerr << " Available B/W " << avail_in << std::endl;
|
//std::cerr << " Available B/W " << avail_in << std::endl;
|
||||||
std::cerr << "Totals (Out) Used B/W " << used_bw_out;
|
//std::cerr << "Totals (Out) Used B/W " << used_bw_out;
|
||||||
std::cerr << " Excess B/W " << extra_bw_out;
|
//std::cerr << " Excess B/W " << extra_bw_out;
|
||||||
std::cerr << " Available B/W " << avail_out << std::endl;
|
//std::cerr << " Available B/W " << avail_out << std::endl;
|
||||||
|
|
||||||
StoreCurrentRates(used_bw_in, used_bw_out);
|
StoreCurrentRates(used_bw_in, used_bw_out);
|
||||||
|
|
||||||
|
46
libretroshare/src/rsiface/rsdistrib.h
Normal file
46
libretroshare/src/rsiface/rsdistrib.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef RS_DISTRIB_GUI_INTERFACE_H
|
||||||
|
#define RS_DISTRIB_GUI_INTERFACE_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/rsiface: rsdistrib.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".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define RS_DISTRIB_PRIVACY_MASK 0x000f /* who can publish & view */
|
||||||
|
#define RS_DISTRIB_AUTHEN_MASK 0x00f0 /* how to publish */
|
||||||
|
#define RS_DISTRIB_LISTEN_MASK 0x0f00 /* distribution flags */
|
||||||
|
|
||||||
|
#define RS_DISTRIB_PUBLIC 0x0001 /* anyone can publish */
|
||||||
|
#define RS_DISTRIB_PRIVATE 0x0002 /* anyone with key can publish */
|
||||||
|
#define RS_DISTRIB_ENCRYPTED 0x0004 /* need publish key to view */
|
||||||
|
|
||||||
|
#define RS_DISTRIB_AUTHEN_REQ 0x0010 /* you must sign messages */
|
||||||
|
#define RS_DISTRIB_AUTHEN_ANON 0x0020 /* you can send anonymous messages */
|
||||||
|
|
||||||
|
#define RS_DISTRIB_ADMIN 0x0100
|
||||||
|
#define RS_DISTRIB_PUBLISH 0x0200
|
||||||
|
#define RS_DISTRIB_SUBSCRIBED 0x0400
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -32,17 +32,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "rsiface/rstypes.h"
|
#include "rsiface/rstypes.h"
|
||||||
|
#include "rsiface/rsdistrib.h" /* For FLAGS */
|
||||||
#define RS_FORUM_PUBLIC 0x0001 /* anyone can publish */
|
|
||||||
#define RS_FORUM_PRIVATE 0x0002 /* anyone with key can publish */
|
|
||||||
#define RS_FORUM_ENCRYPTED 0x0004 /* need admin key */
|
|
||||||
|
|
||||||
#define RS_FORUM_MSG_AUTH 0x0010 /* you must sign messages */
|
|
||||||
#define RS_FORUM_MSG_ANON 0x0020 /* you can send anonymous messages */
|
|
||||||
|
|
||||||
#define RS_FORUM_ADMIN 0x0100 /* anyone can publish */
|
|
||||||
#define RS_FORUM_SUBSCRIBED 0x0200 /* anyone can publish */
|
|
||||||
|
|
||||||
|
|
||||||
class ForumInfo
|
class ForumInfo
|
||||||
{
|
{
|
||||||
@ -123,6 +113,7 @@ virtual bool getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg
|
|||||||
|
|
||||||
virtual bool ForumMessageSend(ForumMsgInfo &info) = 0;
|
virtual bool ForumMessageSend(ForumMsgInfo &info) = 0;
|
||||||
|
|
||||||
|
virtual bool forumSubscribe(std::string fId, bool subscribe) = 0;
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -134,7 +134,7 @@ RsInit *InitRsConfig()
|
|||||||
strcpy(config->inet, "127.0.0.1");
|
strcpy(config->inet, "127.0.0.1");
|
||||||
strcpy(config->logfname, "");
|
strcpy(config->logfname, "");
|
||||||
|
|
||||||
config -> autoLogin = false;
|
config -> autoLogin = true; // Always on now.
|
||||||
config -> passwd = "";
|
config -> passwd = "";
|
||||||
config -> havePasswd = false;
|
config -> havePasswd = false;
|
||||||
config -> haveDebugLevel = false;
|
config -> haveDebugLevel = false;
|
||||||
@ -592,15 +592,20 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
|
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
|
||||||
mCacheStrapper -> addCachePair(cp3);
|
mCacheStrapper -> addCachePair(cp3);
|
||||||
|
|
||||||
|
p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
|
||||||
|
mCacheStrapper, mCacheTransfer,
|
||||||
|
localcachedir, remotecachedir);
|
||||||
|
|
||||||
|
CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0));
|
||||||
|
mCacheStrapper -> addCachePair(cp4);
|
||||||
|
pqih -> addService(mForums); /* This must be also ticked as a service */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
mRanking = NULL;
|
mRanking = NULL;
|
||||||
mQBlog = NULL;
|
mQBlog = NULL;
|
||||||
|
mForums = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
mConnMgr->setDhtMgr(mDhtMgr);
|
mConnMgr->setDhtMgr(mDhtMgr);
|
||||||
@ -624,6 +629,7 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
#ifndef RS_RELEASE
|
#ifndef RS_RELEASE
|
||||||
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
||||||
mConfigMgr->addConfiguration("qblog.cfg", mQblog);
|
mConfigMgr->addConfiguration("qblog.cfg", mQblog);
|
||||||
|
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@ -751,7 +757,7 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
rsGameLauncher = gameLauncher;
|
rsGameLauncher = gameLauncher;
|
||||||
rsPhoto = new p3Photo(photoService);
|
rsPhoto = new p3Photo(photoService);
|
||||||
rsRanks = new p3Rank(mRanking);
|
rsRanks = new p3Rank(mRanking);
|
||||||
rsForums = new p3Forums();
|
rsForums = mForums;
|
||||||
rsStatus = new p3Status();
|
rsStatus = new p3Status();
|
||||||
rsQblog = new p3Blog(mQblog);
|
rsQblog = new p3Blog(mQblog);
|
||||||
|
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
RsPeers *rsPeers = NULL;
|
RsPeers *rsPeers = NULL;
|
||||||
|
|
||||||
|
/*******
|
||||||
|
* #define P3PEERS_DEBUG 1
|
||||||
|
*******/
|
||||||
|
|
||||||
static uint32_t RsPeerTranslateTrust(uint32_t trustLvl);
|
static uint32_t RsPeerTranslateTrust(uint32_t trustLvl);
|
||||||
int ensureExtension(std::string &name, std::string def_ext);
|
int ensureExtension(std::string &name, std::string def_ext);
|
||||||
|
|
||||||
@ -115,7 +119,6 @@ std::string RsPeerLastConnectString(uint32_t lastConnect)
|
|||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define P3PEERS_DEBUG 1
|
|
||||||
|
|
||||||
p3Peers::p3Peers(p3ConnectMgr *cm, p3AuthMgr *am)
|
p3Peers::p3Peers(p3ConnectMgr *cm, p3AuthMgr *am)
|
||||||
:mConnMgr(cm), mAuthMgr(am)
|
:mConnMgr(cm), mAuthMgr(am)
|
||||||
|
136
libretroshare/src/serialiser/rstlvimage.cc
Normal file
136
libretroshare/src/serialiser/rstlvimage.cc
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: rstlvfileitem.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* 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 <iostream>
|
||||||
|
|
||||||
|
#include "serialiser/rstlvbase.h"
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rsbaseserial.h"
|
||||||
|
|
||||||
|
/***
|
||||||
|
* #define TLV_FI_DEBUG 1
|
||||||
|
**/
|
||||||
|
|
||||||
|
/************************************* RsTlvImage ************************************/
|
||||||
|
|
||||||
|
RsTlvImage::RsTlvImage()
|
||||||
|
:RsTlvItem(), image_type(0), binData(TLV_TYPE_BIN_IMAGE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsTlvImage::TlvClear()
|
||||||
|
{
|
||||||
|
image_type = 0;
|
||||||
|
binData.TlvClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t RsTlvImage::TlvSize()
|
||||||
|
{
|
||||||
|
uint32_t s = 4; /* header */
|
||||||
|
|
||||||
|
/* collect sizes for both uInts and data length */
|
||||||
|
s+= 4;
|
||||||
|
s+= binData.TlvSize();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RsTlvImage::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||||
|
{
|
||||||
|
/* must check sizes */
|
||||||
|
uint16_t tlvsize = TlvSize();
|
||||||
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
|
if (size < tlvend)
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
/* start at data[offset] */
|
||||||
|
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_IMAGE , tlvsize);
|
||||||
|
|
||||||
|
/* add mandatory part */
|
||||||
|
ok &= setRawUInt32(data, tlvend, offset, image_type);
|
||||||
|
ok &= binData.SetTlv(data, size, offset);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RsTlvImage::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||||
|
{
|
||||||
|
if (size < *offset + 4)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||||
|
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||||
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
|
if (size < tlvend) /* check size */
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
if (tlvtype != TLV_TYPE_IMAGE) /* check type */
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
/* ready to load */
|
||||||
|
TlvClear();
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
(*offset) += 4;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= getRawUInt32(data, tlvend, offset, &(image_type));
|
||||||
|
ok &= binData.GetTlv(data, size, offset);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* print it out */
|
||||||
|
std::ostream &RsTlvImage::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printBase(out, "RsTlvImage", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "Image_Type: " << image_type;
|
||||||
|
out << std::endl;
|
||||||
|
|
||||||
|
binData.print(out, int_Indent);
|
||||||
|
|
||||||
|
printEnd(out, "RsTlvImage", indent);
|
||||||
|
return out;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -38,7 +38,6 @@ static const int STUN_TTL = 64;
|
|||||||
* #define DEBUG_UDP_SORTER 1
|
* #define DEBUG_UDP_SORTER 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG_UDP_SORTER 1
|
|
||||||
|
|
||||||
UdpSorter::UdpSorter(struct sockaddr_in &local)
|
UdpSorter::UdpSorter(struct sockaddr_in &local)
|
||||||
:udpLayer(NULL), laddr(local), eaddrKnown(false), eaddrStable(false),
|
:udpLayer(NULL), laddr(local), eaddrKnown(false), eaddrStable(false),
|
||||||
@ -72,8 +71,10 @@ void UdpSorter::recvPkt(void *data, int size, struct sockaddr_in &from)
|
|||||||
/* check for STUN packet */
|
/* check for STUN packet */
|
||||||
if (UdpStun_isStunPacket(data, size))
|
if (UdpStun_isStunPacket(data, size))
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_UDP_SORTER
|
||||||
std::cerr << "UdpSorter::recvPkt() is Stun Packet";
|
std::cerr << "UdpSorter::recvPkt() is Stun Packet";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* respond */
|
/* respond */
|
||||||
locked_handleStunPkt(data, size, from);
|
locked_handleStunPkt(data, size, from);
|
||||||
@ -81,15 +82,19 @@ void UdpSorter::recvPkt(void *data, int size, struct sockaddr_in &from)
|
|||||||
else if (it == streams.end())
|
else if (it == streams.end())
|
||||||
{
|
{
|
||||||
/* peer unknown */
|
/* peer unknown */
|
||||||
|
#ifdef DEBUG_UDP_SORTER
|
||||||
std::cerr << "UdpSorter::recvPkt() Peer Unknown!";
|
std::cerr << "UdpSorter::recvPkt() Peer Unknown!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* forward to them */
|
/* forward to them */
|
||||||
|
#ifdef DEBUG_UDP_SORTER
|
||||||
std::cerr << "UdpSorter::recvPkt() Sending to UdpPeer: ";
|
std::cerr << "UdpSorter::recvPkt() Sending to UdpPeer: ";
|
||||||
std::cerr << it->first;
|
std::cerr << it->first;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
(it->second)->recvPkt(data, size);
|
(it->second)->recvPkt(data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user