00001 /*00002 * The Software License00003 * =================================================================================00004 * Copyright (c) 2003-.The Terimber Corporation. All rights reserved.00005 * =================================================================================00006 * Redistributions of source code must retain the above copyright notice, 00007 * this list of conditions and the following disclaimer.00008 * Redistributions in binary form must reproduce the above copyright notice, 00009 * this list of conditions and the following disclaimer in the documentation 00010 * and/or other materials provided with the distribution.00011 * The end-user documentation included with the redistribution, if any, 00012 * must include the following acknowledgment:00013 * "This product includes software developed by the Terimber Corporation."00014 * =================================================================================00015 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00016 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00017 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00018 * IN NO EVENT SHALL THE TERIMBER CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR 00019 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00022 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.00025 * ================================================================================00026 */00027
00028
00029 #ifndef _terimber_msg_conn_h_00030 #define _terimber_msg_conn_h_00031
00032 #include "aiomsg/msg_cpp.h"00033 #include "aiomsg/msg_comm.h"00034 #include "base/primitives.h"00035
00036 BEGIN_TERIMBER_NAMESPACE00037 #pragma pack(4)00038
00040staticconstsize_tqueue_thread_ident = 255;
00041
00044class msg_connection : publicmsg_queue_processor00045 {
00046 protected:
00048enummsg_conn_state00049 {
00050CONN_STATE_CLOSE,
00051CONN_STATE_HANDSHAKE_INITIATOR,
00052CONN_STATE_HANDSHAKE_RECEIVER,
00053CONN_STATE_CONNECTED00054 };
00055 public:
00057 msg_connection( msg_communicator* communicator,
00058 constconf_listener& linfo,
00059 constconf_connection& info
00060 );
00062 msg_connection( msg_communicator* communicator,
00063 constconf_connection& info
00064 );
00066 virtual~msg_connection();
00069 virtual00070 void00071 push_msg( msg_cpp* msg
00072 );
00074 inline00075 constroom_byte_t*
00076get_crypt_key()
00077 {
00078 return_info._support_crypt && _info._crypt_private.size() > 2 ? &_info._crypt_private : 0;
00079 }
00081 inline00082 void00083set_last_activity()
00084 {
00085 mutex_keeper keeper(_mtx_res);
00086 _last_activity = date();
00087 }
00089 inline00090 bool00091is_last_activity_timeout()
00092 {
00093 mutex_keeper keeper(_mtx_res);
00094 return_last_activity.is_time_over(_info._ping);
00095 }
00097 virtual00098 void00099 ping_notify();
00101 inline00102 constconf_connection&
00103get_info()
00104 {
00105 return_info;
00106 }
00107
00109const rsa* get_rsa() const00110 {
00111 return_info._support_crypt ? &_rsa : 0;
00112 }
00113
00114 bool00115is_connected() const00116 {
00117 returnCONN_STATE_CONNECTED == _state;
00118 }
00119
00121 msg_cpp*
00122 prepare_handshake_msg();
00123
00125 msg_cpp*
00126 prepare_handshake_reply(msg_cpp* msg);
00127
00129 void00130 validate_handshake_reply(msg_cpp* msg);
00131
00132 void00133 process_incoming_message(msg_cpp* msg
00134 );
00135
00136 protected:
00138 virtual00139 void00140 wakeup();
00141
00142 protected:
00143conf_connection_info;
00144conf_listener_linfo;
00145msg_conn_state_state;
00146 rsa _rsa;
00147 private:
00148date_last_activity;
00149 };
00150
00151 #pragma pack()00152 END_TERIMBER_NAMESPACE00153
00154 #endif // _terimber_msg_comm_h_00155