7
7
#include " TransactionBuilder.hpp"
8
8
#include " TransactionExtra.hpp"
9
9
#include " common/Math.hpp"
10
- #include " http/Client.hpp"
11
10
#include " http/Server.hpp"
12
11
#include " platform/Time.hpp"
13
12
#include " seria/BinaryInputStream.hpp"
14
13
#include " seria/BinaryOutputStream.hpp"
15
14
#include " seria/KVBinaryInputStream.hpp"
16
15
#include " seria/KVBinaryOutputStream.hpp"
17
16
17
+ #ifndef __EMSCRIPTEN__
18
+ #include " Node.hpp"
19
+ #endif
20
+
18
21
using namespace cn ;
19
22
20
23
const WalletNode::HandlersMap WalletNode::m_jsonrpc_handlers = {
@@ -52,8 +55,10 @@ bool WalletNode::on_api_http_request(http::Client *who, http::RequestBody &&requ
52
55
if (method_found)
53
56
return result;
54
57
}
58
+ #ifndef __EMSCRIPTEN__
55
59
if (m_inproc_node)
56
60
return m_inproc_node->on_json_rpc (who, std::move (request), response);
61
+ #endif
57
62
m_log (logging::INFO) << " http_request node tunneling url=" << request.r .uri
58
63
<< " start of body=" << request.body .substr (0 , 200 );
59
64
http::RequestBody original_request;
@@ -68,15 +73,15 @@ bool WalletNode::on_api_http_request(http::Client *who, http::RequestBody &&requ
68
73
send_response.r .http_version_minor = wc.original_request .r .http_version_minor ;
69
74
send_response.r .keep_alive = wc.original_request .r .keep_alive ;
70
75
// bytecoind never sends connection-close, so we are safe to retain all headers
71
- wc.original_who -> write ( std::move (send_response));
76
+ http::Server::write ( wc.original_who , std::move (send_response));
72
77
},
73
78
[](const WaitingClient &wc, std::string err) {
74
79
http::ResponseBody send_response;
75
80
send_response.r .http_version_major = wc.original_request .r .http_version_major ;
76
81
send_response.r .http_version_minor = wc.original_request .r .http_version_minor ;
77
82
send_response.r .keep_alive = wc.original_request .r .keep_alive ;
78
83
send_response.r .status = 504 ; // TODO -test this code path
79
- wc.original_who -> write ( std::move (send_response));
84
+ http::Server::write ( wc.original_who , std::move (send_response));
80
85
});
81
86
return false ;
82
87
}
@@ -556,6 +561,7 @@ bool WalletNode::on_create_transaction(http::Client *who, http::RequestBody &&ra
556
561
// We ask excess output for the case of collision with our output
557
562
// We ask minimum anonymity, though less than requested might be returned
558
563
ra_request.amounts = selector.get_ra_amounts ();
564
+ #ifndef __EMSCRIPTEN__
559
565
if (m_inproc_node) {
560
566
api::cnd::GetRandomOutputs::Response ra_response;
561
567
m_inproc_node->on_get_random_outputs (
@@ -585,7 +591,7 @@ bool WalletNode::on_create_transaction(http::Client *who, http::RequestBody &&ra
585
591
response.transaction = ptx;
586
592
return true ;
587
593
}
588
-
594
+ # endif
589
595
http::RequestBody new_request =
590
596
json_rpc::create_request (api::cnd::url (), api::cnd::GetRandomOutputs::method (), ra_request);
591
597
new_request.r .basic_authorization = m_config.bytecoind_authorization ;
@@ -632,7 +638,7 @@ bool WalletNode::on_create_transaction(http::Client *who, http::RequestBody &&ra
632
638
last_response.transaction .size = last_response.binary_transaction .size ();
633
639
last_http_response.set_body (json_rpc::create_response_body (last_response, wc.original_jsonrpc_id ));
634
640
}
635
- wc.original_who -> write ( std::move (last_http_response));
641
+ http::Server::write ( wc.original_who , std::move (last_http_response));
636
642
},
637
643
[=](const WaitingClient &wc, std::string err) mutable {
638
644
m_log (logging::INFO) << " got error to get_random_outputs from " CRYPTONOTE_NAME " d, " << err;
@@ -641,7 +647,7 @@ bool WalletNode::on_create_transaction(http::Client *who, http::RequestBody &&ra
641
647
last_http_response.r .status = 200 ;
642
648
last_http_response.set_body (json_rpc::create_error_response_body (
643
649
json_rpc::Error (json_rpc::INTERNAL_ERROR, err), wc.original_jsonrpc_id ));
644
- wc.original_who -> write ( std::move (last_http_response));
650
+ http::Server::write ( wc.original_who , std::move (last_http_response));
645
651
});
646
652
return false ;
647
653
}
@@ -692,7 +698,7 @@ bool WalletNode::on_create_sendproof(http::Client *who, http::RequestBody &&raw_
692
698
last_http_response.r .headers .push_back ({" Content-Type" , " application/json; charset=utf-8" });
693
699
last_http_response.r .status = 200 ;
694
700
last_http_response.set_body (json_rpc::create_response_body (last_response, wc.original_jsonrpc_id ));
695
- wc.original_who -> write ( std::move (last_http_response));
701
+ http::Server::write ( wc.original_who , std::move (last_http_response));
696
702
},
697
703
[=](const WaitingClient &wc, std::string err) mutable {
698
704
m_log (logging::INFO) << " got error to get_raw_transaction from " CRYPTONOTE_NAME " d, " << err;
@@ -701,7 +707,7 @@ bool WalletNode::on_create_sendproof(http::Client *who, http::RequestBody &&raw_
701
707
last_http_response.r .status = 200 ;
702
708
last_http_response.set_body (json_rpc::create_error_response_body (
703
709
json_rpc::Error (json_rpc::INTERNAL_ERROR, err), wc.original_jsonrpc_id ));
704
- wc.original_who -> write ( std::move (last_http_response));
710
+ http::Server::write ( wc.original_who , std::move (last_http_response));
705
711
});
706
712
return false ;
707
713
}
@@ -711,11 +717,13 @@ bool WalletNode::on_send_transaction(http::Client *who, http::RequestBody &&raw_
711
717
api::cnd::SendTransaction::Response &response) {
712
718
m_wallet_state.add_to_payment_queue (request.binary_transaction , true );
713
719
advance_long_poll ();
720
+ #ifndef __EMSCRIPTEN__
714
721
if (m_inproc_node) {
715
722
m_inproc_node->on_send_transaction (
716
723
nullptr , std::move (raw_request), std::move (raw_js_request), std::move (request), response);
717
724
return true ;
718
725
}
726
+ #endif
719
727
http::RequestBody new_request;
720
728
new_request.set_body (std::move (raw_request.body )); // We save on copying body here
721
729
new_request.r .set_firstline (" POST" , api::cnd::url (), 1 , 1 );
@@ -726,15 +734,15 @@ bool WalletNode::on_send_transaction(http::Client *who, http::RequestBody &&raw_
726
734
resp.r .http_version_major = wc2.original_request .r .http_version_major ;
727
735
resp.r .http_version_minor = wc2.original_request .r .http_version_minor ;
728
736
resp.r .keep_alive = wc2.original_request .r .keep_alive ;
729
- wc2.original_who -> write ( std::move (resp));
737
+ http::Server::write ( wc2.original_who , std::move (resp));
730
738
},
731
739
[](const WaitingClient &wc2, std::string err) {
732
740
http::ResponseBody resp (wc2.original_request .r );
733
741
resp.r .headers .push_back ({" Content-Type" , " application/json; charset=utf-8" });
734
742
resp.r .status = 200 ;
735
743
resp.set_body (json_rpc::create_error_response_body (
736
744
json_rpc::Error (json_rpc::INTERNAL_ERROR, err), wc2.original_jsonrpc_id ));
737
- wc2.original_who -> write ( std::move (resp));
745
+ http::Server::write ( wc2.original_who , std::move (resp));
738
746
});
739
747
return false ;
740
748
}
@@ -819,15 +827,18 @@ void WalletNode::advance_long_poll() {
819
827
820
828
for (auto lit = m_long_poll_http_clients.begin (); lit != m_long_poll_http_clients.end ();)
821
829
if (resp.ready_for_longpoll (lit->original_get_status )) {
830
+ LongPollClient cli = std::move (*lit);
831
+ lit = m_long_poll_http_clients.erase (lit);
832
+ // We erase first, because on some platforms on_api_http_disconnect will be called
833
+ // synchronously in Server::write, and will also attempt to erase from m_long_poll_http_clients
822
834
http::ResponseBody last_http_response;
823
835
last_http_response.r .headers .push_back ({" Content-Type" , " application/json; charset=utf-8" });
824
836
last_http_response.r .status = 200 ;
825
- last_http_response.r .http_version_major = lit->original_request .r .http_version_major ;
826
- last_http_response.r .http_version_minor = lit->original_request .r .http_version_minor ;
827
- last_http_response.r .keep_alive = lit->original_request .r .keep_alive ;
828
- last_http_response.set_body (json_rpc::create_response_body (resp, lit->original_jsonrpc_id ));
829
- lit->original_who ->write (std::move (last_http_response));
830
- lit = m_long_poll_http_clients.erase (lit);
837
+ last_http_response.r .http_version_major = cli.original_request .r .http_version_major ;
838
+ last_http_response.r .http_version_minor = cli.original_request .r .http_version_minor ;
839
+ last_http_response.r .keep_alive = cli.original_request .r .keep_alive ;
840
+ last_http_response.set_body (json_rpc::create_response_body (resp, cli.original_jsonrpc_id ));
841
+ http::Server::write (cli.original_who , std::move (last_http_response));
831
842
} else
832
843
++lit;
833
844
}
0 commit comments