28
28
#include < iostream>
29
29
#include < iomanip>
30
30
#include < string>
31
- #include < cstring>
32
- #include < cassert>
33
- #include " crypto/ellcurve/Ed25519.h"
34
31
#include " adnl/utils.hpp"
35
32
#include " auto/tl/ton_api.h"
36
33
#include " auto/tl/ton_api_json.h"
37
34
#include " tl/tl_json.h"
38
35
#include " td/utils/OptionParser.h"
39
36
#include " td/utils/filesystem.h"
40
37
#include " keys/encryptor.h"
41
- #include " keys/keys.hpp"
42
38
#include " git.h"
39
+ #include " dht/dht-node.hpp"
43
40
44
41
int main (int argc, char *argv[]) {
45
42
ton::PrivateKey pk;
46
- ton::tl_object_ptr<ton::ton_api::adnl_addressList> addr_list;
43
+ td::optional<ton::adnl::AdnlAddressList> addr_list;
44
+ td::optional<td::int32> network_id_opt;
47
45
48
46
td::OptionParser p;
49
47
p.set_description (" generate random id" );
@@ -78,11 +76,19 @@ int main(int argc, char *argv[]) {
78
76
if (addr_list) {
79
77
return td::Status::Error (" duplicate '-a' option" );
80
78
}
81
- CHECK (!addr_list);
82
79
83
80
td::BufferSlice bs (key);
84
81
TRY_RESULT_PREFIX (as_json_value, td::json_decode (bs.as_slice ()), " bad addr list JSON: " );
85
- TRY_STATUS_PREFIX (td::from_json (addr_list, std::move (as_json_value)), " bad addr list TL: " );
82
+ ton::tl_object_ptr<ton::ton_api::adnl_addressList> addr_list_tl;
83
+ TRY_STATUS_PREFIX (td::from_json (addr_list_tl, std::move (as_json_value)), " bad addr list TL: " );
84
+ TRY_RESULT_PREFIX_ASSIGN (addr_list, ton::adnl::AdnlAddressList::create (addr_list_tl), " bad addr list: " );
85
+ return td::Status::OK ();
86
+ });
87
+ p.add_checked_option (' i' , " network-id" , " dht network id (default: -1)" , [&](td::Slice key) {
88
+ if (network_id_opt) {
89
+ return td::Status::Error (" duplicate '-i' option" );
90
+ }
91
+ TRY_RESULT_PREFIX_ASSIGN (network_id_opt, td::to_integer_safe<td::int32>(key), " bad network id: " );
86
92
return td::Status::OK ();
87
93
});
88
94
@@ -118,7 +124,7 @@ int main(int argc, char *argv[]) {
118
124
std::cerr << " '-a' option missing" << std::endl;
119
125
return 2 ;
120
126
}
121
- auto x = ton::create_tl_object<ton::ton_api::adnl_node>(pub_key.tl (), std::move ( addr_list));
127
+ auto x = ton::create_tl_object<ton::ton_api::adnl_node>(pub_key.tl (), addr_list. value (). tl ( ));
122
128
auto e = pk.create_decryptor ().move_as_ok ();
123
129
auto r = e->sign (ton::serialize_tl_object (x, true ).as_slice ()).move_as_ok ();
124
130
@@ -129,12 +135,17 @@ int main(int argc, char *argv[]) {
129
135
std::cerr << " '-a' option missing" << std::endl;
130
136
return 2 ;
131
137
}
132
- auto x = ton::create_tl_object<ton::ton_api::dht_node>(pub_key.tl (), std::move (addr_list), -1 , td::BufferSlice ());
138
+ td::int32 network_id = network_id_opt ? network_id_opt.value () : -1 ;
139
+ td::BufferSlice to_sign = ton::serialize_tl_object (
140
+ ton::dht::DhtNode{ton::adnl::AdnlNodeIdFull{pub_key}, addr_list.value (), -1 , network_id, td::BufferSlice{}}
141
+ .tl (),
142
+ true );
133
143
auto e = pk.create_decryptor ().move_as_ok ();
134
- auto r = e->sign (ton::serialize_tl_object (x, true ).as_slice ()).move_as_ok ();
135
- x->signature_ = std::move (r);
144
+ auto signature = e->sign (to_sign.as_slice ()).move_as_ok ();
145
+ auto node =
146
+ ton::dht::DhtNode{ton::adnl::AdnlNodeIdFull{pub_key}, addr_list.value (), -1 , network_id, std::move (signature)};
136
147
137
- auto v = td::json_encode<std::string>(td::ToJson (x ));
148
+ auto v = td::json_encode<std::string>(td::ToJson (node. tl () ));
138
149
std::cout << v << " \n " ;
139
150
} else if (mode == " keys" ) {
140
151
td::write_file (name, pk.export_as_slice ()).ensure ();
0 commit comments