[complement-svn] SF.net SVN: complement: [1410] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-27 08:15:13
|
Revision: 1410 http://svn.sourceforge.net/complement/?rev=1410&view=rev Author: complement Date: 2006-11-27 00:15:11 -0800 (Mon, 27 Nov 2006) Log Message: ----------- change pass addresses when go through some transport; looks like work now Modified Paths: -------------- trunk/complement/explore/include/stem/EDSEv.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EDSEv.h =================================================================== --- trunk/complement/explore/include/stem/EDSEv.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/EDSEv.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:39:23 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 14:15:19 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -16,14 +16,17 @@ namespace stem { -#define EV_EDS_CONNECT 0x06 -#define EV_EDS_DISCONNECT 0x07 -#define EV_EDS_ANNOUNCE 0x08 -#define EV_EDS_RQ_SESSION 0x09 -#define EV_EDS_RRQ_SESSION 0x10 -#define EV_EDS_RS_SESSION 0x11 -#define EV_EDS_CL_SESSION 0x12 +#define EV_STEM_TRANSPORT 0x06 +#define EV_STEM_TRANSPORT_ACK 0x07 +// #define EV_EDS_CONNECT 0x06 +// #define EV_EDS_DISCONNECT 0x07 +// #define EV_EDS_ANNOUNCE 0x08 +// #define EV_EDS_RQ_SESSION 0x09 +// #define EV_EDS_RRQ_SESSION 0x10 +// #define EV_EDS_RS_SESSION 0x11 +// #define EV_EDS_CL_SESSION 0x12 + // Name Service #define EV_STEM_GET_NS_LIST 0x13 #define EV_STEM_GET_NS_NAME 0x14 Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:11:52 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 21:10:31 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -107,6 +107,7 @@ const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); __FIT_DECLSPEC addr_type reflect( const gaddr_type& addr ) const; + __FIT_DECLSPEC gaddr_type reflect( addr_type addr ) const; bool is_avail( addr_type id ) const { Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/Event.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:57:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 14:32:35 ptr> /* * @@ -78,24 +78,13 @@ typedef uint32_t addr_type; typedef uint32_t code_type; -typedef uint32_t key_type; -#ifndef WIN32 extern const addr_type badaddr; extern const addr_type extbit; +extern const addr_type default_addr; extern const addr_type ns_addr; -extern const key_type badkey; extern const code_type badcode; -#endif -#ifdef WIN32 -extern __PG_DECLSPEC addr_type badaddr; -extern __PG_DECLSPEC addr_type extbit; -extern __PG_DECLSPEC addr_type ns_addr; -extern __PG_DECLSPEC key_type badkey; -extern __PG_DECLSPEC code_type badcode; -#endif - #ifdef STLPORT using std::__true_type; using std::__false_type; @@ -175,9 +164,9 @@ code_type code() const { return _code; } - key_type dest() const + addr_type dest() const { return _dst; } - key_type src() const + addr_type src() const { return _src; } bool is_from_foreign() const { return ((_src & extbit) != 0) && (_src != badaddr); } Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:11:46 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 21:21:55 ptr> /* * @@ -27,27 +27,17 @@ using namespace std; using namespace xmt; -#ifndef WIN32 const addr_type badaddr = 0xffffffff; -const key_type badkey = 0xffffffff; const code_type badcode = static_cast<code_type>(-1); const addr_type extbit = 0x80000000; +const addr_type default_addr = 0x00000000; const addr_type ns_addr = 0x00000001; -#endif -#ifdef WIN32 -__PG_DECLSPEC addr_type badaddr = 0xffffffff; -__PG_DECLSPEC key_type badkey = 0xffffffff; -__PG_DECLSPEC code_type badcode = static_cast<code_type>(-1); -__PG_DECLSPEC addr_type extbit = 0x80000000; -__PG_DECLSPEC addr_type ns_addr = 0x00000001; -#endif +const addr_type beglocaddr = 0x00000100; +const addr_type endlocaddr = 0x3fffffff; +const addr_type begextaddr = extbit; +const addr_type endextaddr = 0xbfffffff; -const addr_type beglocaddr = 0x00000100; -const addr_type endlocaddr = 0x3fffffff; -const addr_type begextaddr = extbit; -const addr_type endextaddr = 0xbfffffff; - std::string EvManager::inv_key_str( "invalid key" ); __FIT_DECLSPEC EvManager::EvManager() : @@ -293,7 +283,8 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { - if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { // this host, this process + if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { + // this host, this process if ( (addr.addr & extbit) == 0 ) { // looks like local object Locker _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); @@ -302,6 +293,22 @@ } } } +#if 0 + else if ( addr.hid == gaddr_type() && addr.pid == -1 ) { + // this host, special case: + // peer don't know host ids, used as access to 'standard' services and initial + // communication + if ( (addr.addr & extbit) == 0 && addr.addr <= _low ) { + Locker _x1( _lock_heap ); + local_heap_type::const_iterator l = heap.find( addr.addr ); + if ( l != heap.end() ) { + return addr.addr; // l->first + } + } + // disable external objects here; restrict to 'standard' services + return badaddr; + } +#endif Locker _x1( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); @@ -312,6 +319,17 @@ } __FIT_DECLSPEC +gaddr_type EvManager::reflect( addr_type addr ) const +{ + Locker lk( _lock_xheap ); + ext_uuid_heap_type::const_iterator i = _ex_heap.find( addr ); + if ( i != _ex_heap.end() ) { + return i->second; + } + return gaddr_type(); +} + +__FIT_DECLSPEC void EvManager::Remove( void *channel ) { Locker _x1( _lock_xheap ); Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:17:46 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 12:22:27 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -16,14 +16,18 @@ #endif #include <config/feature.h> + +#include <unistd.h> + #include "stem/Names.h" #include "stem/EvManager.h" #include "stem/EDSEv.h" + #include <list> +#include <iostream> + #include <mt/xmt.h> -#include <iostream> - namespace stem { using namespace std; Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 21:44:47 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 19:14:58 ptr> /* * @@ -111,13 +111,11 @@ uint32_t buf[bsz]; using namespace std; - // cerr << __FILE__ << ":" << __LINE__ << endl; MT_IO_REENTRANT( *net ) if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { return false; } - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( buf[0] != EDS_MAGIC ) { cerr << "EDS Magic fail" << endl; @@ -212,16 +210,51 @@ NetTransport::NetTransport( std::sockstream& s ) : NetTransport_base( "stem::NetTransport" ) { + net = &s; + + try { + Event ev; + gaddr_type dst; + gaddr_type src; + + if ( pop( ev, dst, src ) ) { + if ( ev.code() == EV_STEM_TRANSPORT ) { + src.addr = ns_addr; + addr_type xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + src.addr = default_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + Event ack( EV_STEM_TRANSPORT_ACK ); + push( ack, src, self_glid() ); + } else { + throw runtime_error( "net handshake error" ); + } + } else { + throw runtime_error( "net error or net handshake error" ); + } + } + catch ( runtime_error& err ) { + s.close(); + cerr << err.what() << endl; + } + catch ( ... ) { + s.close(); + } } __FIT_DECLSPEC void NetTransport::connect( sockstream& s ) { - Event ev; - gaddr_type dst; - gaddr_type src; + try { + Event ev; + gaddr_type dst; + gaddr_type src; - try { if ( pop( ev, dst, src ) ) { addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { @@ -230,8 +263,7 @@ ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); - ev.src( manager()->SubscribeRemote( tr, src ) ); + ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { ev.src( xsrc ); } @@ -271,28 +303,55 @@ addr_type NetTransportMgr::open( const char *hostname, int port, std::sock_base::stype stype ) { - // I should be sure, that not more then one _loop running from here! - // For this, I enforce close connection before I try open new, - // and wait thread with _loop before start new. - if ( net == 0 ) { - net = new sockstream( hostname, port, stype ); - } else if ( net->is_open() ) { - // net->close(); - close(); // I should wait termination of _loop, clear EDS address mapping, etc. - net->open( hostname, port, stype ); - } else { - join(); // This is safe: transparent if no _loop, and wait it if one exist - net->open( hostname, port, stype ); - } + try { + // I should be sure, that not more then one _loop running from here! + // For this, I enforce close connection before I try open new, + // and wait thread with _loop before start new. + if ( net == 0 ) { + net = new sockstream( hostname, port, stype ); + } else if ( net->is_open() ) { + // net->close(); + close(); // I should wait termination of _loop, clear EDS address mapping, etc. + net->open( hostname, port, stype ); + } else { + join(); // This is safe: transparent if no _loop, and wait it if one exist + net->open( hostname, port, stype ); + } - if ( net->good() ) { - // _net_ns = rar_map( ns_addr, __ns_at + hostname ); - // addr_type zero_object = rar_map( 0, __at + hostname ); - detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); - // addr_type zero_object = manager()->SubscribeRemote( tr, src ); - _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here - return 0; // zero_object; + if ( net->good() ) { + // _net_ns = rar_map( ns_addr, __ns_at + hostname ); + // addr_type zero_object = rar_map( 0, __at + hostname ); + + Event ev( EV_STEM_TRANSPORT ); + gaddr_type dst; + gaddr_type src; + addr_type xsrc = badaddr; + push( ev, gaddr_type(), self_glid() ); + if ( pop( ev, dst, src ) ) { + if ( ev.code() == EV_STEM_TRANSPORT_ACK ) { + src.addr = ns_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + src.addr = default_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + xsrc = manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + } else { + throw runtime_error( "net handshake error" ); + } + } else { + throw runtime_error( "net error or net handshake error" ); + } + _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here + return xsrc; // zero_object; + } } + catch ( runtime_error& err ) { + cerr << err.what() << endl; + } return badaddr; } @@ -331,8 +390,7 @@ ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - detail::transport tr( static_cast<NetTransport_base *>(&me), detail::transport::socket_tcp, 10 ); - ev.src( manager()->SubscribeRemote( tr, src ) ); + ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(&me), detail::transport::socket_tcp, 10 ), src ) ); } else { ev.src( xsrc ); } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:59:03 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 12:22:42 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -21,13 +21,8 @@ #include "stem/Names.h" #include "mt/xmt.h" -#if defined(__TRACE) || defined(__WARN) +#include <unistd.h> -// DIAG_DEFINE_GROUP(EventHandler,0,4); -// DIAG_DEFINE_GROUP(EventDispatch,0,3); - -#endif // __TRACE || __WARN - namespace stem { char *Init_buf[32]; Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 21:05:01 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 11:08:36 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -47,6 +47,7 @@ void ns(); void echo(); + void echo_net(); void peer(); static xmt::Thread::ret_code thr1( void * ); @@ -259,7 +260,7 @@ stem::addr_type zero = mgr.open( "localhost", 6995 ); BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero == 0 ); // NetTransportMgr should detect local delivery EchoClient node; @@ -283,9 +284,171 @@ // cerr << "Fine\n"; } +void stem_test::echo_net() +{ + xmt::__Condition<true> fcnd; + fcnd.set( false ); + + try { + xmt::Thread::fork(); + + stem::NetTransportMgr mgr; + + fcnd.try_wait(); + + stem::addr_type zero = mgr.open( "localhost", 6995 ); + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); // NetTransportMgr should detect external delivery + + EchoClient node; + + stem::Event ev( NODE_EV_ECHO ); + + ev.dest( zero ); + ev.value() = node.mess; + + node.Send( ev ); + + node.wait(); + + mgr.close(); + + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } + + try { + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + + StEMecho echo( 0, "echo service"); // <= zero! + + fcnd.set( true ); + + // mgr.join(); + + srv.close(); + srv.wait(); + } + catch ( ... ) { + } + // cerr << "Fine\n"; +} + void stem_test::peer() { + xmt::__Condition<true> fcnd; + fcnd.set( false ); + + xmt::__Condition<true> pcnd; + pcnd.set( false ); + + xmt::__Condition<true> scnd; + scnd.set( false ); + + try { + xmt::Thread::fork(); + stem::NetTransportMgr mgr; + + PeerClient c1( "c1 local" ); // c1 client + Naming nm; + + cerr << "1\n"; + fcnd.try_wait(); + + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address + + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); + + ev.value() = "c1@here"; + c1.Send( ev ); // 'register' c1 client on 'echo' server + + stem::gaddr_type ga( c1.manager()->reflect( zero ) ); + + BOOST_CHECK( ga.addr == 0 ); + BOOST_CHECK( ga.pid != -1 ); + + ga.addr = stem::ns_addr; // this will be global address of ns of the same process + // as zero + + BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); + + stem::Event evname( EV_STEM_GET_NS_NAME ); + evname.dest( c1.manager()->reflect( ga ) ); + evname.value() = "c2@here"; + + pcnd.try_wait(); + + nm.Send( evname ); + nm.wait(); + + Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + + BOOST_CHECK( i != nm.lst.end() ); + BOOST_CHECK( i->second == "c2@here" ); + + // c1.manager()->reflect( i->first ); + + cerr << "1.1\n"; + + scnd.set( true ); + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } #if 0 + try { + xmt::Thread::fork(); + stem::NetTransportMgr mgr; + + cerr << "2\n"; + + PeerClient c2( "c2 local" ); // c2 client + + fcnd.try_wait(); + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address + + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); + + ev.value() = "c2@here"; + c2.Send( ev ); // 'register' c2 client on 'echo' server + + cerr << "2.1\n"; + + pcnd.set( true ); + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } +#endif + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' + StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) + cerr << "3\n"; + + fcnd.set( true ); + + scnd.try_wait(); + + srv.close(); + srv.wait(); + +#if 0 /* * Scheme: * / NetTransport / c1 @@ -404,6 +567,7 @@ test_case *dl_tc = BOOST_CLASS_TEST_CASE( &stem_test::dl, instance ); test_case *ns_tc = BOOST_CLASS_TEST_CASE( &stem_test::ns, instance ); test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); + test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); basic2_tc->depends_on( basic1_tc ); @@ -414,6 +578,7 @@ ns_tc->depends_on( basic1_tc ); echo_tc->depends_on( basic2_tc ); + echo_net_tc->depends_on( echo_tc ); peer_tc->depends_on( echo_tc ); add( basic1_tc ); @@ -424,6 +589,7 @@ add( ns_tc ); add( echo_tc ); + add( echo_net_tc ); add( peer_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |