mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-22 16:09:18 -04:00
Updated PeerNetQt inline with bitdht changes.
* Added genTestNet.py, to automatically generate scripts for a test network. * Added new flag -R for blocking proxy UDP port (unfinished). * Call ConnectionOptions to setup connect code. * Updated all the ErrorCodes. * Added extra debugging. * Improvements to Chat. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-peernet@4297 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7f9c8e92c2
commit
ebd9809adf
158
PeerNetQt/src/genTestNet.py
Executable file
158
PeerNetQt/src/genTestNet.py
Executable file
@ -0,0 +1,158 @@
|
||||
#!/usr/bin/python
|
||||
# must be compatible with 2.6.1 (OSX10.6)
|
||||
|
||||
import random, os, stat
|
||||
|
||||
|
||||
basePort = 20000;
|
||||
ipaddr = '127.0.0.1';
|
||||
# for OSX.
|
||||
#execpath = '../../PeerNetQt.app/Contents/MacOS/PeerNetQt';
|
||||
# for Linux
|
||||
execpath = '../../PeerNetQt';
|
||||
|
||||
# function to generate a folder for a peer.
|
||||
def generatePeer(folder, peerId, restrict, directfriends, proxyfriends, relayfriends):
|
||||
return;
|
||||
|
||||
|
||||
def generateNet(basefolder, npeers, nfriends, fracProxy, fracRelay, nguis):
|
||||
ids = [];
|
||||
folders = [];
|
||||
ports = [];
|
||||
blocks = [];
|
||||
relays = [];
|
||||
|
||||
portRange = npeers * 100;
|
||||
blockrange = portRange * fracProxy;
|
||||
relayrange = portRange * fracRelay;
|
||||
if (relayrange > blockrange):
|
||||
relayrange = blockrange;
|
||||
|
||||
for i in range(npeers):
|
||||
# generate an id.
|
||||
id = generatePeerId();
|
||||
folder = 'p%03d' % (i+1);
|
||||
port = basePort + (i+1) * 100;
|
||||
block = random.randint(basePort, basePort + portRange);
|
||||
if (1 == random.randint(0, 1)):
|
||||
relay = block + blockrange - relayrange; #relay is at the upper end
|
||||
else:
|
||||
relay = block; #relay is at the lower end.
|
||||
|
||||
# add into a array;
|
||||
folders.append(folder);
|
||||
ids.append(id);
|
||||
ports.append(port);
|
||||
blocks.append(block);
|
||||
relays.append(relay);
|
||||
|
||||
shuffledIdxs = range(npeers);
|
||||
# use the shuffle to choose the gui ones.
|
||||
random.shuffle(shuffledIdxs);
|
||||
guis = shuffledIdxs[0:nguis];
|
||||
if (os.path.exists(basefolder)):
|
||||
print 'Warning Path: %s already exists' % basefolder;
|
||||
else:
|
||||
os.mkdir(basefolder);
|
||||
|
||||
# open up the master script.
|
||||
scriptfilename = '%s/runall.sh' % (basefolder);
|
||||
fd = open(scriptfilename, 'w');
|
||||
fd.write('#!/bin/sh\n\n');
|
||||
|
||||
for i in range(npeers):
|
||||
random.shuffle(shuffledIdxs);
|
||||
print 'Peer %d : %s' % (i+1, ids[i]);
|
||||
print '\tFolder: %s' % (folders[i]);
|
||||
print '\tProxy Range: %d-%d' % (blocks[i], blocks[i] + blockrange);
|
||||
print '\tRelay Range: %d-%d' % (relays[i], relays[i] + relayrange);
|
||||
print '\tFriends:'
|
||||
friends = [];
|
||||
for j in range(nfriends):
|
||||
fid = shuffledIdxs[j];
|
||||
print '\t\tIdx: %d Port: %d Id: %s' % (fid, ports[fid], ids[fid])
|
||||
friends.append(ids[fid]);
|
||||
|
||||
folder = '%s/%s' % (basefolder, folders[i]);
|
||||
if (os.path.exists(folder)):
|
||||
print 'Warning Path: %s already exists' % folder;
|
||||
else:
|
||||
os.mkdir(folder);
|
||||
|
||||
# now generate the files.
|
||||
genbdboot(folder, ipaddr, ports);
|
||||
makePeerRunScript(folder, i in guis, ports[i], blocks[i], blockrange, relays[i], relayrange);
|
||||
makePeerFriendList(folder, friends);
|
||||
makePeerConfig(folder, ids[i]);
|
||||
|
||||
fd.write('cd %s\n' % folders[i]);
|
||||
fd.write('./run.sh &\n');
|
||||
fd.write('cd ..\n\n');
|
||||
|
||||
fd.close();
|
||||
os.chmod(scriptfilename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IROTH);
|
||||
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def generatePeerId():
|
||||
length = 20;
|
||||
id = "";
|
||||
for i in range(length):
|
||||
r = random.randint(0, 255);
|
||||
id += "%02x" % (r);
|
||||
return id;
|
||||
|
||||
def genbdboot(folder, ipaddr, ports):
|
||||
filename = '%s/bdboot.txt' % (folder);
|
||||
fd = open(filename, 'w');
|
||||
for port in ports:
|
||||
fd.write(('%s %d\n' % (ipaddr, port)));
|
||||
|
||||
return;
|
||||
|
||||
def makePeerConfig(folder, id):
|
||||
return;
|
||||
|
||||
def makePeerRunScript(folder, gui, port, proxyblock, proxyrange, relayblock, relayrange):
|
||||
filename = '%s/run.sh' % (folder);
|
||||
fd = open(filename, 'w');
|
||||
noguistr = '-n';
|
||||
if (gui):
|
||||
noguistr = '';
|
||||
|
||||
fd.write('#/bin/sh\n\n');
|
||||
fd.write('EXEC=%s\n\n' % execpath);
|
||||
fd.write(('$EXEC %s -l -p %d -r %d-%d -R %d-%d -c . > /dev/null 2>&1' % (noguistr, port, proxyblock, proxyblock+proxyrange, relayblock, relayblock+relayrange)));
|
||||
#fd.write(('$EXEC %s -l -p %d -r %d-%d -R %d-%d -c . > pn.log 2>&1' % (noguistr, port, proxyblock, proxyblock+proxyrange, relayblock, relayblock+relayrange)));
|
||||
|
||||
fd.close();
|
||||
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IROTH);
|
||||
return;
|
||||
|
||||
def makePeerFriendList(folder, friends):
|
||||
filename = '%s/peerlist.txt' % (folder);
|
||||
fd = open(filename, 'w');
|
||||
for friend in friends:
|
||||
fd.write('%s\n' % friend);
|
||||
|
||||
return;
|
||||
|
||||
def makePeerConfig(folder, id):
|
||||
filename = '%s/peerconfig.txt' % (folder);
|
||||
fd = open(filename, 'w');
|
||||
fd.write('%s\n' % id);
|
||||
fd.close();
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
tmpId = generatePeerId()
|
||||
print tmpId;
|
||||
|
||||
generateNet('testpeernet', 30, 10, 0.3, 0.1, 3);
|
@ -19,13 +19,16 @@ int main(int argc, char *argv[])
|
||||
bool doRestricted = false;
|
||||
std::list<std::string> restrictions;
|
||||
|
||||
bool doProxyRestricted = false;
|
||||
std::list<std::string> proxyrestrictions;
|
||||
|
||||
bool doFixedPort = false;
|
||||
int portNumber = 0;
|
||||
|
||||
bool doLocalTesting = false;
|
||||
|
||||
int c;
|
||||
while((c = getopt(argc, argv,"r:p:c:nl")) != -1)
|
||||
while((c = getopt(argc, argv,"r:R:p:c:nl")) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
@ -34,6 +37,11 @@ int main(int argc, char *argv[])
|
||||
doRestricted = true;
|
||||
restrictions.push_back(optarg);
|
||||
break;
|
||||
case 'R':
|
||||
std::cerr << "Adding Proxy Restriction: " << optarg << std::endl;
|
||||
doProxyRestricted = true;
|
||||
proxyrestrictions.push_back(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
std::cerr << "Setting Fixed Port: " << optarg << std::endl;
|
||||
doFixedPort = true;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@ -556,6 +557,7 @@ void MainWindow::sendChat()
|
||||
{
|
||||
mPeerNet->sendMessage(msg);
|
||||
}
|
||||
addChatMsg("yourself", msg);
|
||||
}
|
||||
|
||||
|
||||
@ -576,9 +578,13 @@ void MainWindow::updateChat()
|
||||
|
||||
void MainWindow::addChatMsg(std::string id, std::string msg)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString nowstr = now.toString("hh:mm:ss");
|
||||
QString chat = ui->chatBrowser->toPlainText();
|
||||
QString newmsg = "<";
|
||||
newmsg += QString::fromStdString(id);
|
||||
newmsg += QString::fromStdString(id.substr(0,5));
|
||||
newmsg += "...@";
|
||||
newmsg += nowstr;
|
||||
newmsg += "> ";
|
||||
newmsg += QString::fromStdString(msg);
|
||||
newmsg += "\n";
|
||||
|
@ -143,7 +143,8 @@ void PeerNet::init()
|
||||
|
||||
/* setup callback to here */
|
||||
mUdpBitDht->addCallback(this);
|
||||
|
||||
mUdpBitDht->ConnectionOptions(BITDHT_CONNECT_MODE_DIRECT |
|
||||
BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY, 0);
|
||||
|
||||
std::cerr << "PeerNet() startup ... creating UdpRelayReceiver on UdpStack";
|
||||
std::cerr << std::endl;
|
||||
@ -757,6 +758,7 @@ int PeerNet::OnlinePeerCallback_locked(const bdId *id, uint32_t status, PeerStat
|
||||
ca.mType = PEERNET_ACTION_TYPE_CONNECT;
|
||||
ca.mMode = BITDHT_CONNECT_MODE_DIRECT;
|
||||
ca.mDestId = *id;
|
||||
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
|
||||
|
||||
mActions.push_back(ca);
|
||||
}
|
||||
@ -837,6 +839,7 @@ int PeerNet::UnreachablePeerCallback_locked(const bdId *id, uint32_t status, Pee
|
||||
ca.mMode = BITDHT_CONNECT_MODE_RELAY;
|
||||
}
|
||||
|
||||
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
|
||||
mActions.push_back(ca);
|
||||
}
|
||||
else
|
||||
@ -860,7 +863,7 @@ int PeerNet::dhtValueCallback(const bdNodeId *id, std::string key, uint32_t stat
|
||||
}
|
||||
|
||||
int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
||||
uint32_t mode, uint32_t point, uint32_t cbtype)
|
||||
uint32_t mode, uint32_t point, uint32_t cbtype, uint32_t errcode)
|
||||
{
|
||||
std::cerr << "PeerNet::dhtConnectCallback()";
|
||||
std::cerr << std::endl;
|
||||
@ -916,15 +919,16 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
bdStdPrintId(std::cerr, destId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
int connectionAllowed = 0;
|
||||
int connectionAllowed = BITDHT_CONNECT_ERROR_GENERIC;
|
||||
if (checkProxyAllowed(srcId, destId, mode))
|
||||
{
|
||||
connectionAllowed = 1;
|
||||
connectionAllowed = BITDHT_CONNECT_ANSWER_OKAY;
|
||||
std::cerr << "dhtConnectionCallback() Connection Allowed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionAllowed = BITDHT_CONNECT_ERROR_AUTH_DENIED;
|
||||
std::cerr << "dhtConnectionCallback() Connection Denied";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
@ -977,6 +981,14 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
bdStdPrintId(std::cerr, srcId);
|
||||
std::cerr << " and ";
|
||||
bdStdPrintId(std::cerr, destId);
|
||||
|
||||
std::cerr << " ErrorCode: " << errcode;
|
||||
int errsrc = errcode & BITDHT_CONNECT_ERROR_MASK_SOURCE;
|
||||
int errtype = errcode & BITDHT_CONNECT_ERROR_MASK_TYPE;
|
||||
|
||||
std::cerr << " ErrorSrc: " << errsrc;
|
||||
std::cerr << " ErrorType: " << errtype;
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (mode == BITDHT_CONNECT_MODE_RELAY)
|
||||
@ -1012,15 +1024,16 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
bdStdPrintId(std::cerr, &(peerId));
|
||||
std::cerr << std::endl;
|
||||
|
||||
int connectionAllowed = 0;
|
||||
int connectionAllowed = BITDHT_CONNECT_ERROR_GENERIC;
|
||||
if (checkConnectionAllowed(&(peerId), mode))
|
||||
{
|
||||
connectionAllowed = 1;
|
||||
connectionAllowed = BITDHT_CONNECT_ANSWER_OKAY;
|
||||
std::cerr << "dhtConnectionCallback() Connection Allowed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionAllowed = BITDHT_CONNECT_ERROR_AUTH_DENIED;
|
||||
std::cerr << "dhtConnectionCallback() Connection Denied";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
@ -1063,7 +1076,7 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionAllowed = 0;
|
||||
connectionAllowed = BITDHT_CONNECT_ERROR_UNREACHABLE;
|
||||
std::cerr << "dhtConnectionCallback() Proxy Connection";
|
||||
std::cerr << " is Discarded, as Own External Proxy Address is Not Stable!";
|
||||
std::cerr << std::endl;
|
||||
@ -1071,7 +1084,7 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionAllowed = 0;
|
||||
connectionAllowed = BITDHT_CONNECT_ERROR_TEMPUNAVAIL;
|
||||
std::cerr << "PeerAction: ERROR Proxy Connection ";
|
||||
std::cerr << " is Discarded, as Failed to get Own External Proxy Address.";
|
||||
std::cerr << std::endl;
|
||||
@ -1103,7 +1116,7 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
ca.mSrcId = *srcId;
|
||||
ca.mDestId = *destId;
|
||||
ca.mPoint = point;
|
||||
ca.mAnswer = 1;
|
||||
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
|
||||
|
||||
mActions.push_back(ca);
|
||||
|
||||
@ -1115,7 +1128,21 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
std::cerr << "dhtConnectionCallback() Connection Attempt Failed with:";
|
||||
bdStdPrintId(std::cerr, &(peerId));
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
std::cerr << "dhtConnectionCallback() Proxy:";
|
||||
bdStdPrintId(std::cerr, proxyId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "dhtConnectionCallback() ";
|
||||
std::cerr << " ErrorCode: " << errcode;
|
||||
int errsrc = errcode & BITDHT_CONNECT_ERROR_MASK_SOURCE;
|
||||
int errtype = errcode & BITDHT_CONNECT_ERROR_MASK_TYPE;
|
||||
|
||||
std::cerr << " ErrorSrc: " << errsrc;
|
||||
std::cerr << " ErrorType: " << errtype;
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1123,7 +1150,7 @@ int PeerNet::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bd
|
||||
case BITDHT_CONNECT_CB_PENDING:
|
||||
case BITDHT_CONNECT_CB_PROXY:
|
||||
{
|
||||
std::cerr << "dhtConnectionCallback() ERROR unexpected Connection ConnectionCallback:";
|
||||
std::cerr << "dhtConnectionCallback() ERROR unexpected ConnectionCallback:";
|
||||
std::cerr << std::endl;
|
||||
bdStdPrintId(std::cerr, srcId);
|
||||
std::cerr << " and ";
|
||||
|
@ -151,7 +151,7 @@ virtual int dhtNodeCallback(const bdId *id, uint32_t peerflags);
|
||||
virtual int dhtPeerCallback(const bdId *id, uint32_t status);
|
||||
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
||||
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
||||
uint32_t mode, uint32_t point, uint32_t cbtype);
|
||||
uint32_t mode, uint32_t point, uint32_t cbtype, uint32_t errcode);
|
||||
|
||||
// Sub Callback Functions.
|
||||
int OnlinePeerCallback_locked(const bdId *id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user