29
29
30
30
#include < fc/io/json.hpp>
31
31
#include < fc/io/stdio.hpp>
32
- #include < fc/network/http/server.hpp>
33
32
#include < fc/network/http/websocket.hpp>
34
33
#include < fc/rpc/cli.hpp>
35
34
#include < fc/rpc/http_api.hpp>
@@ -77,10 +76,12 @@ int main( int argc, char** argv )
77
76
(" server-rpc-endpoint,s" , bpo::value<string>()->implicit_value (" ws://127.0.0.1:8090" ), " Server websocket RPC endpoint" )
78
77
(" server-rpc-user,u" , bpo::value<string>(), " Server Username" )
79
78
(" server-rpc-password,p" , bpo::value<string>(), " Server Password" )
80
- (" rpc-endpoint,r" , bpo::value<string>()->implicit_value (" 127.0.0.1:8091" ), " Endpoint for wallet websocket RPC to listen on" )
79
+ (" rpc-endpoint,r" , bpo::value<string>()->implicit_value (" 127.0.0.1:8091" ),
80
+ " Endpoint for wallet websocket RPC to listen on (DEPRECATED, use rpc-http-endpoint instead)" )
81
81
(" rpc-tls-endpoint,t" , bpo::value<string>()->implicit_value (" 127.0.0.1:8092" ), " Endpoint for wallet websocket TLS RPC to listen on" )
82
82
(" rpc-tls-certificate,c" , bpo::value<string>()->implicit_value (" server.pem" ), " PEM certificate for wallet websocket TLS RPC" )
83
- (" rpc-http-endpoint,H" , bpo::value<string>()->implicit_value (" 127.0.0.1:8093" ), " Endpoint for wallet HTTP RPC to listen on" )
83
+ (" rpc-http-endpoint,H" , bpo::value<string>()->implicit_value (" 127.0.0.1:8093" ),
84
+ " Endpoint for wallet HTTP and websocket RPC to listen on" )
84
85
(" daemon,d" , " Run the wallet in daemon mode" )
85
86
(" wallet-file,w" , bpo::value<string>()->implicit_value (" wallet.json" ), " wallet to load" )
86
87
(" chain-id" , bpo::value<string>(), " chain ID to connect to" )
@@ -205,15 +206,16 @@ int main( int argc, char** argv )
205
206
206
207
fc::api<wallet_api> wapi (wapiptr);
207
208
208
- auto _websocket_server = std::make_shared <fc::http::websocket_server>() ;
209
+ std::shared_ptr <fc::http::websocket_server> _websocket_server ;
209
210
if ( options.count (" rpc-endpoint" ) )
210
211
{
212
+ _websocket_server = std::make_shared<fc::http::websocket_server>();
211
213
_websocket_server->on_connection ([&wapi]( const fc::http::websocket_connection_ptr& c ){
212
214
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
213
215
wsc->register_api (wapi);
214
216
c->set_session_data ( wsc );
215
217
});
216
- ilog ( " Listening for incoming RPC requests on ${p}" , (" p" , options.at (" rpc-endpoint" ).as <string>() ));
218
+ ilog ( " Listening for incoming HTTP and WS RPC requests on ${p}" , (" p" , options.at (" rpc-endpoint" ).as <string>() ));
217
219
_websocket_server->listen ( fc::ip::endpoint::from_string (options.at (" rpc-endpoint" ).as <string>()) );
218
220
_websocket_server->start_accept ();
219
221
}
@@ -222,37 +224,34 @@ int main( int argc, char** argv )
222
224
if ( options.count ( " rpc-tls-certificate" ) )
223
225
cert_pem = options.at (" rpc-tls-certificate" ).as <string>();
224
226
225
- auto _websocket_tls_server = std::make_shared <fc::http::websocket_tls_server>(cert_pem) ;
227
+ std::shared_ptr <fc::http::websocket_tls_server> _websocket_tls_server ;
226
228
if ( options.count (" rpc-tls-endpoint" ) )
227
229
{
230
+ _websocket_tls_server = std::make_shared<fc::http::websocket_tls_server>(cert_pem);
228
231
_websocket_tls_server->on_connection ([&wapi]( const fc::http::websocket_connection_ptr& c ){
229
232
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
230
233
wsc->register_api (wapi);
231
234
c->set_session_data ( wsc );
232
235
});
233
- ilog ( " Listening for incoming TLS RPC requests on ${p}" ,
236
+ ilog ( " Listening for incoming HTTPS and WSS RPC requests on ${p}" ,
234
237
(" p" , options.at (" rpc-tls-endpoint" ).as <string>()) );
235
238
_websocket_tls_server->listen ( fc::ip::endpoint::from_string (options.at (" rpc-tls-endpoint" ).as <string>()) );
236
239
_websocket_tls_server->start_accept ();
237
240
}
238
241
239
- auto _http_server = std::make_shared <fc::http::server>() ;
242
+ std::shared_ptr <fc::http::websocket_server> _http_ws_server ;
240
243
if ( options.count (" rpc-http-endpoint" ) )
241
244
{
242
- ilog ( " Listening for incoming HTTP RPC requests on ${p}" ,
245
+ _http_ws_server = std::make_shared<fc::http::websocket_server>();
246
+ ilog ( " Listening for incoming HTTP and WS RPC requests on ${p}" ,
243
247
(" p" , options.at (" rpc-http-endpoint" ).as <string>()) );
244
- _http_server->listen ( fc::ip::endpoint::from_string ( options.at ( " rpc-http-endpoint" ).as <string>() ) );
245
- //
246
- // due to implementation, on_request() must come AFTER listen()
247
- //
248
- _http_server->on_request (
249
- [&wapi]( const fc::http::request& req, const fc::http::server::response& resp )
250
- {
251
- std::shared_ptr< fc::rpc::http_api_connection > conn =
252
- std::make_shared< fc::rpc::http_api_connection >( GRAPHENE_MAX_NESTED_OBJECTS );
253
- conn->register_api ( wapi );
254
- conn->on_request ( req, resp );
255
- } );
248
+ _http_ws_server->on_connection ([&wapi]( const fc::http::websocket_connection_ptr& c ){
249
+ auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
250
+ wsc->register_api (wapi);
251
+ c->set_session_data ( wsc );
252
+ });
253
+ _http_ws_server->listen ( fc::ip::endpoint::from_string (options.at (" rpc-http-endpoint" ).as <string>()) );
254
+ _http_ws_server->start_accept ();
256
255
}
257
256
258
257
if ( !options.count ( " daemon" ) )
0 commit comments