| 32 | }; |
| 33 | |
| 34 | void RpcClientImpl::connect_to(const fc::ip::endpoint& remote_endpoint, |
| 35 | const thinkyoung::blockchain::PublicKeyType& remote_public_key) |
| 36 | { |
| 37 | fc::buffered_istream_ptr buffered_istream; |
| 38 | fc::buffered_ostream_ptr buffered_ostream; |
| 39 | |
| 40 | if (remote_public_key != thinkyoung::blockchain::PublicKeyType()) |
| 41 | { |
| 42 | net::StcpSocketPtr socket = std::make_shared<thinkyoung::net::StcpSocket>(); |
| 43 | |
| 44 | try |
| 45 | { |
| 46 | socket->connect_to(remote_endpoint); |
| 47 | } |
| 48 | catch (const fc::exception& e) |
| 49 | { |
| 50 | elog("fatal: error opening RPC socket to endpoint ${endpoint}: ${e}", ("endpoint", remote_endpoint)("e", e.to_detail_string())); |
| 51 | throw; |
| 52 | } |
| 53 | |
| 54 | std::vector<char> packed_signature(80, ' '); |
| 55 | FC_ASSERT(socket->readsome(packed_signature.data(), packed_signature.size()) == 80, "Unexpected number of bytes read from RPC socket"); |
| 56 | fc::ecc::compact_signature signature; |
| 57 | signature = fc::raw::unpack<fc::ecc::compact_signature>(packed_signature); |
| 58 | wdump((signature)); |
| 59 | FC_ASSERT(blockchain::PublicKeyType(fc::ecc::public_key(signature, fc::digest(socket->get_shared_secret()))) |
| 60 | == remote_public_key, |
| 61 | "Unable to establish secure connection with server."); |
| 62 | |
| 63 | buffered_istream = std::make_shared<fc::buffered_istream>(socket); |
| 64 | buffered_ostream = std::make_shared<utilities::PaddingOstream<>>(socket); |
| 65 | } |
| 66 | else { |
| 67 | fc::tcp_socket_ptr socket = std::make_shared<fc::tcp_socket>(); |
| 68 | |
| 69 | try |
| 70 | { |
| 71 | socket->connect_to(remote_endpoint); |
| 72 | } |
| 73 | catch (const fc::exception& e) |
| 74 | { |
| 75 | elog("fatal: error opening RPC socket to endpoint ${endpoint}: ${e}", ("endpoint", remote_endpoint)("e", e.to_detail_string())); |
| 76 | throw; |
| 77 | } |
| 78 | |
| 79 | buffered_istream = std::make_shared<fc::buffered_istream>(socket); |
| 80 | buffered_ostream = std::make_shared<fc::buffered_ostream>(socket); |
| 81 | } |
| 82 | |
| 83 | _json_connection = std::make_shared<fc::rpc::json_connection>(std::move(buffered_istream), |
| 84 | std::move(buffered_ostream)); |
| 85 | _json_exec_loop_complete = fc::async([=](){ _json_connection->exec(); }, "json exec loop"); |
| 86 | } |
| 87 | bool RpcClientImpl::login(const std::string& username, const std::string& password) |
| 88 | { |
| 89 | return _json_connection->call<bool>("login", username, password); |
no test coverage detected