Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
levin_base.h
Go to the documentation of this file.
1
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above copyright
9
// notice, this list of conditions and the following disclaimer in the
10
// documentation and/or other materials provided with the distribution.
11
// * Neither the name of the Andrey N. Sabelnikov nor the
12
// names of its contributors may be used to endorse or promote products
13
// derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
//
26
27
28
29
#ifndef _LEVIN_BASE_H_
30
#define _LEVIN_BASE_H_
31
32
#include "
net_utils_base.h
"
33
34
#define LEVIN_SIGNATURE 0x0101010101012101LL
//Bender's nightmare
35
36
namespace
epee
37
{
38
namespace
levin
39
{
40
#pragma pack(push)
41
#pragma pack(1)
42
struct
bucket_head
43
{
44
uint64_t
m_signature
;
45
uint64_t
m_cb
;
46
bool
m_have_to_return_data
;
47
uint32_t
m_command
;
48
int32_t
m_return_code
;
49
uint32_t
m_reservedA
;
//probably some flags in future
50
uint32_t
m_reservedB
;
//probably some check sum in future
51
};
52
#pragma pack(pop)
53
54
55
#pragma pack(push)
56
#pragma pack(1)
57
struct
bucket_head2
58
{
59
uint64_t
m_signature
;
60
uint64_t
m_cb
;
61
bool
m_have_to_return_data
;
62
uint32_t
m_command
;
63
int32_t
m_return_code
;
64
uint32_t
m_flags
;
65
uint32_t
m_protocol_version
;
66
};
67
#pragma pack(pop)
68
69
70
#define LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED 0
71
#define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000
//100MB by default
72
73
#define LEVIN_PACKET_REQUEST 0x00000001
74
#define LEVIN_PACKET_RESPONSE 0x00000002
75
76
77
#define LEVIN_PROTOCOL_VER_0 0
78
#define LEVIN_PROTOCOL_VER_1 1
79
80
template
<
class
t_connection_context = net_utils::connection_context_base>
81
struct
levin_commands_handler
82
{
83
virtual
int
invoke
(
int
command,
const
epee::span<const uint8_t>
in_buff, std::string& buff_out, t_connection_context& context)=0;
84
virtual
int
notify
(
int
command,
const
epee::span<const uint8_t>
in_buff, t_connection_context& context)=0;
85
virtual
void
callback
(t_connection_context& context){};
86
87
virtual
void
on_connection_new
(t_connection_context& context){};
88
virtual
void
on_connection_close
(t_connection_context& context){};
89
90
virtual
~levin_commands_handler
(){}
91
};
92
93
#define LEVIN_OK 0
94
#define LEVIN_ERROR_CONNECTION -1
95
#define LEVIN_ERROR_CONNECTION_NOT_FOUND -2
96
#define LEVIN_ERROR_CONNECTION_DESTROYED -3
97
#define LEVIN_ERROR_CONNECTION_TIMEDOUT -4
98
#define LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL -5
99
#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED -6
100
#define LEVIN_ERROR_FORMAT -7
101
102
#define DESCRIBE_RET_CODE(code) case code: return #code;
103
inline
104
const
char
*
get_err_descr
(
int
err)
105
{
106
switch
(err)
107
{
108
DESCRIBE_RET_CODE
(
LEVIN_OK
);
109
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION
);
110
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION_NOT_FOUND
);
111
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION_DESTROYED
);
112
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION_TIMEDOUT
);
113
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL
);
114
DESCRIBE_RET_CODE
(
LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
);
115
DESCRIBE_RET_CODE
(
LEVIN_ERROR_FORMAT
);
116
default
:
117
return
"unknown code"
;
118
}
119
}
120
121
122
}
123
}
124
125
126
#endif
//_LEVIN_BASE_H_
epee::span
Non-owning sequence of data. Does not deep copy.
Definition
span.h:57
DESCRIBE_RET_CODE
#define DESCRIBE_RET_CODE(code)
Definition
levin_base.h:102
LEVIN_ERROR_CONNECTION
#define LEVIN_ERROR_CONNECTION
Definition
levin_base.h:94
LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL
#define LEVIN_ERROR_CONNECTION_NO_DUPLEX_PROTOCOL
Definition
levin_base.h:98
LEVIN_OK
#define LEVIN_OK
Definition
levin_base.h:93
LEVIN_ERROR_CONNECTION_DESTROYED
#define LEVIN_ERROR_CONNECTION_DESTROYED
Definition
levin_base.h:96
LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
Definition
levin_base.h:99
LEVIN_ERROR_CONNECTION_NOT_FOUND
#define LEVIN_ERROR_CONNECTION_NOT_FOUND
Definition
levin_base.h:95
LEVIN_ERROR_FORMAT
#define LEVIN_ERROR_FORMAT
Definition
levin_base.h:100
LEVIN_ERROR_CONNECTION_TIMEDOUT
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition
levin_base.h:97
epee::levin
Definition
levin_base.h:39
epee::levin::get_err_descr
const char * get_err_descr(int err)
Definition
levin_base.h:104
epee
Definition
ado_db_helper.h:67
net_utils_base.h
uint32_t
unsigned int uint32_t
Definition
stdint.h:126
int32_t
signed int int32_t
Definition
stdint.h:123
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
epee::levin::bucket_head2
Definition
levin_base.h:58
epee::levin::bucket_head2::m_command
uint32_t m_command
Definition
levin_base.h:62
epee::levin::bucket_head2::m_protocol_version
uint32_t m_protocol_version
Definition
levin_base.h:65
epee::levin::bucket_head2::m_flags
uint32_t m_flags
Definition
levin_base.h:64
epee::levin::bucket_head2::m_cb
uint64_t m_cb
Definition
levin_base.h:60
epee::levin::bucket_head2::m_return_code
int32_t m_return_code
Definition
levin_base.h:63
epee::levin::bucket_head2::m_have_to_return_data
bool m_have_to_return_data
Definition
levin_base.h:61
epee::levin::bucket_head2::m_signature
uint64_t m_signature
Definition
levin_base.h:59
epee::levin::bucket_head
Definition
levin_base.h:43
epee::levin::bucket_head::m_have_to_return_data
bool m_have_to_return_data
Definition
levin_base.h:46
epee::levin::bucket_head::m_signature
uint64_t m_signature
Definition
levin_base.h:44
epee::levin::bucket_head::m_return_code
int32_t m_return_code
Definition
levin_base.h:48
epee::levin::bucket_head::m_command
uint32_t m_command
Definition
levin_base.h:47
epee::levin::bucket_head::m_reservedB
uint32_t m_reservedB
Definition
levin_base.h:50
epee::levin::bucket_head::m_cb
uint64_t m_cb
Definition
levin_base.h:45
epee::levin::bucket_head::m_reservedA
uint32_t m_reservedA
Definition
levin_base.h:49
epee::levin::levin_commands_handler
Definition
levin_base.h:82
epee::levin::levin_commands_handler::on_connection_new
virtual void on_connection_new(t_connection_context &context)
Definition
levin_base.h:87
epee::levin::levin_commands_handler::notify
virtual int notify(int command, const epee::span< const uint8_t > in_buff, t_connection_context &context)=0
epee::levin::levin_commands_handler::on_connection_close
virtual void on_connection_close(t_connection_context &context)
Definition
levin_base.h:88
epee::levin::levin_commands_handler::~levin_commands_handler
virtual ~levin_commands_handler()
Definition
levin_base.h:90
epee::levin::levin_commands_handler::callback
virtual void callback(t_connection_context &context)
Definition
levin_base.h:85
epee::levin::levin_commands_handler::invoke
virtual int invoke(int command, const epee::span< const uint8_t > in_buff, std::string &buff_out, t_connection_context &context)=0
contrib
epee
include
net
levin_base.h
Generated on
for Electroneum by
1.17.0