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