FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BitShares/src/application.cpp at master · Xenland/BitShares · GitHub
Xenland
BitShares
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
BitShares
/
src
/
application.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
240 lines (186 loc) · 7.77 KB
Breadcrumbs
BitShares
/
src
/
application.cpp
Copy path
File metadata and controls
240 lines (186 loc) · 7.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#
include
<
bts/application.hpp
>
#
include
<
bts/bitname/bitname_client.hpp
>
#
include
<
bts/bitchat/bitchat_client.hpp
>
#
include
<
bts/network/upnp.hpp
>
#
include
<
fc/reflect/variant.hpp
>
#
include
<
fc/log/logger.hpp
>
namespace
bts
{
namespace
detail
{
class
application_impl
:
public
bts
::bitname::client_delegate,
public bts::bitchat::client_delegate
{
public:
application_impl
()
:_delegate(
nullptr
){}
application_delegate* _delegate;
fc::optional<application_config> _config;
profile_ptr _profile;
fc::path _profile_dir;
bts::network::server_ptr _server;
bts::peer::peer_channel_ptr _peers;
bts::bitname::client_ptr _bitname_client;
bts::bitchat::client_ptr _bitchat_client;
bts::network::upnp_service _upnp;
virtual
void
bitchat_message_received
(
const
bitchat::decrypted_message& m )
{
ilog
(
"
received ${msg}
"
, (
"
msg
"
,m) );
if
( _profile ) _profile->
cache
( m );
switch
( m.
msg_type
)
{
case
bitchat::private_message_type::text_msg:
{
auto
txt = m.
as
<bitchat::private_text_message>();
ilog
(
"
text message ${msg}
"
, (
"
msg
"
,txt) );
if
( _delegate ) _delegate->
received_text
( txt, *m.
from_key
, m.
decrypt_key
->
get_public_key
() );
break
;
}
case
bitchat::private_message_type::email_msg:
{
auto
email = m.
as
<bitchat::private_email_message>();
ilog
(
"
email message ${msg}
"
, (
"
msg
"
,m.
as
<bitchat::private_email_message>()) );
if
( _delegate ) _delegate->
received_email
( email, *m.
from_key
, m.
decrypt_key
->
get_public_key
() );
break
;
}
}
}
virtual
void
bitname_block_added
(
const
bts::bitname::name_block& h )
{
//
ilog( "${h}", ("h",h) );
}
virtual
void
bitname_header_pending
(
const
bts::bitname::name_header& h )
{
//
ilog( "${h}", ("h",h) );
/*
if( h.name_hash == current_name )
{
current_name = fc::time_point::now().time_since_epoch().count();
auto next_name = std::string(fc::time_point::now());
ilog( "registering next name ${name}", ("name",next_name));
_client->mine_name( next_name,
fc::ecc::private_key::generate().get_public_key() );
}
*/
}
};
}
application::application
()
:my(
new
detail::application_impl() )
{
}
application::~application
(){}
void
application::configure
(
const
application_config& cfg )
{
try
{
my->
_config
= cfg;
my->
_profile_dir
= cfg.
data_dir
/
"
profiles
"
;
fc::create_directories
( my->
_profile_dir
);
if
( cfg.
enable_upnp
)
{
my->
_upnp
.
map_port
( cfg.
network_port
);
}
my->
_server
= std::make_shared<bts::network::server>();
bts::network::server::config server_cfg;
server_cfg.
port
= cfg.
network_port
;
my->
_server
->
configure
( server_cfg );
my->
_peers
= std::make_shared<bts::peer::peer_channel>(my->
_server
);
my->
_bitname_client
= std::make_shared<bts::bitname::client>( my->
_peers
);
my->
_bitname_client
->
set_delegate
( my.
get
() );
bitname::client::config bitname_config;
bitname_config.
data_dir
= cfg.
data_dir
/
"
bitname
"
;
my->
_bitname_client
->
configure
( bitname_config );
my->
_bitchat_client
= std::make_shared<bts::bitchat::client>( my->
_peers
, my.
get
() );
my->
_bitchat_client
->
configure
( cfg.
data_dir
/
"
bitchat
"
);
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
, (
"
config
"
,cfg) ) }
application_config
application::get_configuration
()
const
{
FC_ASSERT
( my->
_config
);
return
*my->
_config
;
}
void
application::set_application_delegate
( application_delegate* del )
{
my->
_delegate
= del;
}
bool
application::has_profile
()
const
{
return
fc::exists
( my->
_profile_dir
/
"
default
"
);
}
profile_ptr
application::get_profile
()
{
FC_ASSERT
( my->
_config
);
return
my->
_profile
;
}
profile_ptr
application::load_profile
(
const
std::string& password )
{
try
{
FC_ASSERT
( my->
_config
);
//
note: stored in temp incase open throws.
auto
tmp_profile = std::make_shared<profile>();
tmp_profile->
open
( my->
_profile_dir
/
"
default
"
, password );
std::vector<fc::ecc::private_key> recv_keys;
auto
keychain = tmp_profile->
get_keychain
();
std::vector<identity> idents = tmp_profile->
identities
();
for
(
auto
itr = idents.
begin
(); itr != idents.
end
(); ++itr )
{
recv_keys.
push_back
( keychain.
get_identity_key
( itr->
bit_id
) );
}
my->
_bitchat_client
->
set_receive_keys
( recv_keys );
return
my->
_profile
= tmp_profile;
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
) }
profile_ptr
application::create_profile
(
const
profile_config& cfg,
const
std::string& password )
{
try
{
fc::create_directories
( my->
_profile_dir
);
//
note: stored in temp incase create throws.
auto
tmp_profile = std::make_shared<profile>();
tmp_profile->
create
( my->
_profile_dir
/
"
default
"
, cfg, password );
tmp_profile->
open
( my->
_profile_dir
/
"
default
"
, password );
return
my->
_profile
= tmp_profile;
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
) }
fc::optional<bitname::name_record>
application::lookup_name
(
const
std::string& name )
{
try
{
FC_ASSERT
( my->
_config
);
return
my->
_bitname_client
->
lookup_name
( name );
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
, (
"
name
"
,name) ) }
fc::optional<bitname::name_record>
application::reverse_name_lookup
(
const
fc::ecc::public_key& key )
{
try
{
FC_ASSERT
( my->
_config
);
return
my->
_bitname_client
->
reverse_name_lookup
( key );
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
, (
"
key
"
,key) ) }
void
application::mine_name
(
const
std::string& name,
const
fc::ecc::public_key& key,
float
effort )
{
FC_ASSERT
( my->
_config
);
my->
_bitname_client
->
mine_name
( name, key );
}
void
application::send_contact_request
(
const
fc::ecc::public_key& to,
const
fc::ecc::private_key& from )
{
FC_ASSERT
( my->
_config
);
}
void
application::send_email
(
const
bitchat::private_email_message& email,
const
fc::ecc::public_key& to,
const
fc::ecc::private_key& from )
{
try
{
FC_ASSERT
( my->
_config
);
bitchat::decrypted_message
msg
( email );
msg.
sign
(from);
my->
_bitchat_client
->
send_message
( msg, to,
0
/*
chan 0
*/
);
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
) }
void
application::send_text_message
(
const
bitchat::private_text_message& txtmsg,
const
fc::ecc::public_key& to,
const
fc::ecc::private_key& from )
{
try
{
FC_ASSERT
( my->
_config
);
bitchat::decrypted_message
msg
( txtmsg );
msg.
sign
(from);
my->
_bitchat_client
->
send_message
( msg, to,
0
/*
chan 0
*/
);
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
) }
void
application::add_node
(
const
fc::ip::endpoint& remote_ep )
{
try
{
FC_ASSERT
( my->
_config
);
my->
_server
->
connect_to
(remote_ep);
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
, (
"
endpoint
"
,remote_ep) ) }
void
application::quit
()
{
try
{
my.
reset
();
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
) }
application_ptr
application::instance
()
{
static
application_ptr app = std::make_shared<application>();
return
app;
}
}
//
namespace bts
Back
|
FazBrowse Home
|
New Git URL