]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/rscript/rscript.cpp
Hide or add proper copy ctor and assignement operator, initialize
[stg.git] / projects / stargazer / plugins / other / rscript / rscript.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 /*
23  $Revision: 1.33 $
24  $Date: 2010/04/16 12:30:37 $
25  $Author: faust $
26 */
27
28 #include <sys/time.h>
29
30 #include <csignal>
31 #include <cassert>
32 #include <cstdlib>
33 #include <algorithm>
34
35 #include "stg/common.h"
36 #include "stg/locker.h"
37 #include "stg/user_property.h"
38 #include "stg/plugin_creator.h"
39 #include "rscript.h"
40 #include "ur_functor.h"
41 #include "send_functor.h"
42
43 extern volatile const time_t stgTime;
44
45 #define RS_MAX_ROUTERS  (100)
46
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 PLUGIN_CREATOR<REMOTE_SCRIPT> rsc;
51 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 PLUGIN * GetPlugin()
55 {
56 return rsc.GetPlugin();
57 }
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 RS_USER & RS_USER::operator=(const RS_USER & rvalue)
62 {
63 lastSentTime = rvalue.lastSentTime;
64 user = rvalue.user;
65 routers = rvalue.routers;
66 shortPacketsCount = rvalue.shortPacketsCount;
67 return *this;
68 }
69 //-----------------------------------------------------------------------------
70 RS_SETTINGS::RS_SETTINGS()
71     : sendPeriod(0),
72       port(0),
73       errorStr(),
74       netRouters(),
75       userParams(),
76       password(),
77       subnetFile()
78 {
79 }
80 //-----------------------------------------------------------------------------
81 int RS_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
82 {
83 int p;
84 PARAM_VALUE pv;
85 vector<PARAM_VALUE>::const_iterator pvi;
86 netRouters.clear();
87 ///////////////////////////
88 pv.param = "Port";
89 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
90 if (pvi == s.moduleParams.end())
91     {
92     errorStr = "Parameter \'Port\' not found.";
93     printfd(__FILE__, "Parameter 'Port' not found\n");
94     return -1;
95     }
96 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
97     {
98     errorStr = "Cannot parse parameter \'Port\': " + errorStr;
99     printfd(__FILE__, "Cannot parse parameter 'Port'\n");
100     return -1;
101     }
102 port = p;
103 ///////////////////////////
104 pv.param = "SendPeriod";
105 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
106 if (pvi == s.moduleParams.end())
107     {
108     errorStr = "Parameter \'SendPeriod\' not found.";
109     printfd(__FILE__, "Parameter 'SendPeriod' not found\n");
110     return -1;
111     }
112
113 if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod))
114     {
115     errorStr = "Cannot parse parameter \'SendPeriod\': " + errorStr;
116     printfd(__FILE__, "Cannot parse parameter 'SendPeriod'\n");
117     return -1;
118     }
119 ///////////////////////////
120 pv.param = "UserParams";
121 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
122 if (pvi == s.moduleParams.end())
123     {
124     errorStr = "Parameter \'UserParams\' not found.";
125     printfd(__FILE__, "Parameter 'UserParams' not found\n");
126     return -1;
127     }
128 userParams = pvi->value;
129 ///////////////////////////
130 pv.param = "Password";
131 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
132 if (pvi == s.moduleParams.end())
133     {
134     errorStr = "Parameter \'Password\' not found.";
135     printfd(__FILE__, "Parameter 'Password' not found\n");
136     return -1;
137     }
138 password = pvi->value[0];
139 ///////////////////////////
140 pv.param = "SubnetFile";
141 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
142 if (pvi == s.moduleParams.end())
143     {
144     errorStr = "Parameter \'SubnetFile\' not found.";
145     printfd(__FILE__, "Parameter 'SubnetFile' not found\n");
146     return -1;
147     }
148 subnetFile = pvi->value[0];
149
150 NRMapParser nrMapParser;
151
152 if (nrMapParser.ReadFile(subnetFile))
153     {
154     errorStr = nrMapParser.GetErrorStr();
155     return -1;
156     }
157
158 netRouters = nrMapParser.GetMap();
159
160 if (netRouters.empty())
161     {
162     errorStr = "Parameter(s) \'Subnet*\' not found.";
163     printfd(__FILE__, "Parameter(s) 'Subnet*' not found\n");
164     return -1;
165     }
166
167 return 0;
168 }
169 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
172 REMOTE_SCRIPT::REMOTE_SCRIPT()
173     : ctx(),
174       afterChgIPNotifierList(),
175       authorizedUsers(),
176       errorStr(),
177       rsSettings(),
178       settings(),
179       sendPeriod(15),
180       halfPeriod(8),
181       nonstop(false),
182       isRunning(false),
183       users(NULL),
184       netRouters(),
185       thread(),
186       mutex(),
187       sock(0),
188       onAddUserNotifier(*this),
189       onDelUserNotifier(*this)
190 {
191 pthread_mutex_init(&mutex, NULL);
192 }
193 //-----------------------------------------------------------------------------
194 REMOTE_SCRIPT::~REMOTE_SCRIPT()
195 {
196 pthread_mutex_destroy(&mutex);
197 }
198 //-----------------------------------------------------------------------------
199 void * REMOTE_SCRIPT::Run(void * d)
200 {
201 REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
202
203 rs->isRunning = true;
204
205 while (rs->nonstop)
206     {
207     rs->PeriodicSend();
208     sleep(2);
209     }
210
211 rs->isRunning = false;
212 return NULL;
213 }
214 //-----------------------------------------------------------------------------
215 int REMOTE_SCRIPT::ParseSettings()
216 {
217 int ret = rsSettings.ParseSettings(settings);
218 if (ret)
219     errorStr = rsSettings.GetStrError();
220
221 sendPeriod = rsSettings.GetSendPeriod();
222 halfPeriod = sendPeriod / 2;
223
224 return ret;
225 }
226 //-----------------------------------------------------------------------------
227 int REMOTE_SCRIPT::Start()
228 {
229 netRouters = rsSettings.GetSubnetsMap();
230
231 InitEncrypt(&ctx, rsSettings.GetPassword());
232
233 //onAddUserNotifier.SetRemoteScript(this);
234 //onDelUserNotifier.SetRemoteScript(this);
235
236 users->AddNotifierUserAdd(&onAddUserNotifier);
237 users->AddNotifierUserDel(&onDelUserNotifier);
238
239 nonstop = true;
240
241 if (GetUsers())
242     {
243     return -1;
244     }
245
246 if (PrepareNet())
247     {
248     return -1;
249     }
250
251 if (!isRunning)
252     {
253     if (pthread_create(&thread, NULL, Run, this))
254         {
255         errorStr = "Cannot create thread.";
256         printfd(__FILE__, "Cannot create thread\n");
257         return -1;
258         }
259     }
260
261 errorStr = "";
262 return 0;
263 }
264 //-----------------------------------------------------------------------------
265 int REMOTE_SCRIPT::Stop()
266 {
267 if (!IsRunning())
268     return 0;
269
270 nonstop = false;
271
272 std::for_each(
273         authorizedUsers.begin(),
274         authorizedUsers.end(),
275         DisconnectUser(*this)
276         );
277
278 FinalizeNet();
279
280 if (isRunning)
281     {
282     //5 seconds to thread stops itself
283     for (int i = 0; i < 25 && isRunning; i++)
284         {
285         usleep(200000);
286         }
287
288     //after 5 seconds waiting thread still running. now killing it
289     if (isRunning)
290         {
291         if (pthread_kill(thread, SIGINT))
292             {
293             errorStr = "Cannot kill thread.";
294             printfd(__FILE__, "Cannot kill thread\n");
295             return -1;
296             }
297         printfd(__FILE__, "REMOTE_SCRIPT killed Run\n");
298         }
299     }
300
301 users->DelNotifierUserDel(&onDelUserNotifier);
302 users->DelNotifierUserAdd(&onAddUserNotifier);
303
304 return 0;
305 }
306 //-----------------------------------------------------------------------------
307 int REMOTE_SCRIPT::Reload()
308 {
309 NRMapParser nrMapParser;
310
311 if (nrMapParser.ReadFile(rsSettings.GetMapFileName()))
312     {
313     errorStr = nrMapParser.GetErrorStr();
314     return -1;
315     }
316
317     {
318     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
319
320     printfd(__FILE__, "REMOTE_SCRIPT::Reload()\n");
321
322     netRouters = nrMapParser.GetMap();
323     }
324
325 std::for_each(authorizedUsers.begin(),
326               authorizedUsers.end(),
327               UpdateRouter(*this));
328
329 return 0;
330 }
331 //-----------------------------------------------------------------------------
332 bool REMOTE_SCRIPT::PrepareNet()
333 {
334 sock = socket(AF_INET, SOCK_DGRAM, 0);
335
336 if (sock < 0)
337     {
338     errorStr = "Cannot create socket.";
339     printfd(__FILE__, "Cannot create socket\n");
340     return true;
341     }
342
343 return false;
344 }
345 //-----------------------------------------------------------------------------
346 bool REMOTE_SCRIPT::FinalizeNet()
347 {
348 close(sock);
349 return false;
350 }
351 //-----------------------------------------------------------------------------
352 void REMOTE_SCRIPT::PeriodicSend()
353 {
354 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
355
356 map<uint32_t, RS_USER>::iterator it(authorizedUsers.begin());
357 while (it != authorizedUsers.end())
358     {
359     if (difftime(stgTime, it->second.lastSentTime) - (rand() % halfPeriod) > sendPeriod)
360     //if (stgTime - it->second.lastSentTime > sendPeriod)
361         {
362         Send(it->first, it->second);
363         }
364     ++it;
365     }
366 }
367 //-----------------------------------------------------------------------------
368 #ifdef NDEBUG
369 bool REMOTE_SCRIPT::PreparePacket(char * buf, size_t, uint32_t ip, RS_USER & rsu, bool forceDisconnect) const
370 #else
371 bool REMOTE_SCRIPT::PreparePacket(char * buf, size_t bufSize, uint32_t ip, RS_USER & rsu, bool forceDisconnect) const
372 #endif
373 {
374 RS_PACKET_HEADER packetHead;
375
376 memset(packetHead.padding, 0, sizeof(packetHead.padding));
377 strcpy((char*)packetHead.magic, RS_ID);
378 packetHead.protoVer[0] = '0';
379 packetHead.protoVer[1] = '2';
380 if (forceDisconnect)
381     {
382     packetHead.packetType = RS_DISCONNECT_PACKET;
383     }
384 else
385     {
386     if (rsu.shortPacketsCount % MAX_SHORT_PCKT == 0)
387         {
388         //SendLong
389         packetHead.packetType = rsu.user->IsInetable() ? RS_CONNECT_PACKET : RS_DISCONNECT_PACKET;
390         }
391     else
392         {
393         //SendShort
394         packetHead.packetType = rsu.user->IsInetable() ? RS_ALIVE_PACKET : RS_DISCONNECT_PACKET;
395         }
396     }
397 rsu.shortPacketsCount++;
398 rsu.lastSentTime = stgTime;
399
400 packetHead.ip = htonl(ip);
401 packetHead.id = htonl(rsu.user->GetID());
402 strncpy((char*)packetHead.login, rsu.user->GetLogin().c_str(), RS_LOGIN_LEN);
403 packetHead.login[RS_LOGIN_LEN - 1] = 0;
404
405 memcpy(buf, &packetHead, sizeof(packetHead));
406
407 if (packetHead.packetType == RS_ALIVE_PACKET)
408     {
409     return false;
410     }
411
412 RS_PACKET_TAIL packetTail;
413
414 memset(packetTail.padding, 0, sizeof(packetTail.padding));
415 strcpy((char*)packetTail.magic, RS_ID);
416 vector<string>::const_iterator it;
417 std::string params;
418 for(it = rsSettings.GetUserParams().begin();
419     it != rsSettings.GetUserParams().end();
420     ++it)
421     {
422     std::string parameter(GetUserParam(rsu.user, *it));
423     if (params.length() + parameter.length() > RS_PARAMS_LEN - 1)
424         break;
425     params += parameter + " ";
426     }
427 strncpy((char *)packetTail.params, params.c_str(), RS_PARAMS_LEN);
428 packetTail.params[RS_PARAMS_LEN - 1] = 0;
429
430 assert(sizeof(packetHead) + sizeof(packetTail) <= bufSize && "Insufficient buffer space");
431
432 Encrypt(&ctx, buf + sizeof(packetHead), (char *)&packetTail, sizeof(packetTail) / 8);
433
434 return false;
435 }
436 //-----------------------------------------------------------------------------
437 bool REMOTE_SCRIPT::Send(uint32_t ip, RS_USER & rsu, bool forceDisconnect) const
438 {
439 char buffer[RS_MAX_PACKET_LEN];
440
441 memset(buffer, 0, sizeof(buffer));
442
443 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
444     {
445     printfd(__FILE__, "REMOTE_SCRIPT::Send() - Invalid packet length!\n");
446     return true;
447     }
448
449 std::for_each(
450         rsu.routers.begin(),
451         rsu.routers.end(),
452         PacketSender(sock, buffer, sizeof(buffer), htons(rsSettings.GetPort()))
453         );
454
455 return false;
456 }
457 //-----------------------------------------------------------------------------
458 bool REMOTE_SCRIPT::SendDirect(uint32_t ip, RS_USER & rsu, uint32_t routerIP, bool forceDisconnect) const
459 {
460 char buffer[RS_MAX_PACKET_LEN];
461
462 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
463     {
464     printfd(__FILE__, "REMOTE_SCRIPT::SendDirect() - Invalid packet length!\n");
465     return true;
466     }
467
468 struct sockaddr_in sendAddr;
469
470 sendAddr.sin_family = AF_INET;
471 sendAddr.sin_port = htons(rsSettings.GetPort());
472 sendAddr.sin_addr.s_addr = routerIP;
473
474 int res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr));
475
476 return (res != sizeof(buffer));
477 }
478 //-----------------------------------------------------------------------------
479 bool REMOTE_SCRIPT::GetUsers()
480 {
481 USER_PTR u;
482
483 int h = users->OpenSearch();
484 if (!h)
485     {
486     errorStr = "users->OpenSearch() error.";
487     printfd(__FILE__, "OpenSearch() error\n");
488     return true;
489     }
490
491 while (!users->SearchNext(h, &u))
492     {
493     SetUserNotifier(u);
494     }
495
496 users->CloseSearch(h);
497 return false;
498 }
499 //-----------------------------------------------------------------------------
500 void REMOTE_SCRIPT::ChangedIP(USER_PTR u, uint32_t oldIP, uint32_t newIP)
501 {
502 /*
503  * When ip changes process looks like:
504  * old => 0, 0 => new
505  *
506  */
507 if (newIP)
508     {
509     RS_USER rsu(IP2Routers(newIP), u);
510     Send(newIP, rsu);
511
512     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
513     authorizedUsers[newIP] = rsu;
514     }
515 else
516     {
517     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
518     const map<uint32_t, RS_USER>::iterator it(
519             authorizedUsers.find(oldIP)
520             );
521     if (it != authorizedUsers.end())
522         {
523         Send(oldIP, it->second, true);
524         authorizedUsers.erase(it);
525         }
526     }
527 }
528 //-----------------------------------------------------------------------------
529 std::vector<uint32_t> REMOTE_SCRIPT::IP2Routers(uint32_t ip)
530 {
531 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
532 for (size_t i = 0; i < netRouters.size(); ++i)
533     {
534     if ((ip & netRouters[i].subnetMask) == (netRouters[i].subnetIP & netRouters[i].subnetMask))
535         {
536         return netRouters[i].routers;
537         }
538     }
539 return std::vector<uint32_t>();
540 }
541 //-----------------------------------------------------------------------------
542 string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const string & paramName) const
543 {
544 string value = "";
545 if (strcasecmp(paramName.c_str(), "cash") == 0)
546     strprintf(&value, "%f", u->GetProperty().cash.Get());
547 else
548 if (strcasecmp(paramName.c_str(), "freeMb") == 0)
549     strprintf(&value, "%f", u->GetProperty().freeMb.Get());
550 else
551 if (strcasecmp(paramName.c_str(), "passive") == 0)
552     strprintf(&value, "%d", u->GetProperty().passive.Get());
553 else
554 if (strcasecmp(paramName.c_str(), "disabled") == 0)
555     strprintf(&value, "%d", u->GetProperty().disabled.Get());
556 else
557 if (strcasecmp(paramName.c_str(), "alwaysOnline") == 0)
558     strprintf(&value, "%d", u->GetProperty().alwaysOnline.Get());
559 else
560 if (strcasecmp(paramName.c_str(), "tariffName") == 0 ||
561     strcasecmp(paramName.c_str(), "tariff") == 0)
562     value = "\"" + u->GetProperty().tariffName.Get() + "\"";
563 else
564 if (strcasecmp(paramName.c_str(), "nextTariff") == 0)
565     value = "\"" + u->GetProperty().nextTariff.Get() + "\"";
566 else
567 if (strcasecmp(paramName.c_str(), "address") == 0)
568     value = "\"" + u->GetProperty().address.Get() + "\"";
569 else
570 if (strcasecmp(paramName.c_str(), "note") == 0)
571     value = "\"" + u->GetProperty().note.Get() + "\"";
572 else
573 if (strcasecmp(paramName.c_str(), "group") == 0)
574     value = "\"" + u->GetProperty().group.Get() + "\"";
575 else
576 if (strcasecmp(paramName.c_str(), "email") == 0)
577     value = "\"" + u->GetProperty().email.Get() + "\"";
578 else
579 if (strcasecmp(paramName.c_str(), "realName") == 0)
580     value = "\"" + u->GetProperty().realName.Get() + "\"";
581 else
582 if (strcasecmp(paramName.c_str(), "credit") == 0)
583     strprintf(&value, "%f", u->GetProperty().credit.Get());
584 else
585 if (strcasecmp(paramName.c_str(), "userdata0") == 0)
586     value = "\"" + u->GetProperty().userdata0.Get() + "\"";
587 else
588 if (strcasecmp(paramName.c_str(), "userdata1") == 0)
589     value = "\"" + u->GetProperty().userdata1.Get() + "\"";
590 else
591 if (strcasecmp(paramName.c_str(), "userdata2") == 0)
592     value = "\"" + u->GetProperty().userdata2.Get() + "\"";
593 else
594 if (strcasecmp(paramName.c_str(), "userdata3") == 0)
595     value = "\"" + u->GetProperty().userdata3.Get() + "\"";
596 else
597 if (strcasecmp(paramName.c_str(), "userdata4") == 0)
598     value = "\"" + u->GetProperty().userdata4.Get() + "\"";
599 else
600 if (strcasecmp(paramName.c_str(), "userdata5") == 0)
601     value = "\"" + u->GetProperty().userdata5.Get() + "\"";
602 else
603 if (strcasecmp(paramName.c_str(), "userdata6") == 0)
604     value = "\"" + u->GetProperty().userdata6.Get() + "\"";
605 else
606 if (strcasecmp(paramName.c_str(), "userdata7") == 0)
607     value = "\"" + u->GetProperty().userdata7.Get() + "\"";
608 else
609 if (strcasecmp(paramName.c_str(), "userdata8") == 0)
610     value = "\"" + u->GetProperty().userdata8.Get() + "\"";
611 else
612 if (strcasecmp(paramName.c_str(), "userdata9") == 0)
613     value = "\"" + u->GetProperty().userdata9.Get() + "\"";
614 else
615 if (strcasecmp(paramName.c_str(), "enabledDirs") == 0)
616     value = u->GetEnabledDirs();
617 else
618     printfd(__FILE__, "Unknown value name: %s\n", paramName.c_str());
619 return value;
620 }
621 //-----------------------------------------------------------------------------
622 void REMOTE_SCRIPT::SetUserNotifier(USER_PTR u)
623 {
624 RS_CHG_AFTER_NOTIFIER<uint32_t> afterChgIPNotifier(*this, u);
625
626 afterChgIPNotifierList.push_front(afterChgIPNotifier);
627
628 u->AddCurrIPAfterNotifier(&(*afterChgIPNotifierList.begin()));
629 }
630 //-----------------------------------------------------------------------------
631 void REMOTE_SCRIPT::UnSetUserNotifier(USER_PTR u)
632 {
633 list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator  ipAIter;
634 std::list<list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator> toErase;
635
636 for (ipAIter = afterChgIPNotifierList.begin(); ipAIter != afterChgIPNotifierList.end(); ++ipAIter)
637     {
638     if (ipAIter->GetUser() == u)
639         {
640         u->DelCurrIPAfterNotifier(&(*ipAIter));
641         toErase.push_back(ipAIter);
642         }
643     }
644
645 std::list<list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator>::iterator eIter;
646
647 for (eIter = toErase.begin(); eIter != toErase.end(); ++eIter)
648     {
649     afterChgIPNotifierList.erase(*eIter);
650     }
651 }
652 //-----------------------------------------------------------------------------
653 template <typename varParamType>
654 void RS_CHG_AFTER_NOTIFIER<varParamType>::Notify(const varParamType & oldValue, const varParamType & newValue)
655 {
656 rs.ChangedIP(user, oldValue, newValue);
657 }
658 //-----------------------------------------------------------------------------
659 void REMOTE_SCRIPT::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const
660 {
661 unsigned char keyL[PASSWD_LEN];  // Пароль для шифровки
662 memset(keyL, 0, PASSWD_LEN);
663 strncpy((char *)keyL, password.c_str(), PASSWD_LEN);
664 Blowfish_Init(ctx, keyL, PASSWD_LEN);
665 }
666 //-----------------------------------------------------------------------------
667 void REMOTE_SCRIPT::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const
668 {
669 if (dst != src)
670     memcpy(dst, src, len8 * 8);
671 for (size_t i = 0; i < len8; ++i)
672     Blowfish_Encrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4));
673 }
674 //-----------------------------------------------------------------------------