[complement-svn] SF.net SVN: complement: [1406] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-24 16:03:28
|
Revision: 1406 http://svn.sourceforge.net/complement/?rev=1406&view=rev Author: complement Date: 2006-11-24 08:03:22 -0800 (Fri, 24 Nov 2006) Log Message: ----------- rewritten scheme of mapping between internal and external addresses and message routing logic; just compile, not checked 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/include/stem/Names.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/EvPack.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/stem/EDSEv.h =================================================================== --- trunk/complement/explore/include/stem/EDSEv.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/EDSEv.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:36:24 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:39:23 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -19,31 +19,23 @@ #define EV_EDS_CONNECT 0x06 #define EV_EDS_DISCONNECT 0x07 #define EV_EDS_ANNOUNCE 0x08 -#define EV_EDS_RQ_SESSION 0x10 -#define EV_EDS_RRQ_SESSION 0x11 -#define EV_EDS_RS_SESSION 0x12 -#define EV_EDS_CL_SESSION 0x13 +#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_EDS_NM_LIST 0x14 -#define EV_EDS_NS_ADDR 0x1c -#define EV_EDS_RQ_ADDR_LIST 0x15 -#define EV_EDS_RQ_EXT_ADDR_LIST 0x16 -#define EV_EDS_RQ_ADDR_BY_NAME 0x1b +#define EV_STEM_GET_NS_LIST 0x13 +#define EV_STEM_GET_NS_NAME 0x14 +#define EV_STEM_NS_LIST 0x15 +#define EV_STEM_NS_NAME 0x16 - -#define EV_STEM_NS1_LIST 0x1e -#define EV_STEM_NS1_NAME 0x1f -#define EV_STEM_RQ_ADDR_LIST1 0x20 -#define EV_STEM_RQ_EXT_ADDR_LIST1 0x21 -#define EV_STEM_RQ_ADDR_BY_NAME1 0x22 - // Cron Service #define EV_EDS_CRON_ADD 0x17 #define EV_EDS_CRON_REMOVE 0x18 -#define EV_EDS_CRON_REMOVE_ARG 0x1d -#define EV_EDS_CRON_START 0x19 -#define EV_EDS_CRON_STOP 0x1a +#define EV_EDS_CRON_REMOVE_ARG 0x19 +#define EV_EDS_CRON_START 0x1a +#define EV_EDS_CRON_STOP 0x1b } // namespace stem Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:03:42 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:11:52 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -49,7 +49,7 @@ kind( unknown ) { } - transport( transport_entry *l, kind_type k, int m = 0 ) : + transport( transport_entry l, kind_type k, int m = 0 ) : link( l ), metric( m ), kind( k ) @@ -106,6 +106,7 @@ const gaddr_type& addr, const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); + __FIT_DECLSPEC addr_type reflect( const gaddr_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-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/Event.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:07:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 14:50:06 ptr> /* * @@ -123,6 +123,10 @@ bool operator !=( const gaddr_type& ga ) const { return hid != ga.hid || pid != ga.pid || addr != ga.addr; } __FIT_DECLSPEC bool operator <( const gaddr_type& ga ) const; + + + __FIT_DECLSPEC void _xnet_pack( char *buf ) const; + __FIT_DECLSPEC void _xnet_unpack( const char *buf ); }; class __Event_Base Modified: trunk/complement/explore/include/stem/Names.h =================================================================== --- trunk/complement/explore/include/stem/Names.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/Names.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:35:52 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 18:23:55 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -41,9 +41,8 @@ explicit __FIT_DECLSPEC Names( addr_type id, const char *info = 0 ); __FIT_DECLSPEC ~Names(); - __FIT_DECLSPEC void get_list( const Event& ); - __FIT_DECLSPEC void get_ext_list( const Event& ); - __FIT_DECLSPEC void get_by_name( const Event& ); + __FIT_DECLSPEC void ns_list( const Event& ); + __FIT_DECLSPEC void ns_name( const Event& ); private: DECLARE_RESPONSE_TABLE( Names, EventHandler ); @@ -52,8 +51,7 @@ struct NameRecord : public __pack_base { - NameRecord() : - addr( badaddr ) + NameRecord() { } NameRecord( const NameRecord& nr ) : @@ -61,12 +59,12 @@ record( nr.record ) { } - NameRecord( addr_type a, const std::string& r ) : + NameRecord( const gaddr_type& a, const std::string& r ) : addr( a ), record( r ) { } - addr_type addr; + gaddr_type addr; std::string record; virtual __FIT_DECLSPEC void pack( std::ostream& s ) const; @@ -81,7 +79,7 @@ // bool operator == ( const std::string& s, const NameRecord& nr ) // { return nr.record == s; } -inline bool operator == ( const NameRecord& nr, addr_type a ) +inline bool operator == ( const NameRecord& nr, const gaddr_type& a ) { return nr.addr == a; } // bool operator == ( addr_type a, const NameRecord& nr ) @@ -118,7 +116,8 @@ { __pack( s, container.size() ); for ( const_iterator i = container.begin(); i != container.end(); ++i ) { - __pack( s, i->first ); + // __pack( s, i->first ); + i->first.pack( s ); __pack( s, i->second ); } } @@ -128,7 +127,8 @@ { __net_pack( s, static_cast<uint32_t>(container.size()) ); for ( const_iterator i = container.begin(); i != container.end(); ++i ) { - __net_pack( s, i->first ); + // __net_pack( s, i->first ); + i->first.net_pack( s ); __net_pack( s, i->second ); } } @@ -145,7 +145,8 @@ Info i; while ( sz-- > 0 ) { - __unpack( s, a ); + // __unpack( s, a ); + a.unpack( s ); __unpack( s, i ); container.push_back( std::make_pair(a, i) ); } @@ -163,7 +164,8 @@ Info i; while ( sz-- > 0 ) { - __net_unpack( s, a ); + // __net_unpack( s, a ); + a.net_unpack( s ); __net_unpack( s, i ); container.push_back( std::make_pair(a, i) ); } Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:07:32 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 15:29:19 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -63,7 +63,7 @@ __FIT_DECLSPEC bool push( const Event&, const gaddr_type& dst, const gaddr_type& src ); protected: - bool pop( Event& ); + bool pop( Event&, gaddr_type& dst, gaddr_type& src ); std::sockstream *net; uint32_t _count; @@ -78,9 +78,6 @@ __FIT_DECLSPEC void connect( std::sockstream& ); - - private: - std::string _at_hostname; }; class NetTransportMgr : Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,3 +1,19 @@ +2006-11-24 Petr Ovtchenkov <pt...@is...> + + * Event.h, EvPack.h, EvPack.cc: introduce 'global + address'---unique object address as composition + of hostid, pid adn local address; + + * NetTransport.h, NetTransport.cc, EvManager.h, EvManager.cc: + rewritten scheme of mapping between internal and external + addresses and message routing logic. + + * Names.cc, Names.h, EDSEv.h: return gloabal addresses + list; remove obsolete requests/responses; + + * Makefile.inc: _EvSession.cc, _SessionMgr.cc removed + from compilation; library version 4.2.0 + 2006-10-12 Petr Ovtchenkov <pt...@is...> * NetTransport.h, NetTransport.cc: remove make_map, Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 11:59:21 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:17:05 ptr> /* * @@ -20,9 +20,13 @@ #include "stem/EvManager.h" #include "stem/NetTransport.h" #include <iomanip> +#include <mt/xmt.h> namespace stem { +using namespace std; +using namespace xmt; + #ifndef WIN32 const addr_type badaddr = 0xffffffff; const key_type badkey = 0xffffffff; @@ -202,7 +206,7 @@ __FIT_DECLSPEC addr_type EvManager::SubscribeRemote( const detail::transport& tr, - const gaddr_type addr, + const gaddr_type& addr, const char *info ) { addr_type id; @@ -231,7 +235,7 @@ pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( addr ); for ( uuid_tr_heap_type::iterator i = range.first; i != range.second; ++i ) { - pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( i->link ); + pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( i->second.link ); for ( tr_uuid_heap_type::iterator j = ch_range.first; j != ch_range.second; ) { if ( j->second == i->first ) { _ch_heap.erase( j++ ); @@ -256,6 +260,27 @@ } __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.addr & extbit) == 0 ) { // looks like local object + Locker _x1( _lock_heap ); + local_heap_type::const_iterator l = heap.find( addr.addr ); + if ( l != heap.end() ) { + return addr.addr; // l->first + } + } + } + + Locker _x1( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + if ( i == _ui_heap.end() ) { + return badaddr; + } + return i->second; +} + +__FIT_DECLSPEC void EvManager::Remove( void *channel ) { Locker _x1( _lock_xheap ); @@ -285,15 +310,15 @@ { Locker _x1( _lock_xheap ); if ( (id & extbit) != 0 ) { - ext_uuid_heap_type::iterator i = _ex_heap.find( id ); + ext_uuid_heap_type::const_iterator i = _ex_heap.find( id ); if ( i == _ex_heap.end() ) { throw range_error( string( "no such address" ) ); } - pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( i->second ); + pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( i->second ); if ( range.first == _tr_heap.end() ) { throw range_error( string( "no transport" ) ); } - return min_element( range.first, range.second, tr_compare ).second; + return min_element( range.first, range.second, tr_compare )->second; } throw range_error( string( "internal address" ) ); } @@ -318,11 +343,11 @@ if ( range.first == _tr_heap.end() ) { throw range_error( string( "no transport" ) ); } - detail::transport& tr = min_element( range.first, range.second, tr_compare ).second; + detail::transport& tr = min_element( range.first, range.second, tr_compare )->second; detail::transport::kind_type k = tr.kind; void *link = tr.link; - uuid_type gaddr_dst( i->second ); - uuid_type gaddr_src; + gaddr_type gaddr_dst( i->second ); + gaddr_type gaddr_src; ext_uuid_heap_type::iterator j = _ex_heap.find( e.src() ); if ( j == _ex_heap.end() ) { @@ -340,7 +365,7 @@ _lock_xheap.unlock(); switch ( k ) { - detail::transport::socket_tcp: + case detail::transport::socket_tcp: if ( reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { // if I detect bad connection during writing to net // (in the push), I remove this connetion related entries. @@ -349,7 +374,7 @@ unsafe_Remove( link ); } break; - detail::transport::unknown: + case detail::transport::unknown: break; default: break; Modified: trunk/complement/explore/lib/stem/EvPack.cc =================================================================== --- trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:06:12 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:19:05 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -12,7 +12,7 @@ */ #include <config/feature.h> -#include "stem/EvPack.h" +#include "stem/Event.h" #include <iterator> #include <iostream> #include <string> @@ -121,6 +121,26 @@ __net_unpack( s, addr ); } +__FIT_DECLSPEC void gaddr_type::_xnet_pack( char *buf ) const +{ + uint64_t _pid = to_net( pid ); + addr_type _addr = to_net( addr ); + + // copy( (char *)hid.u.b, (char *)hid.u.b + 16, buf ); + memcpy( (void *)buf, (const void *)hid.u.b, 16 ); + memcpy( (void *)(buf + 16), &_pid, sizeof(pid) ); + memcpy( (void *)(buf + 16 + sizeof(pid)), &_addr, sizeof(addr_type) ); +} + +__FIT_DECLSPEC void gaddr_type::_xnet_unpack( const char *buf ) +{ + memcpy( (void *)hid.u.b, (const void *)buf, 16 ); + memcpy( (void *)&pid, (const void *)(buf + 16), sizeof(pid) ); + memcpy( (void *)&addr, (const void *)(buf + 16 + sizeof(pid)), sizeof(addr_type) ); + pid = from_net( pid ); + addr = from_net( addr ); +} + __FIT_DECLSPEC bool gaddr_type::operator <( const gaddr_type& ga ) const { if ( hid < ga.hid ) { Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:51:02 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 18:19:55 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -20,10 +20,12 @@ #include "stem/EvManager.h" #include "stem/EDSEv.h" #include <list> +#include <mt/xmt.h> namespace stem { using namespace std; +using namespace xmt; __FIT_DECLSPEC Names::Names() : EventHandler() @@ -44,139 +46,93 @@ { } -void __FIT_DECLSPEC Names::get_list( const Event& rq ) +void __FIT_DECLSPEC Names::ns_list( const Event& rq ) { - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_LIST ); + typedef NameRecords<gaddr_type,string> Seq; + Event_base<Seq> rs( EV_STEM_NS_LIST ); Seq::container_type& lst = rs.value().container; - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) == 0 ) { // only local... - lst.push_back( make_pair((*i).first, (*i).second.info) ); + manager()->_lock_xheap.lock(); + manager()->_lock_iheap.lock(); + for ( EvManager::uuid_ext_heap_type::const_iterator i = manager()->_ui_heap.begin(); i != manager()->_ui_heap.end(); ++i ) { + EvManager::info_heap_type::const_iterator j = manager()->iheap.find( i->second ); + if ( j != manager()->iheap.end() ) { + lst.push_back( make_pair( i->first, j->second ) ); + } else { + lst.push_back( make_pair( i->first, string() ) ); } } - manager()->_lock_heap.unlock(); + manager()->_lock_iheap.unlock(); + manager()->_lock_xheap.unlock(); - if ( rq.code() == EV_STEM_RQ_ADDR_LIST1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NM_LIST ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } + rs.dest( rq.src() ); + Send( rs ); } -void __FIT_DECLSPEC Names::get_ext_list( const Event& rq ) +void __FIT_DECLSPEC Names::ns_name( const Event& rq ) { - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_LIST ); + typedef NameRecords<gaddr_type,string> Seq; + Event_base<Seq> rs( EV_STEM_NS_NAME ); Seq::container_type& lst = rs.value().container; - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::const_iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) != 0 ) { // only external... - lst.push_back( make_pair((*i).first, (*i).second.info) ); + manager()->_lock_iheap.lock(); + for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + if ( i->second == rq.value() ) { + if ( /* i->first & extbit */ true ) { + Locker lk( manager()->_lock_xheap ); + EvManager::ext_uuid_heap_type::const_iterator j = manager()->_ex_heap.find( i->first ); + if ( j != manager()->_ex_heap.end() ) { + lst.push_back( make_pair( j->second, i->second ) ); + } + } else { + Locker lk( manager()->_lock_heap ); + EvManager::local_heap_type::const_iterator j = manager()->heap.find( i->first ); + if ( j != manager()->heap.end() ) { + gaddr_type gaddr; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = j->first; + lst.push_back( make_pair( gaddr, i->second ) ); + } + } } } - manager()->_lock_heap.unlock(); + manager()->_lock_iheap.unlock(); - if ( rq.code() == EV_STEM_RQ_EXT_ADDR_LIST1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NM_LIST ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } + rs.dest( rq.src() ); + Send( rs ); } -void __FIT_DECLSPEC Names::get_by_name( const Event& rq ) -{ - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_NAME ); - Seq::container_type& lst = rs.value().container; - - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::const_iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) == 0 && (*i).second.info == rq.value() ) { // only local... - lst.push_back( make_pair((*i).first, (*i).second.info) ); - } - } - manager()->_lock_heap.unlock(); - - if ( rq.code() == EV_STEM_RQ_ADDR_BY_NAME1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NS_ADDR ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } -} - DEFINE_RESPONSE_TABLE( Names ) - EV_EDS(ST_NULL,EV_EDS_RQ_ADDR_LIST,get_list) - EV_EDS(ST_NULL,EV_STEM_RQ_ADDR_LIST1,get_list) - EV_EDS(ST_NULL,EV_EDS_RQ_EXT_ADDR_LIST,get_ext_list) - EV_EDS(ST_NULL,EV_STEM_RQ_EXT_ADDR_LIST1,get_ext_list) - EV_EDS(ST_NULL,EV_EDS_RQ_ADDR_BY_NAME,get_by_name) - EV_EDS(ST_NULL,EV_STEM_RQ_ADDR_BY_NAME1,get_by_name) + EV_EDS(ST_NULL,EV_STEM_GET_NS_LIST,ns_list) + EV_EDS(ST_NULL,EV_STEM_GET_NS_NAME,ns_name) END_RESPONSE_TABLE __FIT_DECLSPEC void NameRecord::pack( std::ostream& s ) const { - __pack( s, addr ); + addr.pack( s ); __pack( s, record ); } __FIT_DECLSPEC void NameRecord::net_pack( std::ostream& s ) const { - __net_pack( s, addr ); + addr.net_pack( s ); __net_pack( s, record ); } __FIT_DECLSPEC void NameRecord::unpack( std::istream& s ) { - __unpack( s, addr ); + addr.unpack( s ); __unpack( s, record ); } __FIT_DECLSPEC void NameRecord::net_unpack( std::istream& s ) { - __net_unpack( s, addr ); + addr.net_unpack( s ); __net_unpack( s, record ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:09:57 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:09:01 ptr> /* * @@ -105,13 +105,12 @@ } } -bool NetTransport_base::pop( Event& _rs ) +bool NetTransport_base::pop( Event& _rs, gaddr_type& dst, gaddr_type& src ) { - uint32_t buf[8]; + const int bsz = 2+(4+2+1)*2+4; + uint32_t buf[bsz]; using namespace std; - // _STLP_ASSERT( net != 0 ); - // cerr << __FILE__ << ":" << __LINE__ << endl; MT_IO_REENTRANT( *net ) @@ -120,22 +119,21 @@ } // cerr << __FILE__ << ":" << __LINE__ << endl; - // if ( from_net( buf[0] ) != EDS_MAGIC ) { if ( buf[0] != EDS_MAGIC ) { cerr << "EDS Magic fail" << endl; NetTransport_base::close(); return false; } - if ( !net->read( (char *)&buf[1], sizeof(uint32_t) * 7 ).good() ) { + if ( !net->read( (char *)&buf[1], sizeof(uint32_t) * (bsz-1) ).good() ) { return false; } _rs.code( from_net( buf[1] ) ); - _rs.dest( from_net( buf[2] ) ); - _rs.src( from_net( buf[3] ) ); - uint32_t _x_count = from_net( buf[4] ); - uint32_t _x_time = from_net( buf[5] ); // time? - uint32_t sz = from_net( buf[6] ); + dst._xnet_unpack( (const char *)&buf[2] ); + src._xnet_unpack( (const char *)&buf[9] ); + uint32_t _x_count = from_net( buf[16] ); + uint32_t _x_time = from_net( buf[17] ); // time? + uint32_t sz = from_net( buf[18] ); if ( sz >= EDS_MSG_LIMIT ) { cerr << "EDS Message size too big: " << sz << endl; @@ -143,8 +141,8 @@ return false; } - adler32_type adler = adler32( (unsigned char *)buf, sizeof(uint32_t) * 7 ); - if ( adler != from_net( buf[7] ) ) { + adler32_type adler = adler32( (unsigned char *)buf, sizeof(uint32_t) * 19 ); + if ( adler != from_net( buf[19] ) ) { cerr << "EDS Adler-32 fail" << endl; NetTransport_base::close(); return false; @@ -152,18 +150,10 @@ string& str = _rs.value(); - str.erase(); // str.clear(); absent in VC's STL + str.erase(); str.reserve( sz ); -#if defined(_MSC_VER) && (_MSC_VER < 1200) - char ch; -#endif while ( sz-- > 0 ) { -#if defined(_MSC_VER) && (_MSC_VER < 1200) - net->get( ch ); - str += ch; -#else str += (char)net->get(); -#endif } return net->good(); @@ -173,29 +163,28 @@ __FIT_DECLSPEC bool NetTransport_base::push( const Event& _rs, const gaddr_type& dst, const gaddr_type& src ) { - // _STLP_ASSERT( net != 0 ); if ( !net->good() ) { return false; } - // const int bsz = 8-2+(4+2+1)*2; - // uint32_t buf[bsz]; + const int bsz = 2+(4+2+1)*2+4; + uint32_t buf[bsz]; - ostringstream sbuf; // 4 bytes - sbuf.write( (const char *)&EDS_MAGIC, sizeof(EDS_MAGIC) ); // 0 - __pack_base::__net_pack( sbuf, _rs.code() ); // 1 - dst.net_pack( sbuf ); // 2-8 - src.net_pack( sbuf ); // 9-15 + // ostringstream sbuf; // 4 bytes + buf[0] = EDS_MAGIC; + buf[1] = to_net( _rs.code() ); + dst._xnet_pack( reinterpret_cast<char *>(buf + 2) ); + src._xnet_pack( reinterpret_cast<char *>(buf + 9) ); // MT_IO_REENTRANT_W( *net ) MT_IO_LOCK_W( *net ) - __pack_base::__net_pack( sbuf, ++_count ); // 16 - __pack_base::__net_pack( sbuf, 0 ); // 17 time? - __pack_base::__net_pack( sbuf, static_cast<uint32_t>(_rs.value().size()) ); // 18 - __pack_base::__net_pack( sbuf, adler32( (unsigned char *)sbuf.str().c_str(), sizeof(uint32_t) * 19 ) ); // 19 crc + buf[16] = to_net( ++_count ); + buf[17] = 0; // time? + buf[18] = to_net( static_cast<uint32_t>(_rs.value().size()) ); + buf[19] = to_net( adler32( (unsigned char *)buf, sizeof(uint32_t) * 19 )); // crc try { - net->write( sbuf.str().c_str(), sizeof(uint32_t) * 20 ); + net->write( (const char *)buf, sizeof(uint32_t) * 20 ); copy( _rs.value().begin(), _rs.value().end(), ostream_iterator<char,char,char_traits<char> >(*net) ); @@ -207,7 +196,6 @@ } catch ( ios_base::failure& ) { if ( net != 0 ) { // clear connection: required by non-Solaris OS - rar.clear(); // for MP connection policy net->close(); } } @@ -230,10 +218,23 @@ void NetTransport::connect( sockstream& s ) { Event ev; + gaddr_type dst; + gaddr_type src; try { - if ( pop( ev ) ) { - ev.src( rar_map( ev.src(), _at_hostname ) ); // substitute my local id + if ( pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + return; + } + 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 ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } } @@ -285,10 +286,10 @@ } if ( net->good() ) { - _net_ns = rar_map( ns_addr, __ns_at + hostname ); - addr_type zero_object = rar_map( 0, __at + hostname ); + // _net_ns = rar_map( ns_addr, __ns_at + hostname ); + // addr_type zero_object = rar_map( 0, __at + hostname ); _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here - return zero_object; + return 0; // zero_object; } return badaddr; } @@ -313,14 +314,26 @@ xmt::Thread::ret_code NetTransportMgr::_loop( void *p ) { NetTransportMgr& me = *reinterpret_cast<NetTransportMgr *>(p); - heap_type::iterator r; Event ev; xmt::Thread::ret_code rt; rt.iword = 0; + gaddr_type dst; + gaddr_type src; try { - while ( me.pop( ev ) ) { - ev.src( me.rar_map( ev.src(), __at + hostname( me.net->rdbuf()->inet_addr()) ) ); // substitute my local id + while ( me.pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + continue; + } + 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 ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } // cerr << __FILE__ << ":" << __LINE__ << endl; @@ -338,15 +351,25 @@ __FIT_DECLSPEC void NetTransportMP::connect( sockstream& s ) { - const string& _hostname = hostname( s.rdbuf()->inet_addr() ); - // bool sock_dgr = (s.rdbuf()->stype() == std::sock_base::sock_stream) ? false : true; - Event ev; // cerr << "Connected: " << _hostname << endl; + gaddr_type dst; + gaddr_type src; try { - if ( pop( ev ) ) { - ev.src( rar_map( ev.src(), __at + _hostname ) ); // substitute my local id + if ( pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + return; + } + 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 ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } if ( !s.good() ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |