void HostTab::getHosts( void ) { hosts.clear(); if( !connection || !*connection ) { return; } uint8_t cmd = CMD_PSTAT; boost::asio::write(connection->socket(),boost::asio::buffer(&cmd,1)); size_t blockSize; uint64_t count(0); shared_ptr<char> buf = connection->receiveBlock( blockSize ); if( !blockSize ) return; const char* ptr = buf.get(); try { Host host; while( count < blockSize ) { count += host.unpack( ptr+count, swap_endian ); hosts.insert( Host::Ptr(new Host(host.info)) ); } } catch( const exception& e ) { cout << "getPeers: Exception caught while parsing block: " << e.what() << endl; } if( count != blockSize ) { cout << "getPeers: Parsing of datablock failed, count = " << count << " blockSize = " << blockSize << " bytes." << endl; } }
void printPeerList( TcpConnection::Ptr conn, int ns ) { uint8_t cmd = CMD_PSTAT; boost::asio::write(conn->socket(),boost::asio::buffer(&cmd,1)); uint64_t blockSize; shared_ptr<char> buf = conn->receiveBlock( blockSize ); if ( !blockSize ) return; const char* ptr = buf.get(); uint64_t count(0); try { Host peer; cout << " " << peer.printHeader() << endl; int hostCount(0); while( count < blockSize ) { count += peer.unpack(ptr+count,conn->getSwapEndian()); if ( hostCount == 0 ) cout << " " << peer.print() << endl; else if ( ns==0 || hostCount < ns) cout << alignRight(to_string(hostCount),4) << peer.print() << endl; hostCount++; } if (ns!=0 && hostCount > ns) cout << " :" << endl << alignRight(to_string(hostCount),4) << peer.print() << endl; } catch ( const exception& e) { cerr << "printPeerList: Exception caught while parsing block: " << e.what() << endl; } if( count != blockSize ) { cerr << "printPeerList: Parsing of datablock failed, count = " << count << " blockSize = " << blockSize << " bytes." << endl; } }