BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
message_oriented_connection.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
26 #include <graphene/net/message.hpp>
27 
28 namespace graphene { namespace net {
29 
30  namespace detail { class message_oriented_connection_impl; }
31 
33 
36  {
37  public:
38  virtual void on_message(message_oriented_connection* originating_connection, const message& received_message) = 0;
39  virtual void on_connection_closed(message_oriented_connection* originating_connection) = 0;
40  };
41 
44  {
45  public:
48  fc::tcp_socket& get_socket();
49 
50  void accept();
51  void bind(const fc::ip::endpoint& local_endpoint);
52  void connect_to(const fc::ip::endpoint& remote_endpoint);
53 
54  void send_message(const message& message_to_send);
55  void close_connection();
56  void destroy_connection();
57 
58  uint64_t get_total_bytes_sent() const;
59  uint64_t get_total_bytes_received() const;
60  fc::time_point get_last_message_sent_time() const;
61  fc::time_point get_last_message_received_time() const;
62  fc::time_point get_connection_time() const;
63  fc::sha512 get_shared_secret() const;
64  private:
65  std::unique_ptr<detail::message_oriented_connection_impl> my;
66  };
67  typedef std::shared_ptr<message_oriented_connection> message_oriented_connection_ptr;
68 
69 } } // graphene::net
Definition: api.cpp:56
void accept(AcceptorType &acc, SocketType &sock)
wraps boost::asio::async_accept
Definition: asio.hpp:251
std::shared_ptr< message_oriented_connection > message_oriented_connection_ptr