mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-10 18:15:18 -04:00
Bugfixes:
* Corrected mLocal -> mExt in ipset.cc * Added pqiipset_test * added both Ext and Local address to GUI display. * p3connmgr: Ip Addresses only updated if we connected (otherwise port is wrong). * p3connmgr: update external address when we get it. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3251 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
518de7b8c8
commit
6f219d4fef
5 changed files with 228 additions and 32 deletions
|
@ -12,12 +12,13 @@ TESTOBJ = conn_harness.o ppg_harness.o
|
|||
|
||||
TESTOBJ += net_test.o dht_test.o net_test1.o netiface_test.o dht_test.o
|
||||
TESTOBJ += pkt_test.o pqiarchive_test.o pqiperson_test.o
|
||||
TESTOBJ += extaddrfinder_test.o
|
||||
TESTOBJ += extaddrfinder_test.o pqiipset_test.o
|
||||
TESTOBJ += p3connmgr_reset_test.o p3connmgr_connect_test.o
|
||||
#conn_test.o
|
||||
|
||||
TESTS = net_test net_test1 netiface_test pqiarchive_test pqiperson_test extaddrfinder_test
|
||||
TESTS = p3connmgr_reset_test p3connmgr_connect_test
|
||||
TESTS += pqiipset_test
|
||||
TESTS += p3connmgr_reset_test p3connmgr_connect_test
|
||||
#TESTS = p3connmgr_test1
|
||||
|
||||
MANUAL_TESTS = dht_test
|
||||
|
@ -55,10 +56,12 @@ pqiperson_test: pqiperson_test.o testconnect.o
|
|||
extaddrfinder_test: extaddrfinder_test.o
|
||||
$(CC) $(CFLAGS) -o extaddrfinder_test extaddrfinder_test.o $(LIBS)
|
||||
|
||||
pqiipset_test: pqiipset_test.o
|
||||
$(CC) $(CFLAGS) -o pqiipset_test pqiipset_test.o $(LIBS)
|
||||
|
||||
p3connmgr_reset_test: p3connmgr_reset_test.o
|
||||
$(CC) $(CFLAGS) -o p3connmgr_reset_test p3connmgr_reset_test.o $(LIBS)
|
||||
|
||||
|
||||
p3connmgr_connect_test: p3connmgr_connect_test.o conn_harness.o ppg_harness.o
|
||||
$(CC) $(CFLAGS) -o p3connmgr_connect_test p3connmgr_connect_test.o conn_harness.o ppg_harness.o $(LIBS)
|
||||
|
||||
|
|
142
libretroshare/src/tests/pqi/pqiipset_test.cc
Normal file
142
libretroshare/src/tests/pqi/pqiipset_test.cc
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* libretroshare/src/test/pqi pqiipset_test.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2010 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******
|
||||
* NETWORKING Test to check Big/Little Endian behaviour
|
||||
* as well as socket behaviour
|
||||
*
|
||||
*/
|
||||
|
||||
#include "util/utest.h"
|
||||
|
||||
#include "pqi/pqiipset.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsnet.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
bool test_addr_list();
|
||||
|
||||
|
||||
INITTEST();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cerr << "libretroshare:pqi " << argv[0] << std::endl;
|
||||
|
||||
test_addr_list();
|
||||
|
||||
FINALREPORT("libretroshare pqiipset Tests");
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
/* test 1: byte manipulation */
|
||||
bool test_addr_list()
|
||||
{
|
||||
pqiIpAddress addr;
|
||||
pqiIpAddrList list;
|
||||
|
||||
for(int i = 100; i < 150; i++)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "192.168.2." << i;
|
||||
inet_aton(out.str().c_str(), &(addr.mAddr.sin_addr));
|
||||
addr.mAddr.sin_port = htons(7812);
|
||||
addr.mSeenTime = time(NULL) - i;
|
||||
|
||||
list.updateIpAddressList(addr);
|
||||
}
|
||||
|
||||
/* print out the list */
|
||||
std::cerr << "IpAddressList (expect variation: 192.168.2.[100-103]:7812)";
|
||||
std::cerr << std::endl;
|
||||
list.printIpAddressList(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
const uint32_t expectedListSize = 4;
|
||||
CHECK(list.mAddrs.size() == expectedListSize);
|
||||
|
||||
time_t min_time = time(NULL) - expectedListSize + 100;
|
||||
|
||||
/* expect the most recent ones to appear */
|
||||
std::list<pqiIpAddress>::iterator it;
|
||||
for(it = list.mAddrs.begin(); it != list.mAddrs.end(); it++)
|
||||
{
|
||||
CHECK(it->mSeenTime < min_time);
|
||||
}
|
||||
|
||||
/* now add some with same address + port */
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "192.168.2.200";
|
||||
inet_aton(out.str().c_str(), &(addr.mAddr.sin_addr));
|
||||
addr.mAddr.sin_port = htons(8812);
|
||||
}
|
||||
|
||||
/* make sure it more recent than the previous ones */
|
||||
for(int i = 100; i > 89; i--)
|
||||
{
|
||||
addr.mSeenTime = time(NULL) - i;
|
||||
list.updateIpAddressList(addr);
|
||||
|
||||
/* check that was added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
}
|
||||
|
||||
/* print out the list */
|
||||
std::cerr << "IpAddressList (last item to be 192.168.2.200:8812)";
|
||||
std::cerr << std::endl;
|
||||
list.printIpAddressList(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* now add with the different ports */
|
||||
|
||||
for(int i = 70; i > 50; i--)
|
||||
{
|
||||
addr.mAddr.sin_port = htons(8000 + i);
|
||||
addr.mSeenTime = time(NULL) - i;
|
||||
|
||||
list.updateIpAddressList(addr);
|
||||
|
||||
/* check that was added to the back */
|
||||
CHECK(list.mAddrs.back().mSeenTime == addr.mSeenTime);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr);
|
||||
CHECK(list.mAddrs.back().mAddr.sin_port == addr.mAddr.sin_port);
|
||||
|
||||
}
|
||||
|
||||
std::cerr << "IpAddressList (expect same Ip, but variations in port)";
|
||||
std::cerr << std::endl;
|
||||
list.printIpAddressList(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
REPORT("pqiIpAddrList Test");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue