mirror of
https://gitee.com/BDWare/cp.git
synced 2026-02-14 17:39:28 +00:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a3c59ed59 | ||
|
|
9ecbf54c2d | ||
|
|
a9ec23400e | ||
|
|
247adc11de | ||
|
|
957cdb469f | ||
|
|
afd6363fd5 | ||
|
|
406dafebc4 | ||
|
|
a17925a5f1 | ||
|
|
4087202c24 | ||
|
|
533c92f843 | ||
|
|
93ccf7410b | ||
|
|
b50f891f02 | ||
|
|
9204992153 | ||
|
|
b5470af3c5 | ||
|
|
79cd1d1781 | ||
|
|
46b67d200e | ||
|
|
94db480dc2 | ||
|
|
de617542e9 | ||
|
|
8ffaa3f535 | ||
|
|
35e39f3dd9 | ||
|
|
ac62f7bbf7 | ||
|
|
eb91d17982 | ||
|
|
7e8076e075 | ||
| 2180260a20 | |||
| 2384f6cc59 | |||
| a794bd3af4 | |||
| c0c580090e | |||
| 0b253a4625 | |||
| 5326f41ff7 | |||
| 2a59f577fc | |||
| 6dbb0e161c | |||
|
|
78d068d39b | ||
|
|
e757264a38 | ||
|
|
0e5f92e51e | ||
|
|
587310c899 | ||
|
|
16f1e3a2cd | ||
|
|
9e55d56e85 | ||
|
|
50991a89d0 | ||
|
|
d76f816e92 | ||
|
|
76f564c777 | ||
|
|
fd1690c97b | ||
|
|
723c9c7a06 | ||
|
|
dc0671cfbd | ||
|
|
841f567a88 | ||
|
|
2514980e8b | ||
|
|
491cbadc4d | ||
|
|
042cfae39b | ||
|
|
16f2d4fae1 | ||
|
|
cd87b1f014 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@
|
|||||||
debugconf.json
|
debugconf.json
|
||||||
/ContractDB/
|
/ContractDB/
|
||||||
/defaultLog/
|
/defaultLog/
|
||||||
/log/
|
/log/
|
||||||
|
.DS_Store
|
||||||
366
LICENSE
366
LICENSE
@@ -1,339 +1,127 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
木兰宽松许可证, 第2版
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
木兰宽松许可证, 第2版
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
0. 定义
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
“法人实体”是指提交贡献的机构及其“关联实体”。
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
“关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
1. 授予版权许可
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
2. 授予专利许可
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
3. 无商标许可
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
4. 分发限制
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
5. 免责声明与责任限制
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
6. 语言
|
||||||
identifiable sections of that work are not derived from the Program,
|
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
条款结束
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
如何将木兰宽松许可证,第2版,应用到您的软件
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
3, 请将如下声明文本放入每个源文件的头部注释中。
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
Copyright (c) [Year] [name of copyright holder]
|
||||||
to distribute corresponding source code. (This alternative is
|
[Software Name] is licensed under Mulan PSL v2.
|
||||||
allowed only for noncommercial distribution and only if you
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
received the program in object code or executable form with such
|
You may obtain a copy of Mulan PSL v2 at:
|
||||||
an offer, in accord with Subsection b above.)
|
http://license.coscl.org.cn/MulanPSL2
|
||||||
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
See the Mulan PSL v2 for more details.
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
Mulan Permissive Software License,Version 2
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
|
||||||
except as expressly provided under this License. Any attempt
|
January 2020 http://license.coscl.org.cn/MulanPSL2
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
0. Definition
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
||||||
the Program or works based on it.
|
|
||||||
|
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
||||||
|
|
||||||
|
Legal Entity means the entity making a Contribution and all its Affiliates.
|
||||||
|
|
||||||
|
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
1. Grant of Copyright License
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
2. Grant of Patent License
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
3. No Trademark License
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
4. Distribution Restriction
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
5. Disclaimer of Warranty and Limitation of Liability
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
6. Language
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF THE TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
Copyright (c) [Year] [name of copyright holder]
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
[Software Name] is licensed under Mulan PSL v2.
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
You may obtain a copy of Mulan PSL v2 at:
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
http://license.coscl.org.cn/MulanPSL2
|
||||||
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
If the program is interactive, make it output a short notice like this
|
See the Mulan PSL v2 for more details.
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License.
|
|
||||||
|
|||||||
@@ -16,4 +16,9 @@ copy debugconf.json.template debugconf.json
|
|||||||
3.设置DebugMain的路径为:xxx/xxx/cp
|
3.设置DebugMain的路径为:xxx/xxx/cp
|
||||||
```
|
```
|
||||||
执行DebugMain.main即可
|
执行DebugMain.main即可
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 构建可执行版本
|
||||||
|
执行`cp/build.gradle`中的`buildBundle`任务。
|
||||||
|
在`cp/build/output`即为相关的jar包。
|
||||||
|
由`yjs.jar`(即cp.jar)和一系列依赖(在libs目录下)组成。
|
||||||
|
|||||||
25
build.gradle
25
build.gradle
@@ -5,9 +5,15 @@ plugins {
|
|||||||
id 'signing'
|
id 'signing'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "org.bdware.sc"
|
apply from: '../spotless.gradle'
|
||||||
version = "1.8.0"
|
|
||||||
|
|
||||||
|
group = "org.bdware.sc"
|
||||||
|
version = "1.10.6"
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
// options.compilerArgs << '-Xlint:none'
|
||||||
|
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
||||||
|
options.compilerArgs << '-parameters'
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@@ -34,25 +40,29 @@ sourceSets {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api project(":common")
|
api project(":common")
|
||||||
api project(":mockjava")
|
api project(":mockjava")
|
||||||
|
implementation 'org.bdware:delta-crdts:1.2.0'
|
||||||
implementation 'org.apache.commons:commons-lang3:3.0'
|
implementation 'org.apache.commons:commons-lang3:3.0'
|
||||||
implementation 'com.atlassian.commonmark:commonmark:0.17.0'
|
implementation 'com.atlassian.commonmark:commonmark:0.17.0'
|
||||||
implementation 'com.idealista:format-preserving-encryption:1.0.0'
|
implementation 'com.idealista:format-preserving-encryption:1.0.0'
|
||||||
implementation 'org.apache.commons:commons-math3:3.6.1'
|
implementation 'org.apache.commons:commons-math3:3.6.1'
|
||||||
implementation 'org.codehaus.groovy:groovy-all:3.0.8'
|
implementation 'org.codehaus.groovy:groovy-all:3.0.8'
|
||||||
implementation 'io.grpc:grpc-all:1.41.0'
|
implementation 'io.grpc:grpc-all:1.64.0'
|
||||||
implementation 'org.jsoup:jsoup:1.14.2'
|
implementation 'org.jsoup:jsoup:1.14.2'
|
||||||
implementation 'com.sun.mail:javax.mail:1.6.2'
|
implementation 'com.sun.mail:javax.mail:1.6.2'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||||
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
||||||
implementation 'org.bdware.doip:doip-audit-tool:1.1.3'
|
implementation 'org.bdware.doip:doip-audit-tool:1.6.0'
|
||||||
|
implementation 'org.bdware.doip:doip-sdk:1.5.9'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-layout-template-json:2.17.2'
|
||||||
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
|
||||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
}
|
}
|
||||||
tasks.jar.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
tasks.jar.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
||||||
|
|
||||||
task classJar(type: Jar, dependsOn: classes) {
|
task classJar(type: Jar, dependsOn: classes) {
|
||||||
classifier = "jar"
|
classifier = "jar"
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
String libs = ''
|
String libs = ''
|
||||||
configurations.runtimeClasspath.each {
|
configurations.runtimeClasspath.each {
|
||||||
@@ -62,7 +72,7 @@ jar {
|
|||||||
// uncomment this when publish,
|
// uncomment this when publish,
|
||||||
// while develop at local use "false"
|
// while develop at local use "false"
|
||||||
configurations.runtimeClasspath.filter {
|
configurations.runtimeClasspath.filter {
|
||||||
// it.getAbsolutePath().contains("/lib/")
|
// it.getAbsolutePath().contains("/lib/")
|
||||||
false
|
false
|
||||||
}.collect {
|
}.collect {
|
||||||
it.isDirectory() ? it : zipTree(it)
|
it.isDirectory() ? it : zipTree(it)
|
||||||
@@ -119,8 +129,7 @@ tasks.withType(Javadoc) {
|
|||||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||||
archiveClassifier = 'javadoc'
|
archiveClassifier = 'javadoc'
|
||||||
classifier = "javadoc"
|
classifier = "javadoc"
|
||||||
exclude {
|
exclude { details -> details.file.getAbsolutePath().contains("/gm/")
|
||||||
details -> details.file.getAbsolutePath().contains("/gm/")
|
|
||||||
}
|
}
|
||||||
from javadoc.destinationDir
|
from javadoc.destinationDir
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
lib/bdledger-java-sdk-dev-250321.jar
Normal file
BIN
lib/bdledger-java-sdk-dev-250321.jar
Normal file
Binary file not shown.
@@ -16,8 +16,6 @@ import com.alibaba.datax.plugin.rdbms.util.DBUtil;
|
|||||||
import com.alibaba.datax.plugin.rdbms.util.DBUtilErrorCode;
|
import com.alibaba.datax.plugin.rdbms.util.DBUtilErrorCode;
|
||||||
import com.alibaba.datax.plugin.rdbms.util.DataBaseType;
|
import com.alibaba.datax.plugin.rdbms.util.DataBaseType;
|
||||||
import com.alibaba.datax.plugin.rdbms.util.RdbmsException;
|
import com.alibaba.datax.plugin.rdbms.util.RdbmsException;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
@@ -47,8 +45,8 @@ public class MaskingJob {
|
|||||||
|
|
||||||
public void init(String confContent) {
|
public void init(String confContent) {
|
||||||
maskConf = Configuration.from(confContent);
|
maskConf = Configuration.from(confContent);
|
||||||
System.out.println("maskConf"+maskConf.toString());
|
System.out.println("maskConf" + maskConf.toString());
|
||||||
System.out.println(("maskCOnfjob"+maskConf.get("job").toString()));
|
System.out.println(("maskCOnfjob" + maskConf.get("job").toString()));
|
||||||
readerPara = maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT_READER_PARAMETER);
|
readerPara = maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT_READER_PARAMETER);
|
||||||
System.out.println(readerPara);
|
System.out.println(readerPara);
|
||||||
username = readerPara.getString(Key.USERNAME);
|
username = readerPara.getString(Key.USERNAME);
|
||||||
@@ -56,16 +54,19 @@ public class MaskingJob {
|
|||||||
jdbcUrl = readerPara.getString(Key.JDBC_URL);
|
jdbcUrl = readerPara.getString(Key.JDBC_URL);
|
||||||
table = readerPara.getString(Key.TABLE);
|
table = readerPara.getString(Key.TABLE);
|
||||||
buffer = new ArrayList<>();
|
buffer = new ArrayList<>();
|
||||||
System.out.println("maskConf11"+maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT + "[0]"));
|
System.out.println(
|
||||||
transformerExecs = TransformerUtil.buildTransformerInfo(maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT + "[0]"));
|
"maskConf11" + maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT + "[0]"));
|
||||||
|
transformerExecs = TransformerUtil.buildTransformerInfo(
|
||||||
|
maskConf.getConfiguration(CoreConstant.DATAX_JOB_CONTENT + "[0]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String buildQuerySql() {
|
public String buildQuerySql() {
|
||||||
String column = "*";
|
String column = "*";
|
||||||
//String column = readerPara.getString(Key.COLUMN);
|
// String column = readerPara.getString(Key.COLUMN);
|
||||||
String table = readerPara.getString(Key.TABLE);
|
String table = readerPara.getString(Key.TABLE);
|
||||||
String where = readerPara.getString(Key.WHERE, null);
|
String where = readerPara.getString(Key.WHERE, null);
|
||||||
//String querySql = SingleTableSplitUtil.buildQuerySql(column, table, where) + " limit 100";
|
// String querySql = SingleTableSplitUtil.buildQuerySql(column, table, where) + " limit
|
||||||
|
// 100";
|
||||||
String querySql = SingleTableSplitUtil.buildQuerySql(column, table, where) + " limit 100";
|
String querySql = SingleTableSplitUtil.buildQuerySql(column, table, where) + " limit 100";
|
||||||
|
|
||||||
return querySql;
|
return querySql;
|
||||||
@@ -74,24 +75,24 @@ public class MaskingJob {
|
|||||||
public JsonPrimitive getMaskedData(String confContent) {
|
public JsonPrimitive getMaskedData(String confContent) {
|
||||||
init(confContent);
|
init(confContent);
|
||||||
return startRead();
|
return startRead();
|
||||||
//return new JsonPrimitive(getResult());
|
// return new JsonPrimitive(getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonPrimitive startRead() {
|
public JsonPrimitive startRead() {
|
||||||
String querySql = buildQuerySql();
|
String querySql = buildQuerySql();
|
||||||
System.out.println("startRead"+dataBaseType+jdbcUrl+username+password);
|
System.out.println("startRead" + dataBaseType + jdbcUrl + username + password);
|
||||||
Connection conn = DBUtil.getConnection(dataBaseType, jdbcUrl, username, password);
|
Connection conn = DBUtil.getConnection(dataBaseType, jdbcUrl, username, password);
|
||||||
System.out.println(dataBaseType+jdbcUrl+username+password);
|
System.out.println(dataBaseType + jdbcUrl + username + password);
|
||||||
int columnNumber = 0;
|
int columnNumber = 0;
|
||||||
String res="";
|
String res = "";
|
||||||
ArrayList<String>columnName=new ArrayList<>();
|
ArrayList<String> columnName = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
ResultSet rs = DBUtil.query(conn, querySql);
|
ResultSet rs = DBUtil.query(conn, querySql);
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
columnNumber = metaData.getColumnCount();
|
columnNumber = metaData.getColumnCount();
|
||||||
for(int i=1;i<=metaData.getColumnCount();i++){
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
//获取列表 index 从1开始、列名、列类型、列的数据长度
|
// 获取列表 index 从1开始、列名、列类型、列的数据长度
|
||||||
//System.out.println("aaa"+metaData.getColumnName(i)+"\t"+metaData.getColumnTypeName(i)+"\t"+metaData.getColumnDisplaySize(i));
|
// System.out.println("aaa"+metaData.getColumnName(i)+"\t"+metaData.getColumnTypeName(i)+"\t"+metaData.getColumnDisplaySize(i));
|
||||||
columnName.add(metaData.getColumnName(i));
|
columnName.add(metaData.getColumnName(i));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -106,15 +107,14 @@ public class MaskingJob {
|
|||||||
} finally {
|
} finally {
|
||||||
DBUtil.closeDBResources(null, conn);
|
DBUtil.closeDBResources(null, conn);
|
||||||
}
|
}
|
||||||
////for(int i=0;i<columnNumber;i++){
|
//// for(int i=0;i<columnNumber;i++){
|
||||||
//columnName.add(metaData.getColumnName(i));
|
// columnName.add(metaData.getColumnName(i));
|
||||||
//}//
|
// }//
|
||||||
res=getResult(columnName);
|
res = getResult(columnName);
|
||||||
return new JsonPrimitive(res);
|
return new JsonPrimitive(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Record transportOneRecord(ResultSet rs, ResultSetMetaData metaData,
|
private Record transportOneRecord(ResultSet rs, ResultSetMetaData metaData, int columnNumber) {
|
||||||
int columnNumber) {
|
|
||||||
Record record = buildRecord(rs, metaData, columnNumber);
|
Record record = buildRecord(rs, metaData, columnNumber);
|
||||||
sendToWriter(record);
|
sendToWriter(record);
|
||||||
return record;
|
return record;
|
||||||
@@ -133,32 +133,34 @@ public class MaskingJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Record doTransformer(Record record) {
|
private Record doTransformer(Record record) {
|
||||||
System.out.println("Record"+record);
|
System.out.println("Record" + record);
|
||||||
if (transformerExecs == null || transformerExecs.size() == 0) {
|
if (transformerExecs == null || transformerExecs.size() == 0) {
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassLoaderSwapper classLoaderSwapper = ClassLoaderSwapper
|
ClassLoaderSwapper classLoaderSwapper =
|
||||||
.newCurrentThreadClassLoaderSwapper();
|
ClassLoaderSwapper.newCurrentThreadClassLoaderSwapper();
|
||||||
|
|
||||||
Record result = record;
|
Record result = record;
|
||||||
|
|
||||||
String errorMsg = null;
|
String errorMsg = null;
|
||||||
boolean failed = false;
|
boolean failed = false;
|
||||||
for (TransformerExecution transformerInfoExec : transformerExecs) {
|
for (TransformerExecution transformerInfoExec : transformerExecs) {
|
||||||
System.out.println("transformerExecs"+transformerInfoExec.getTransformerName());
|
System.out.println("transformerExecs" + transformerInfoExec.getTransformerName());
|
||||||
if (transformerInfoExec.getClassLoader() != null) {
|
if (transformerInfoExec.getClassLoader() != null) {
|
||||||
classLoaderSwapper.setCurrentThreadClassLoader(transformerInfoExec.getClassLoader());
|
classLoaderSwapper
|
||||||
|
.setCurrentThreadClassLoader(transformerInfoExec.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟检查transformer参数的有效性,直接抛出异常,不作为脏数据
|
* 延迟检查transformer参数的有效性,直接抛出异常,不作为脏数据 不需要在插件中检查参数的有效性。但参数的个数等和插件相关的参数,在插件内部检查
|
||||||
* 不需要在插件中检查参数的有效性。但参数的个数等和插件相关的参数,在插件内部检查
|
|
||||||
*/
|
*/
|
||||||
if (!transformerInfoExec.isChecked()) {
|
if (!transformerInfoExec.isChecked()) {
|
||||||
|
|
||||||
if (transformerInfoExec.getColumnIndex() != null && transformerInfoExec.getColumnIndex() >= record.getColumnNumber()) {
|
if (transformerInfoExec.getColumnIndex() != null
|
||||||
throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_ILLEGAL_PARAMETER,
|
&& transformerInfoExec.getColumnIndex() >= record.getColumnNumber()) {
|
||||||
|
throw DataXException.asDataXException(
|
||||||
|
TransformerErrorCode.TRANSFORMER_ILLEGAL_PARAMETER,
|
||||||
String.format("columnIndex[%s] out of bound[%s]. name=%s",
|
String.format("columnIndex[%s] out of bound[%s]. name=%s",
|
||||||
transformerInfoExec.getColumnIndex(), record.getColumnNumber(),
|
transformerInfoExec.getColumnIndex(), record.getColumnNumber(),
|
||||||
transformerInfoExec.getTransformerName()));
|
transformerInfoExec.getTransformerName()));
|
||||||
@@ -167,14 +169,15 @@ public class MaskingJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = transformerInfoExec.getTransformer().evaluate(result, transformerInfoExec.gettContext(), transformerInfoExec.getFinalParas());
|
result = transformerInfoExec.getTransformer().evaluate(result,
|
||||||
|
transformerInfoExec.gettContext(), transformerInfoExec.getFinalParas());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMsg = String.format("transformer(%s) has Exception(%s)", transformerInfoExec.getTransformerName(),
|
errorMsg = String.format("transformer(%s) has Exception(%s)",
|
||||||
e.getMessage());
|
transformerInfoExec.getTransformerName(), e.getMessage());
|
||||||
failed = true;
|
failed = true;
|
||||||
//LOG.error(errorMsg, e);
|
// LOG.error(errorMsg, e);
|
||||||
// transformerInfoExec.addFailedRecords(1);
|
// transformerInfoExec.addFailedRecords(1);
|
||||||
//脏数据不再进行后续transformer处理,按脏数据处理,并过滤该record。
|
// 脏数据不再进行后续transformer处理,按脏数据处理,并过滤该record。
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@@ -193,14 +196,13 @@ public class MaskingJob {
|
|||||||
if (failed) {
|
if (failed) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("result"+result);
|
System.out.println("result" + result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Record buildRecord(ResultSet rs, ResultSetMetaData metaData,
|
protected Record buildRecord(ResultSet rs, ResultSetMetaData metaData, int columnNumber) {
|
||||||
int columnNumber) {
|
|
||||||
final byte[] EMPTY_CHAR_ARRAY = new byte[0];
|
final byte[] EMPTY_CHAR_ARRAY = new byte[0];
|
||||||
Record record = new DefaultRecord();
|
Record record = new DefaultRecord();
|
||||||
try {
|
try {
|
||||||
@@ -276,14 +278,11 @@ public class MaskingJob {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw DataXException
|
throw DataXException.asDataXException(DBUtilErrorCode.UNSUPPORTED_TYPE,
|
||||||
.asDataXException(
|
String.format(
|
||||||
DBUtilErrorCode.UNSUPPORTED_TYPE,
|
"您的配置文件中的列配置信息有误. 因为DataX 不支持数据库读取这种字段类型. 字段名:[%s], 字段名称:[%s], 字段Java类型:[%s]. 请尝试使用数据库函数将其转换datax支持的类型 或者不同步该字段 .",
|
||||||
String.format(
|
metaData.getColumnName(i), metaData.getColumnType(i),
|
||||||
"您的配置文件中的列配置信息有误. 因为DataX 不支持数据库读取这种字段类型. 字段名:[%s], 字段名称:[%s], 字段Java类型:[%s]. 请尝试使用数据库函数将其转换datax支持的类型 或者不同步该字段 .",
|
metaData.getColumnClassName(i)));
|
||||||
metaData.getColumnName(i),
|
|
||||||
metaData.getColumnType(i),
|
|
||||||
metaData.getColumnClassName(i)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -294,33 +293,33 @@ public class MaskingJob {
|
|||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private String recordToString(Record record) {
|
// private String recordToString(Record record) {
|
||||||
// final String NEWLINE_FLAG = "\n";
|
// final String NEWLINE_FLAG = "\n";
|
||||||
// String fieldDelimiter = "\t";
|
// String fieldDelimiter = "\t";
|
||||||
//
|
//
|
||||||
// int recordLength = record.getColumnNumber();
|
// int recordLength = record.getColumnNumber();
|
||||||
// if (0 == recordLength) {
|
// if (0 == recordLength) {
|
||||||
// return NEWLINE_FLAG;
|
// return NEWLINE_FLAG;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Column column;
|
// Column column;
|
||||||
// StringBuilder sb = new StringBuilder();
|
// StringBuilder sb = new StringBuilder();
|
||||||
// for (int i = 0; i < recordLength; i++) {
|
// for (int i = 0; i < recordLength; i++) {
|
||||||
// column = record.getColumn(i);
|
// column = record.getColumn(i);
|
||||||
// sb.append(column.asString()).append(fieldDelimiter);
|
// sb.append(column.asString()).append(fieldDelimiter);
|
||||||
// }
|
// }
|
||||||
// sb.setLength(sb.length() - 1);
|
// sb.setLength(sb.length() - 1);
|
||||||
// sb.append(NEWLINE_FLAG);
|
// sb.append(NEWLINE_FLAG);
|
||||||
//
|
//
|
||||||
// return sb.toString();
|
// return sb.toString();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public String getResult(ArrayList<String> columnName) {
|
public String getResult(ArrayList<String> columnName) {
|
||||||
List<Object> dataList = new ArrayList<>();
|
List<Object> dataList = new ArrayList<>();
|
||||||
int size = buffer.size();
|
int size = buffer.size();
|
||||||
//System.out.println("CCULUMN"+readerPara.getString(Key.COLUMN).toString());
|
// System.out.println("CCULUMN"+readerPara.getString(Key.COLUMN).toString());
|
||||||
//String[] colmnNames = readerPara.getString(Key.COLUMN).replace(" ", "").split(",");
|
// String[] colmnNames = readerPara.getString(Key.COLUMN).replace(" ", "").split(",");
|
||||||
int colmnSize= columnName.size();
|
int colmnSize = columnName.size();
|
||||||
for (int i = 0; i < colmnSize; ++i) {
|
for (int i = 0; i < colmnSize; ++i) {
|
||||||
Map<Object, Object> rowData = new HashMap<>();
|
Map<Object, Object> rowData = new HashMap<>();
|
||||||
for (int j = 0; j < size; ++j) {
|
for (int j = 0; j < size; ++j) {
|
||||||
|
|||||||
@@ -26,60 +26,65 @@ public class DebugMain {
|
|||||||
DebugConfig config = JsonUtil.fromJson(content, DebugConfig.class);
|
DebugConfig config = JsonUtil.fromJson(content, DebugConfig.class);
|
||||||
inject(config);
|
inject(config);
|
||||||
String keyPairStr = "{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}";
|
String keyPairStr = "{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}";
|
||||||
SM2KeyPair pair = SM2KeyPair.fromJson(String.format(keyPairStr, config.publicKey, config.privateKey));
|
SM2KeyPair pair =
|
||||||
|
SM2KeyPair.fromJson(String.format(keyPairStr, config.publicKey, config.privateKey));
|
||||||
String uriFormat = "ws://%s/SCIDE/SCExecutor";
|
String uriFormat = "ws://%s/SCIDE/SCExecutor";
|
||||||
if (config.killBeforeStart != null && config.killBeforeStart.length() > 0) {
|
if (config.killBeforeStart != null && config.killBeforeStart.length() > 0) {
|
||||||
AtomicInteger counter = new AtomicInteger(0);
|
AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
SmartContractClient client = new SmartContractClient(String.format(uriFormat, config.agentAddress), pair) {
|
SmartContractClient client =
|
||||||
public void onLogin(JsonObject obj) {
|
new SmartContractClient(String.format(uriFormat, config.agentAddress), pair) {
|
||||||
counter.incrementAndGet();
|
public void onLogin(JsonObject obj) {
|
||||||
}
|
counter.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
public void onKillContractProcess(JsonObject obj) {
|
public void onKillContractProcess(JsonObject obj) {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
client.waitForConnect();
|
client.waitForConnect();
|
||||||
client.login();
|
client.login();
|
||||||
try {
|
try {
|
||||||
for (; counter.get() == 0; )
|
for (; counter.get() == 0;)
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
client.sendMsg("{\"action\":\"killContractProcess\",\"name\":\"" + config.killBeforeStart + "\"}");
|
client.sendMsg("{\"action\":\"killContractProcess\",\"name\":\""
|
||||||
|
+ config.killBeforeStart + "\"}");
|
||||||
try {
|
try {
|
||||||
for (; counter.get() == 1; )
|
for (; counter.get() == 1;)
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.contract.setCreateParam(config.createParam);
|
config.contract.setCreateParam(config.createParam);
|
||||||
ContractProcess.main(new String[]{"-port=" + config.port, "-cmi=" + config.cmi, "-disablePID"});
|
ContractProcess
|
||||||
ResultCallback printCallback
|
.main(new String[] {"-port=" + config.port, "-cmi=" + config.cmi, "-disablePID"});
|
||||||
= new ResultCallback() {
|
ResultCallback printCallback = new ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(String str) {
|
public void onResult(String str) {
|
||||||
if(str.contains("Error")) {
|
if (str.contains("Error")) {
|
||||||
LOGGER.error("Some error happens: " + str);
|
LOGGER.error("Some error happens: " + str);
|
||||||
}
|
}
|
||||||
LOGGER.info("[PrintCB] " + str);
|
LOGGER.info("[PrintCB] " + str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ContractProcess.instance.handler.setDBInfo(wrap("", config.dbPath), printCallback);
|
ContractProcess.instance.handler.setDBInfo(wrap("", config.dbPath), printCallback);
|
||||||
ContractProcess.instance.handler.registerMangerPort(wrap("", Integer.valueOf(config.cPort)), printCallback);
|
ContractProcess.instance.handler.registerMangerPort(wrap("", Integer.valueOf(config.cPort)),
|
||||||
|
printCallback);
|
||||||
|
|
||||||
ContractProcess.instance.handler.setContractBundle(wrap("", config.contract), printCallback);
|
ContractProcess.instance.handler.setContractBundle(wrap("", config.contract),
|
||||||
|
printCallback);
|
||||||
|
|
||||||
String urlFormat = "http://%s/SCIDE/SCManager?action=reconnectPort&owner=%s&port=%d%s";
|
String urlFormat = "http://%s/SCIDE/SCManager?action=reconnectPort&owner=%s&port=%d%s";
|
||||||
String cpHost = "";
|
String cpHost = "";
|
||||||
if (config.cpHost != null && config.cpHost.length() > 0)
|
if (config.cpHost != null && config.cpHost.length() > 0)
|
||||||
cpHost = "&host=" + config.cpHost;
|
cpHost = "&host=" + config.cpHost;
|
||||||
String url = String.format(urlFormat, config.agentAddress,
|
String url = String.format(urlFormat, config.agentAddress, config.publicKey,
|
||||||
config.publicKey, ContractProcess.instance.server.mainPort.get(), cpHost);
|
ContractProcess.instance.server.mainPort.get(), cpHost);
|
||||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||||
|
|
||||||
String data = (String) resp.get("response");
|
String data = (String) resp.get("response");
|
||||||
@@ -103,7 +108,8 @@ public class DebugMain {
|
|||||||
config.cPort = jsonObject.get("cPort").getAsInt();
|
config.cPort = jsonObject.get("cPort").getAsInt();
|
||||||
config.port = jsonObject.get("port").getAsInt();
|
config.port = jsonObject.get("port").getAsInt();
|
||||||
JsonObject ownerAndScript = new JsonObject();
|
JsonObject ownerAndScript = new JsonObject();
|
||||||
String arg = "abc&owner=" + config.publicKey + "&script=" + config.ypkPath;
|
String arg = "abc&owner=" + config.publicKey + "&script=" + config.ypkPath
|
||||||
|
+ "&doipStartPort=" + config.doipStartPort;
|
||||||
url = String.format(urlFormat, config.agentAddress, "allocateKeyPair", arg);
|
url = String.format(urlFormat, config.agentAddress, "allocateKeyPair", arg);
|
||||||
resp = HttpUtil.httpGet(url);
|
resp = HttpUtil.httpGet(url);
|
||||||
LOGGER.info(url);
|
LOGGER.info(url);
|
||||||
@@ -133,7 +139,8 @@ public class DebugMain {
|
|||||||
String killBeforeStart;
|
String killBeforeStart;
|
||||||
String ypkPath;
|
String ypkPath;
|
||||||
String cpHost;
|
String cpHost;
|
||||||
//AutoAppend
|
int doipStartPort;
|
||||||
|
// AutoAppend
|
||||||
int port;
|
int port;
|
||||||
String cmi;
|
String cmi;
|
||||||
String dbPath;
|
String dbPath;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.bdware.sc.engine.DesktopEngine;
|
|||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
import org.bdware.sc.engine.hook.*;
|
import org.bdware.sc.engine.hook.*;
|
||||||
import org.bdware.sc.handler.ContractHandler;
|
import org.bdware.sc.handler.ContractHandler;
|
||||||
|
import org.bdware.sc.handler.DOOPRequestHandler;
|
||||||
import org.bdware.sc.index.TimeSerialIndex;
|
import org.bdware.sc.index.TimeSerialIndex;
|
||||||
import org.bdware.sc.node.*;
|
import org.bdware.sc.node.*;
|
||||||
import org.bdware.sc.server.DoipClusterServer;
|
import org.bdware.sc.server.DoipClusterServer;
|
||||||
@@ -41,6 +42,8 @@ import org.bdware.sc.util.JsonUtil;
|
|||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
|
import org.zz.gmhelper.SM2Util;
|
||||||
|
|
||||||
import javax.script.ScriptContext;
|
import javax.script.ScriptContext;
|
||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
@@ -50,12 +53,11 @@ import java.lang.reflect.Method;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class ContractProcess {
|
public class ContractProcess {
|
||||||
private static final byte[] ZIP_HEADER_1 = new byte[]{80, 75, 3, 4};
|
private static final byte[] ZIP_HEADER_1 = new byte[] {80, 75, 3, 4};
|
||||||
private static final byte[] ZIP_HEADER_2 = new byte[]{80, 75, 5, 6};
|
private static final byte[] ZIP_HEADER_2 = new byte[] {80, 75, 5, 6};
|
||||||
private static final org.apache.logging.log4j.Logger LOGGER =
|
private static final org.apache.logging.log4j.Logger LOGGER =
|
||||||
org.apache.logging.log4j.LogManager.getLogger(ContractProcess.class);
|
org.apache.logging.log4j.LogManager.getLogger(ContractProcess.class);
|
||||||
public static ContractProcess instance;
|
public static ContractProcess instance;
|
||||||
@@ -81,6 +83,7 @@ public class ContractProcess {
|
|||||||
private TimeSerialIndex logIndex;
|
private TimeSerialIndex logIndex;
|
||||||
private RocksDBUtil edion;
|
private RocksDBUtil edion;
|
||||||
private String pid;
|
private String pid;
|
||||||
|
public DOOPRequestHandler doopRequestHandler;
|
||||||
|
|
||||||
public ContractProcess(int port, String cmi) {
|
public ContractProcess(int port, String cmi) {
|
||||||
handler = new ContractHandler(this);
|
handler = new ContractHandler(this);
|
||||||
@@ -108,7 +111,7 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Scanner sc = new Scanner(pidInput);
|
Scanner sc = new Scanner(pidInput);
|
||||||
for (String str; sc.hasNextLine(); ) {
|
for (String str; sc.hasNextLine();) {
|
||||||
str = sc.nextLine();
|
str = sc.nextLine();
|
||||||
LOGGER.info("[CP From STDIN] " + str);
|
LOGGER.info("[CP From STDIN] " + str);
|
||||||
if (str.contains("CP PID:")) {
|
if (str.contains("CP PID:")) {
|
||||||
@@ -136,9 +139,8 @@ public class ContractProcess {
|
|||||||
byte[] buffer = new byte[4];
|
byte[] buffer = new byte[4];
|
||||||
int length = input.read(buffer, 0, 4);
|
int length = input.read(buffer, 0, 4);
|
||||||
if (length == 4) {
|
if (length == 4) {
|
||||||
isArchive =
|
isArchive = (Arrays.equals(ZIP_HEADER_1, buffer))
|
||||||
(Arrays.equals(ZIP_HEADER_1, buffer))
|
|| (Arrays.equals(ZIP_HEADER_2, buffer));
|
||||||
|| (Arrays.equals(ZIP_HEADER_2, buffer));
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -193,9 +195,8 @@ public class ContractProcess {
|
|||||||
|
|
||||||
cn = czb.mergeContractNode();
|
cn = czb.mergeContractNode();
|
||||||
} else {
|
} else {
|
||||||
cn =
|
cn = compiler.compile(new ByteArrayInputStream(script.getBytes()),
|
||||||
compiler.compile(
|
"contract_main.yjs");
|
||||||
new ByteArrayInputStream(script.getBytes()), "contract_main.yjs");
|
|
||||||
}
|
}
|
||||||
DesktopEngine engine = new DesktopEngine(); // engine.loadJar(zf);
|
DesktopEngine engine = new DesktopEngine(); // engine.loadJar(zf);
|
||||||
engine.loadContract(c, cn, ret.isInsnLimit);
|
engine.loadContract(c, cn, ret.isInsnLimit);
|
||||||
@@ -215,8 +216,8 @@ public class ContractProcess {
|
|||||||
|
|
||||||
MethodNode mn = methods.get(fn.functionName);
|
MethodNode mn = methods.get(fn.functionName);
|
||||||
if (mn != null) {
|
if (mn != null) {
|
||||||
System.out.println(
|
System.out
|
||||||
"[ContractManager] getMethodNode, verify:" + fn.functionName);
|
.println("[ContractManager] getMethodNode, verify:" + fn.functionName);
|
||||||
TaintResult.nLocals = mn.maxLocals;
|
TaintResult.nLocals = mn.maxLocals;
|
||||||
TaintResult.nStack = mn.maxStack;
|
TaintResult.nStack = mn.maxStack;
|
||||||
TaintCFG cfg = new TaintCFG(mn);
|
TaintCFG cfg = new TaintCFG(mn);
|
||||||
@@ -274,22 +275,17 @@ public class ContractProcess {
|
|||||||
MethodNode mn = methods.get(fn.functionName);
|
MethodNode mn = methods.get(fn.functionName);
|
||||||
if (mn != null) {
|
if (mn != null) {
|
||||||
/*
|
/*
|
||||||
* CFGraph cfg = new CFGraph(mn) {
|
* CFGraph cfg = new CFGraph(mn) {
|
||||||
*
|
*
|
||||||
* @Override public BasicBlock getBasicBlock(int id) { return new
|
* @Override public BasicBlock getBasicBlock(int id) { return new
|
||||||
* BasicBlock(id); } }; FrontCF frontCF = new FrontCF(graph); String[]
|
* BasicBlock(id); } }; FrontCF frontCF = new FrontCF(graph); String[] data =
|
||||||
data =
|
* fn.plainText().split("\n"); for (int i = 0; i < graph.getBasicBlockSize();
|
||||||
* fn.plainText().split("\n"); for (int i = 0; i <
|
* i++) { BasicBlock bb = graph.getBasicBlockAt(i); String decompiled = ""; if
|
||||||
graph.getBasicBlockSize();
|
* (bb.lineNum - 1 < data.length && bb.lineNum > 0) { decompiled =
|
||||||
* i++) { BasicBlock bb = graph.getBasicBlockAt(i); String decompiled =
|
* data[bb.lineNum - 1]; } frontCF.addBB(bb, decompiled); Set<BasicBlock> suc =
|
||||||
""; if
|
* graph.getSucBlocks(bb); for (BasicBlock sucBB : suc) frontCF.addEdge(bb,
|
||||||
* (bb.lineNum - 1 < data.length && bb.lineNum > 0) { decompiled =
|
* sucBB); }
|
||||||
* data[bb.lineNum - 1]; } frontCF.addBB(bb, decompiled); Set<BasicBlock>
|
*/
|
||||||
suc =
|
|
||||||
* graph.getSucBlocks(bb); for (BasicBlock sucBB : suc)
|
|
||||||
frontCF.addEdge(bb,
|
|
||||||
* sucBB); }
|
|
||||||
*/
|
|
||||||
TaintResult.nLocals = mn.maxLocals;
|
TaintResult.nLocals = mn.maxLocals;
|
||||||
TaintResult.nStack = mn.maxStack;
|
TaintResult.nStack = mn.maxStack;
|
||||||
TaintCFG cfg = new TaintCFG(mn);
|
TaintCFG cfg = new TaintCFG(mn);
|
||||||
@@ -310,55 +306,56 @@ public class ContractProcess {
|
|||||||
List<Integer> ids = map.get(i);
|
List<Integer> ids = map.get(i);
|
||||||
frontCF.addBB(bb, decompiled, ids, cfg);
|
frontCF.addBB(bb, decompiled, ids, cfg);
|
||||||
Set<BasicBlock> suc = cfg.getSucBlocks(bb);
|
Set<BasicBlock> suc = cfg.getSucBlocks(bb);
|
||||||
for (BasicBlock sucBB : suc) frontCF.addEdge(bb, sucBB);
|
for (BasicBlock sucBB : suc)
|
||||||
|
frontCF.addEdge(bb, sucBB);
|
||||||
}
|
}
|
||||||
// get result
|
// get result
|
||||||
// TaintBB lastBlock = cfg.getLastBlock();
|
// TaintBB lastBlock = cfg.getLastBlock();
|
||||||
// if (lastBlock != null) {
|
// if (lastBlock != null) {
|
||||||
// frontCF.ret = lastBlock.getResultWithTaintBit();
|
// frontCF.ret = lastBlock.getResultWithTaintBit();
|
||||||
// // System.out.println(frontCF.ret);
|
// // System.out.println(frontCF.ret);
|
||||||
// if (parameters != null && parameters != "") {
|
// if (parameters != null && parameters != "") {
|
||||||
// // System.out.println(parameters);
|
// // System.out.println(parameters);
|
||||||
// // frontCF.finalRet = "yes";
|
// // frontCF.finalRet = "yes";
|
||||||
// Gson gson = JsonUtil;
|
// Gson gson = JsonUtil;
|
||||||
// JsonParser jsonParser = new JsonParser();
|
// JsonParser jsonParser = new JsonParser();
|
||||||
// JsonArray jsonArray =
|
// JsonArray jsonArray =
|
||||||
// jsonParser.parse(parameters).getAsJsonArray();
|
// jsonParser.parse(parameters).getAsJsonArray();
|
||||||
// List<String> listConstraint = new ArrayList<>();
|
// List<String> listConstraint = new ArrayList<>();
|
||||||
// List<String> listResource = new ArrayList<>();
|
// List<String> listResource = new ArrayList<>();
|
||||||
// for (JsonElement je : jsonArray) {
|
// for (JsonElement je : jsonArray) {
|
||||||
// Bean bean = gson.fromJson(je, Bean.class);
|
// Bean bean = gson.fromJson(je, Bean.class);
|
||||||
// switch (bean.name) {
|
// switch (bean.name) {
|
||||||
// case "open":
|
// case "open":
|
||||||
// listConstraint.add("open");
|
// listConstraint.add("open");
|
||||||
// break;
|
// break;
|
||||||
// case "byValue":
|
// case "byValue":
|
||||||
// listConstraint.add("byValue");
|
// listConstraint.add("byValue");
|
||||||
// break;
|
// break;
|
||||||
// case "control":
|
// case "control":
|
||||||
// listConstraint.add("control");
|
// listConstraint.add("control");
|
||||||
// break;
|
// break;
|
||||||
// case "close":
|
// case "close":
|
||||||
// listConstraint.add("close");
|
// listConstraint.add("close");
|
||||||
// break;
|
// break;
|
||||||
// case "originalData":
|
// case "originalData":
|
||||||
// listResource.add("originalData");
|
// listResource.add("originalData");
|
||||||
// break;
|
// break;
|
||||||
// case "contractCall":
|
// case "contractCall":
|
||||||
// listResource.add("contractCall");
|
// listResource.add("contractCall");
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//// String dep =
|
//// String dep =
|
||||||
// frontCF.blocks.get(frontCF.blocks.size() - 1).blockDep;
|
// frontCF.blocks.get(frontCF.blocks.size() - 1).blockDep;
|
||||||
//// if ((listConstraint.contains("open")
|
//// if ((listConstraint.contains("open")
|
||||||
//// ||
|
//// ||
|
||||||
// listConstraint.contains("close"))
|
// listConstraint.contains("close"))
|
||||||
//// && (frontCF.ret != null || dep != null))
|
//// && (frontCF.ret != null || dep != null))
|
||||||
//// frontCF.finalRet = "不通过";
|
//// frontCF.finalRet = "不通过";
|
||||||
//// else frontCF.finalRet = "通过";
|
//// else frontCF.finalRet = "通过";
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
result.put(fn.functionName, frontCF);
|
result.put(fn.functionName, frontCF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,10 +400,8 @@ public class ContractProcess {
|
|||||||
String yancloud_desktop = "";
|
String yancloud_desktop = "";
|
||||||
isOpen.put(pmList[0], pmList[1]);
|
isOpen.put(pmList[0], pmList[1]);
|
||||||
yancloud_desktop += UtilRegistry.getInitStr(pmList[0], pmList[1].equals("open"));
|
yancloud_desktop += UtilRegistry.getInitStr(pmList[0], pmList[1].equals("open"));
|
||||||
engine.getNashornEngine()
|
engine.getNashornEngine().getContext().setAttribute(ScriptEngine.FILENAME,
|
||||||
.getContext()
|
yancloud_desktop, ScriptContext.ENGINE_SCOPE);
|
||||||
.setAttribute(
|
|
||||||
ScriptEngine.FILENAME, yancloud_desktop, ScriptContext.ENGINE_SCOPE);
|
|
||||||
engine.getNashornEngine().eval(yancloud_desktop);
|
engine.getNashornEngine().eval(yancloud_desktop);
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -428,25 +423,20 @@ public class ContractProcess {
|
|||||||
// 判断是否满足Oracle和Contact的执行要求
|
// 判断是否满足Oracle和Contact的执行要求
|
||||||
public String verifyOracleAndContractPermission(Contract contract) {
|
public String verifyOracleAndContractPermission(Contract contract) {
|
||||||
// 权限校验 如果是Oracle 启动方式只能是Sole 否则报错
|
// 权限校验 如果是Oracle 启动方式只能是Sole 否则报错
|
||||||
if (cn.getYjsType() == YjsType.Oracle && contract.getType() != ContractExecType.Sole && contract.getType() != ContractExecType.Sharding) {
|
if (cn.getYjsType() == YjsType.Oracle && contract.getType() != ContractExecType.Sole
|
||||||
|
&& contract.getType() != ContractExecType.Sharding) {
|
||||||
LOGGER.info("Oracle only support Sole ContractType!");
|
LOGGER.info("Oracle only support Sole ContractType!");
|
||||||
return JsonUtil.toJson(
|
return JsonUtil.toJson(new ContractResult(Status.Error,
|
||||||
new ContractResult(
|
new JsonPrimitive("Oracle only support Sole ContractType!")));
|
||||||
Status.Error,
|
|
||||||
new JsonPrimitive("Oracle only support Sole ContractType!")));
|
|
||||||
}
|
}
|
||||||
// 权限校验 如果是contract 申请了MySQL等权限 报错
|
// 权限校验 如果是contract 申请了MySQL等权限 报错
|
||||||
if (cn.getYjsType() == YjsType.Contract) {
|
if (cn.getYjsType() == YjsType.Contract) {
|
||||||
for (Permission per : cn.getPermission()) {
|
for (Permission per : cn.getPermission()) {
|
||||||
if (per == Permission.SQL
|
if (per == Permission.SQL || per == Permission.Http || per == Permission.RocksDB
|
||||||
|| per == Permission.Http
|
|
||||||
|| per == Permission.RocksDB
|
|
||||||
|| per == Permission.MongoDB) {
|
|| per == Permission.MongoDB) {
|
||||||
LOGGER.debug("Contract can not have permissions of IO!");
|
LOGGER.debug("Contract can not have permissions of IO!");
|
||||||
return JsonUtil.toJson(
|
return JsonUtil.toJson(new ContractResult(Status.Error,
|
||||||
new ContractResult(
|
new JsonPrimitive("Contract can not have permissions of IO|")));
|
||||||
Status.Error,
|
|
||||||
new JsonPrimitive("Contract can not have permissions of IO|")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,45 +447,45 @@ public class ContractProcess {
|
|||||||
JavaScriptEntry.members = members;
|
JavaScriptEntry.members = members;
|
||||||
if (members != null)
|
if (members != null)
|
||||||
return members.size() + "";
|
return members.size() + "";
|
||||||
else return "0";
|
else
|
||||||
|
return "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String setContractBundle(Contract contract) {
|
public String setContractBundle(Contract contract) {
|
||||||
try {
|
try {
|
||||||
// long start = System.currentTimeMillis();
|
fixContractIfNecessary(contract);
|
||||||
// long start0 = start;
|
// long start = System.currentTimeMillis();
|
||||||
|
// long start0 = start;
|
||||||
this.contract = contract;
|
this.contract = contract;
|
||||||
|
|
||||||
JavaScriptEntry.random = new Random();
|
JavaScriptEntry.random = new Random();
|
||||||
JavaScriptEntry.invokeID = 0L;
|
JavaScriptEntry.invokeID = 0L;
|
||||||
JavaScriptEntry.random.setSeed(Integer.parseInt(contract.getID()));
|
JavaScriptEntry.random.setSeed(Integer.parseInt(contract.getID()));
|
||||||
JavaScriptEntry.numOfCopies = this.contract.getNumOfCopies();
|
JavaScriptEntry.numOfCopies = this.contract.getNumOfCopies();
|
||||||
JavaScriptEntry.shardingID =
|
JavaScriptEntry.shardingID = this.contract.getShardingId(); // 设置javaScriptEntry中的shardingID
|
||||||
this.contract.getShardingId(); // 设置javaScriptEntry中的shardingID
|
|
||||||
// JavaScriptEntry
|
// JavaScriptEntry
|
||||||
|
// contract.getCreateParam().get("repoId").getAsString()-->去获取repoId。
|
||||||
|
// 知道自己的BDOID --> repo的id。+contract.getID()
|
||||||
String zipPath = contract.getScriptStr();
|
String zipPath = contract.getScriptStr();
|
||||||
if (isArchiveFile(new File(zipPath))) {
|
if (isArchiveFile(new File(zipPath))) {
|
||||||
ZipFile zf = new ZipFile(zipPath);
|
ZipFile zf = new ZipFile(zipPath);
|
||||||
ContractZipBundle zipBundle = new YJSCompiler().compile(zf);
|
ContractZipBundle zipBundle = new YJSCompiler().compile(zf);
|
||||||
cn = zipBundle.mergeContractNode();
|
cn = zipBundle.mergeContractNode();
|
||||||
// check functionNodes
|
// check functionNodes
|
||||||
List<FunctionNode> functionNodes = cn.getFunctions();
|
|
||||||
injectHandlers();
|
injectHandlers();
|
||||||
|
|
||||||
this.contract.setYjsType(cn.getYjsType());
|
this.contract.setYjsType(cn.getYjsType());
|
||||||
memorySet = cn.memorySet;
|
memorySet = cn.memorySet;
|
||||||
this.contract.sourcePath = zipBundle.getManifest().sourcePath;
|
this.contract.sourcePath = zipBundle.getManifest().sourcePath;
|
||||||
|
|
||||||
LOGGER.debug(
|
LOGGER.debug("check sourcePath\n\tin-contract=" + this.contract.sourcePath
|
||||||
"check sourcePath\n\tin-contract="
|
+ "\n\tin-manifest=" + zipBundle.getManifest().sourcePath);
|
||||||
+ this.contract.sourcePath
|
|
||||||
+ "\n\tin-manifest="
|
|
||||||
+ zipBundle.getManifest().sourcePath);
|
|
||||||
// zhanghongwei
|
// zhanghongwei
|
||||||
|
|
||||||
/* if (ret.getManifest().getInsnLimit() != 0) {
|
/*
|
||||||
gasLimit=ret.getManifest().getInsnLimit();
|
* if (ret.getManifest().getInsnLimit() != 0) {
|
||||||
isInsnLimit = true;
|
* gasLimit=ret.getManifest().getInsnLimit(); isInsnLimit = true; }
|
||||||
}*/
|
*/
|
||||||
String ver = verifyOracleAndContractPermission(contract);
|
String ver = verifyOracleAndContractPermission(contract);
|
||||||
if (!ver.isEmpty()) {
|
if (!ver.isEmpty()) {
|
||||||
return ver;
|
return ver;
|
||||||
@@ -506,10 +496,8 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleLog();
|
handleLog();
|
||||||
|
|
||||||
// System.out.println("[ret.getManifest().getInsnLimit()]" +
|
// System.out.println("[ret.getManifest().getInsnLimit()]" +
|
||||||
// ret.getManifest().getInsnLimit());
|
// ret.getManifest().getInsnLimit());
|
||||||
|
|
||||||
engine = new DesktopEngine(zipBundle.getManifest(), zipPath, contract);
|
engine = new DesktopEngine(zipBundle.getManifest(), zipPath, contract);
|
||||||
engine.loadJar(zf);
|
engine.loadJar(zf);
|
||||||
engine.registerResource(new Resources(zf, engine.getClassLoad()));
|
engine.registerResource(new Resources(zf, engine.getClassLoad()));
|
||||||
@@ -520,14 +508,12 @@ public class ContractProcess {
|
|||||||
jo.add("loadContract", JsonUtil.parseObject(result));
|
jo.add("loadContract", JsonUtil.parseObject(result));
|
||||||
jo.addProperty("status", result.status.merge(onCreate.status).toString());
|
jo.addProperty("status", result.status.merge(onCreate.status).toString());
|
||||||
LOGGER.debug("result: " + jo.toString());
|
LOGGER.debug("result: " + jo.toString());
|
||||||
|
|
||||||
// doipModule的话,拉起DoipServer服务端口
|
// doipModule的话,拉起DoipServer服务端口
|
||||||
if(cn.getYjsType() == YjsType.DoipModule) {
|
if (cn.hasDoipModule()) {
|
||||||
// 只有一台机器去更新Router中的repoInfo就可以了
|
// 只有一台机器去更新Router中的repoInfo就可以了
|
||||||
updateRepoInfo(contract.getCreateParam());
|
updateRepoInfo(contract.getCreateParam());
|
||||||
invokeOnStartingDoipServer(cn, contract.getCreateParam());
|
invokeOnStartingDoipServer(cn, contract.getCreateParam(), jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jo.toString();
|
return jo.toString();
|
||||||
} else {
|
} else {
|
||||||
contract.setScript(FileUtil.getFileContent(zipPath));
|
contract.setScript(FileUtil.getFileContent(zipPath));
|
||||||
@@ -535,19 +521,27 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (MalformedJsonException | JsonSyntaxException e) {
|
} catch (MalformedJsonException | JsonSyntaxException e) {
|
||||||
return JsonUtil.toJson(
|
return JsonUtil.toJson(new ContractResult(Status.Error,
|
||||||
new ContractResult(
|
new JsonPrimitive("parse manifest.json error, not json format!")));
|
||||||
Status.Error,
|
|
||||||
new JsonPrimitive("parse manifest.json error, not json format!")));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
return JsonUtil.toJson(
|
return JsonUtil
|
||||||
new ContractResult(Status.Error, new JsonPrimitive(bo.toString())));
|
.toJson(new ContractResult(Status.Error, new JsonPrimitive(bo.toString())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void injectHandlers() {
|
private void fixContractIfNecessary(Contract contract) {
|
||||||
|
if (contract.getID() == null)
|
||||||
|
contract.setID(contract.getScriptStr().hashCode() + "");
|
||||||
|
if (contract.getPublicKey() == null) {
|
||||||
|
SM2KeyPair pair = SM2Util.generateSM2KeyPair();
|
||||||
|
contract.setKey(pair.getPrivateKeyStr());
|
||||||
|
contract.setPublicKey(pair.getPublicKeyStr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void injectHandlers() throws Exception {
|
||||||
// 正式启动
|
// 正式启动
|
||||||
if (!this.contract.isDebug()) {
|
if (!this.contract.isDebug()) {
|
||||||
// this.engine.getResources().loadAsString("/maskConfig.json");
|
// this.engine.getResources().loadAsString("/maskConfig.json");
|
||||||
@@ -560,31 +554,40 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DOOPBeforeExecHandler doopBeforeExecHandler = null;
|
||||||
|
DOOPAfterExecHandler doopAfterExecHandler = null;
|
||||||
|
doopRequestHandler = null;
|
||||||
for (FunctionNode fun : cn.getFunctions()) {
|
for (FunctionNode fun : cn.getFunctions()) {
|
||||||
if (fun.isConfidential()) {
|
if (fun.isConfidential()) {
|
||||||
fun.appendBeforeInvokeHandler(new ConfidentialHandler(fun));
|
fun.appendBeforeInvokeHandler(new ConfidentialHandler(fun));
|
||||||
}
|
}
|
||||||
ArgSchemaHandler argSchemaHandler = createHandlerIfExist(fun, fun.annotations, ArgSchemaHandler.class);
|
ArgSchemaHandler argSchemaHandler = createHandlerIfExist(fun, ArgSchemaHandler.class);
|
||||||
if (argSchemaHandler != null) {
|
if (argSchemaHandler != null) {
|
||||||
fun.appendBeforeInvokeHandler(argSchemaHandler);
|
fun.appendBeforeInvokeHandler(argSchemaHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fun.isExport()) {
|
if (fun.isExport()) {
|
||||||
//if(fun.annotations...)
|
// if(fun.annotations...)
|
||||||
AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class);
|
AccessHandler accessHandler = createHandlerIfExist(fun, AccessHandler.class);
|
||||||
if (accessHandler != null) {
|
if (accessHandler != null) {
|
||||||
fun.appendBeforeInvokeHandler(accessHandler);
|
fun.appendBeforeInvokeHandler(accessHandler);
|
||||||
}
|
}
|
||||||
fun.appendAfterInvokeHandler(new ObjToJsonHandler());
|
fun.appendAfterInvokeHandler(new ObjToJsonHandler());
|
||||||
|
ResultSchemaHandler resultSchemaHandler =
|
||||||
|
createHandlerIfExist(fun, ResultSchemaHandler.class);
|
||||||
|
if (resultSchemaHandler != null) {
|
||||||
|
fun.appendAfterInvokeHandler(resultSchemaHandler);
|
||||||
|
}
|
||||||
// fun.appendBeforeInvokeHandler(new ReadMeHandler());
|
// fun.appendBeforeInvokeHandler(new ReadMeHandler());
|
||||||
// Mask是用于返回真正结果之后,做一些偏移,以保护数据隐私。
|
// Mask是用于返回真正结果之后,做一些偏移,以保护数据隐私。
|
||||||
// if (fun.isMask()) {
|
// if (fun.isMask()) {
|
||||||
|
|
||||||
// String maskConfig =
|
// String maskConfig =
|
||||||
// engine.getResources().loadAsString("/maskConfig.json");
|
// engine.getResources().loadAsString("/maskConfig.json");
|
||||||
// System.out.println("injectMask"+maskConfig);
|
// System.out.println("injectMask"+maskConfig);
|
||||||
// System.out.println("injectMask"+this.contract.Mask);
|
// System.out.println("injectMask"+this.contract.Mask);
|
||||||
fun.appendAfterInvokeHandler(new MaskHandler());
|
// fun.appendAfterInvokeHandler(new MaskHandler());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
if (fun.isHomomorphicEncrypt()) {
|
if (fun.isHomomorphicEncrypt()) {
|
||||||
@@ -596,26 +599,32 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fun.isDoipOperation()) {
|
if (fun.isDoipOperation()) {
|
||||||
fun.appendBeforeInvokeHandler(DOOPBeforeExecHandler.createDOOPHandler());
|
if (doopRequestHandler == null) {
|
||||||
fun.appendAfterInvokeHandler(DOOPAfterExecHandler.createDOOPHandler());
|
doopRequestHandler = new DOOPRequestHandler();
|
||||||
|
}
|
||||||
|
fun.appendBeforeInvokeHandler(
|
||||||
|
new DOOPBeforeExecHandler(fun.getDoipOperationInfo().operation));
|
||||||
|
fun.appendAfterInvokeHandler(
|
||||||
|
new DOOPAfterExecHandler(fun.getDoipOperationInfo().operation));
|
||||||
|
doopRequestHandler.addDoipOperation(fun);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<T extends AnnotationHook> T createHandlerIfExist(FunctionNode function, List<AnnotationNode> annotations, Class<T> clz) {
|
<T extends AnnotationHook> T createHandlerIfExist(FunctionNode function, Class<T> clz) {
|
||||||
YJSAnnotation annotation = clz.getAnnotation(YJSAnnotation.class);
|
YJSAnnotation annotation = clz.getAnnotation(YJSAnnotation.class);
|
||||||
if (annotation == null) return null;
|
if (annotation == null)
|
||||||
if (annotations == null) return null;
|
return null;
|
||||||
for (AnnotationNode node : annotations) {
|
try {
|
||||||
if (annotation.name().equals(node.getType())) {
|
AnnotationNode node = function.getAnnotation(annotation.name());
|
||||||
try {
|
if (node == null)
|
||||||
Method m = clz.getDeclaredMethod("fromAnnotationNode", FunctionNode.class, AnnotationNode.class);
|
return null;
|
||||||
T result = (T) m.invoke(null, function, node);
|
Method m = clz.getDeclaredMethod("fromAnnotationNode", FunctionNode.class,
|
||||||
return result;
|
AnnotationNode.class);
|
||||||
} catch (Exception e) {
|
T result = (T) m.invoke(null, function, node);
|
||||||
e.printStackTrace();
|
return result;
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -633,9 +642,13 @@ public class ContractProcess {
|
|||||||
|
|
||||||
public String setContract(Contract contract) {
|
public String setContract(Contract contract) {
|
||||||
try {
|
try {
|
||||||
|
fixContractIfNecessary(contract);
|
||||||
JavaScriptEntry.random = new Random();
|
JavaScriptEntry.random = new Random();
|
||||||
JavaScriptEntry.invokeID = 0L;
|
JavaScriptEntry.invokeID = 0L;
|
||||||
JavaScriptEntry.random.setSeed(Integer.parseInt(contract.getID()));
|
if (contract.getID() == null)
|
||||||
|
JavaScriptEntry.random.setSeed(contract.getScriptStr().hashCode());
|
||||||
|
else
|
||||||
|
JavaScriptEntry.random.setSeed(Integer.parseInt(contract.getID()));
|
||||||
JavaScriptEntry.numOfCopies = contract.getNumOfCopies();
|
JavaScriptEntry.numOfCopies = contract.getNumOfCopies();
|
||||||
// TODO Optimize, 4 seconds takes to create an Engine.
|
// TODO Optimize, 4 seconds takes to create an Engine.
|
||||||
engine = new DesktopEngine();
|
engine = new DesktopEngine();
|
||||||
@@ -653,8 +666,7 @@ public class ContractProcess {
|
|||||||
handleLog();
|
handleLog();
|
||||||
LOGGER.info("load script, contract:" + JsonUtil.toJson(contract.getScriptStr()));
|
LOGGER.info("load script, contract:" + JsonUtil.toJson(contract.getScriptStr()));
|
||||||
LOGGER.info("load cn:" + JsonUtil.toJson(cn));
|
LOGGER.info("load cn:" + JsonUtil.toJson(cn));
|
||||||
ContractResult ret =
|
ContractResult ret = engine.loadContract(contract, cn, cn.getInstrumentBranch());
|
||||||
engine.loadContract(contract, cn, cn.getInstrumentBranch());
|
|
||||||
ContractResult onCreate = invokeOnCreate(contract.getCreateParam());
|
ContractResult onCreate = invokeOnCreate(contract.getCreateParam());
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
jo.add("onCreate", JsonUtil.parseObject(onCreate));
|
jo.add("onCreate", JsonUtil.parseObject(onCreate));
|
||||||
@@ -663,32 +675,36 @@ public class ContractProcess {
|
|||||||
LOGGER.debug("result: " + jo.toString());
|
LOGGER.debug("result: " + jo.toString());
|
||||||
|
|
||||||
// doipModule的话,拉起DoipServer服务端口
|
// doipModule的话,拉起DoipServer服务端口
|
||||||
if(cn.getYjsType() == YjsType.DoipModule) {
|
if (cn.getYjsType() == YjsType.DoipModule) {
|
||||||
updateRepoInfo(contract.getCreateParam());
|
updateRepoInfo(contract.getCreateParam());
|
||||||
invokeOnStartingDoipServer(cn, contract.getCreateParam());
|
invokeOnStartingDoipServer(cn, contract.getCreateParam(), jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jo.toString();
|
return jo.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
return JsonUtil.toJson(
|
return JsonUtil
|
||||||
new ContractResult(Status.Error, new JsonPrimitive(bo.toString())));
|
.toJson(new ContractResult(Status.Error, new JsonPrimitive(bo.toString())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRepoInfo(JsonElement arg) throws Exception {
|
public void updateRepoInfo(JsonElement arg) throws Exception {
|
||||||
// 只有0号节点需要初始化IRP连接去updateRepoInfo
|
// 只有0号节点需要初始化IRP连接去updateRepoInfo
|
||||||
if(JavaScriptEntry.shardingID == 0) {
|
// just disable this part
|
||||||
|
if (JavaScriptEntry.shardingID == -1) {
|
||||||
// DOOP relevant logic
|
// DOOP relevant logic
|
||||||
DoipClusterServer server = DoipClusterServer.getDOOPServerInstance();
|
DoipClusterServer server = DoipClusterServer.getDOOPServerInstance();
|
||||||
if(server == null) {
|
if (server == null) {
|
||||||
JsonObject createParams = arg.getAsJsonObject();
|
JsonObject createParams = arg.getAsJsonObject();
|
||||||
if(createParams.has("router")) {
|
if (createParams.has("router")) {
|
||||||
JsonElement routerInfo = createParams.get("router");
|
JsonElement routerInfo = createParams.get("router");
|
||||||
if(!routerInfo.isJsonObject()) throw new Exception("Provide wrong router info in create params to DoipModule");
|
if (!routerInfo.isJsonObject())
|
||||||
|
throw new Exception(
|
||||||
|
"Provide wrong router info in create params to DoipModule");
|
||||||
else {
|
else {
|
||||||
EndpointConfig endpointConfig = JsonUtil.GSON.fromJson(routerInfo.getAsJsonObject(), EndpointConfig.class);
|
EndpointConfig endpointConfig = JsonUtil.GSON
|
||||||
|
.fromJson(routerInfo.getAsJsonObject(), EndpointConfig.class);
|
||||||
DoipClusterServer.createDOOPServerInstance(endpointConfig);
|
DoipClusterServer.createDOOPServerInstance(endpointConfig);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -697,79 +713,57 @@ public class ContractProcess {
|
|||||||
|
|
||||||
server = DoipClusterServer.getDOOPServerInstance();
|
server = DoipClusterServer.getDOOPServerInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只有一台机器去更新Router中的repoInfo就可以了
|
// 只有一台机器去更新Router中的repoInfo就可以了
|
||||||
|
|
||||||
server.updateRepoInfo(contract, cn);
|
server.updateRepoInfo(contract, cn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeOnStartingDoipServer(ContractNode cn, JsonElement arg) {
|
public void invokeOnStartingDoipServer(ContractNode cn, JsonElement arg,
|
||||||
|
JsonObject returnValue) {
|
||||||
ContractRequest onStartingDoipServer = new ContractRequest();
|
ContractRequest onStartingDoipServer = new ContractRequest();
|
||||||
onStartingDoipServer.setAction("onServerStart");
|
onStartingDoipServer.setAction("onServerStart");
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
if (engine != null && engine.getManifest() != null && engine.getManifest().createParam != null)
|
if (engine != null && engine.getManifest() != null
|
||||||
|
&& engine.getManifest().createParam != null)
|
||||||
arg = engine.getManifest().createParam;
|
arg = engine.getManifest().createParam;
|
||||||
else
|
else
|
||||||
arg = new JsonPrimitive("");
|
arg = new JsonPrimitive("");
|
||||||
}
|
}
|
||||||
onStartingDoipServer.setArg(arg);
|
onStartingDoipServer.setArg(arg);
|
||||||
LOGGER.debug("invoke onStartingDoipServer, param:" + onStartingDoipServer.getArg().toString());
|
LOGGER.debug(
|
||||||
|
"invoke onStartingDoipServer, param:" + onStartingDoipServer.getArg().toString());
|
||||||
onStartingDoipServer.setRequester(contract.getOwner());
|
onStartingDoipServer.setRequester(contract.getOwner());
|
||||||
if (contract.getDoipFlag() && null != contract.getDOI() && !contract.getDOI().isEmpty()) {
|
|
||||||
onStartingDoipServer.setRequesterDOI(contract.getDOI());
|
|
||||||
} else {
|
|
||||||
onStartingDoipServer.setRequesterDOI("empty");
|
|
||||||
}
|
|
||||||
FunctionNode funNode = cn.getFunction("onServerStart");
|
FunctionNode funNode = cn.getFunction("onServerStart");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JsonElement onStartingDoipServerRes = invoke(onStartingDoipServer, funNode).result;
|
JsonElement onStartingDoipServerRes = invoke(onStartingDoipServer, funNode).result;
|
||||||
LOGGER.info("Fetch the onStartingDoipServerRes from router successfully, the result is " + onStartingDoipServerRes);
|
returnValue.add("doipModuleStartResult", onStartingDoipServerRes);
|
||||||
if(onStartingDoipServerRes.isJsonObject()) {
|
int startPort = ContractProcess.instance.server.getPort() + 1;
|
||||||
JsonObject onStartingDoipServerJO = onStartingDoipServerRes.getAsJsonObject();
|
if (arg.isJsonObject() && arg.getAsJsonObject().has("doipStartPort")) {
|
||||||
if (!onStartingDoipServerJO.has("doipAddr")) {
|
startPort = arg.getAsJsonObject().get("doipStartPort").getAsInt();
|
||||||
throw new Exception("the doipAddr is improper");
|
|
||||||
} else {
|
|
||||||
JsonElement doipAddrJE = onStartingDoipServerJO.get("doipAddr");
|
|
||||||
if(doipAddrJE.isJsonArray()) {
|
|
||||||
JsonArray doipAddrJA = doipAddrJE.getAsJsonArray();
|
|
||||||
for(int i = 0 ; i < doipAddrJA.size() ; i++) {
|
|
||||||
DoipClusterServer.startDoipServer(doipAddrJA.get(i).getAsString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DoipClusterServer.startDoipServer(doipAddrJE.getAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Exception("the onStartingDoipServerRes doesn't return the correct json result");
|
|
||||||
}
|
}
|
||||||
|
LOGGER.info("Fetch the onStartingDoipServerRes from router successfully, the result is "
|
||||||
|
+ onStartingDoipServerRes);
|
||||||
|
int doipListenPort =
|
||||||
|
DoipClusterServer.startDoipServer(startPort, onStartingDoipServerRes);
|
||||||
|
returnValue.addProperty("doipListenPort", doipListenPort);
|
||||||
|
this.contract.setDoipPort(doipListenPort);
|
||||||
|
returnValue.addProperty("doipStartPort", startPort);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("DoipLocalSingleton cannot starts properly, plz check the onServerStart function");
|
LOGGER.error(
|
||||||
|
"DoipLocalSingleton cannot starts properly, plz check the onServerStart function");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
funNode = cn.getFunction("onInitSharableVars");
|
||||||
|
|
||||||
public void invokeOnStartingDoipServer2(JsonElement arg) {
|
if (funNode != null) {
|
||||||
Object[] funcArgs = new Object[3];
|
ContractRequest requestForInitVar = new ContractRequest();
|
||||||
funcArgs[0] = JSONTool.convertJsonElementToMirror(arg);
|
requestForInitVar.setAction("onInitSharableVars");
|
||||||
funcArgs[1] = contract.getOwner();
|
requestForInitVar.setArg(onStartingDoipServer.getArg());
|
||||||
if (contract.getDoipFlag() && null != contract.getDOI() && !contract.getDOI().isEmpty()) {
|
requestForInitVar.setRequester(onStartingDoipServer.getRequester());
|
||||||
funcArgs[2] = contract.getDOI();
|
JsonElement onInitSharableVars = invoke(requestForInitVar, funNode).result;
|
||||||
} else {
|
returnValue.add("onInitSharableVars", onInitSharableVars);
|
||||||
funcArgs[2] = "empty";
|
|
||||||
}
|
|
||||||
Object result = engine.invokeFunction("onServerStart", funcArgs);
|
|
||||||
Map<String, String> resMap = (Map<String, String>) result;
|
|
||||||
try {
|
|
||||||
if (!resMap.containsKey("doipAddr")) {
|
|
||||||
throw new Exception("the doipAddr is improper");
|
|
||||||
} else {
|
|
||||||
DoipClusterServer.startDoipServer(resMap.get("doipAddr"));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("DoipLocalSingleton cannot starts properly, plz check the onServerStart function");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,7 +787,8 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fun.getLogToBDContract()) detail.append("bdcontract;");
|
if (fun.getLogToBDContract())
|
||||||
|
detail.append("bdcontract;");
|
||||||
if (fun.getLogToNamedLedger()) {
|
if (fun.getLogToNamedLedger()) {
|
||||||
for (String str : fun.getLedgerNames()) {
|
for (String str : fun.getLedgerNames()) {
|
||||||
detail.append("bdledger:").append(str).append(";");
|
detail.append("bdledger:").append(str).append(";");
|
||||||
@@ -831,9 +826,6 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JavaScriptEntry.setSM2KeyPair(contract.getPublicKey(), contract.getKey());
|
JavaScriptEntry.setSM2KeyPair(contract.getPublicKey(), contract.getKey());
|
||||||
if (null != contract.getDOI() && !contract.getDOI().isEmpty()) {
|
|
||||||
JavaScriptEntry.doi = contract.getDOI();
|
|
||||||
}
|
|
||||||
if (null != contract.getAuthInfoPersistDOI()
|
if (null != contract.getAuthInfoPersistDOI()
|
||||||
&& !contract.getAuthInfoPersistDOI().isEmpty()) {
|
&& !contract.getAuthInfoPersistDOI().isEmpty()) {
|
||||||
JavaScriptEntry.authInfoPersistDOI = contract.getAuthInfoPersistDOI();
|
JavaScriptEntry.authInfoPersistDOI = contract.getAuthInfoPersistDOI();
|
||||||
@@ -842,7 +834,8 @@ public class ContractProcess {
|
|||||||
ContractRequest onCreate = new ContractRequest();
|
ContractRequest onCreate = new ContractRequest();
|
||||||
onCreate.setAction("onCreate");
|
onCreate.setAction("onCreate");
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
if (engine != null && engine.getManifest() != null && engine.getManifest().createParam != null)
|
if (engine != null && engine.getManifest() != null
|
||||||
|
&& engine.getManifest().createParam != null)
|
||||||
arg = engine.getManifest().createParam;
|
arg = engine.getManifest().createParam;
|
||||||
else
|
else
|
||||||
arg = new JsonPrimitive("");
|
arg = new JsonPrimitive("");
|
||||||
@@ -850,11 +843,6 @@ public class ContractProcess {
|
|||||||
onCreate.setArg(arg);
|
onCreate.setArg(arg);
|
||||||
LOGGER.debug("invoke onCreate, param:" + onCreate.getArg().toString());
|
LOGGER.debug("invoke onCreate, param:" + onCreate.getArg().toString());
|
||||||
onCreate.setRequester(contract.getOwner());
|
onCreate.setRequester(contract.getOwner());
|
||||||
if (contract.getDoipFlag() && null != contract.getDOI() && !contract.getDOI().isEmpty()) {
|
|
||||||
onCreate.setRequesterDOI(contract.getDOI());
|
|
||||||
} else {
|
|
||||||
onCreate.setRequesterDOI("empty");
|
|
||||||
}
|
|
||||||
FunctionNode funNode = cn.getFunction("onCreate");
|
FunctionNode funNode = cn.getFunction("onCreate");
|
||||||
return invoke(onCreate, funNode);
|
return invoke(onCreate, funNode);
|
||||||
}
|
}
|
||||||
@@ -872,13 +860,6 @@ public class ContractProcess {
|
|||||||
else
|
else
|
||||||
onRecover.setArg(arg);
|
onRecover.setArg(arg);
|
||||||
onRecover.setRequester(contract.getOwner());
|
onRecover.setRequester(contract.getOwner());
|
||||||
if (contract.getDoipFlag()
|
|
||||||
&& (contract.getDOI() != null)
|
|
||||||
&& (contract.getDOI().length() > 0)) {
|
|
||||||
onRecover.setRequesterDOI(contract.getDOI());
|
|
||||||
} else {
|
|
||||||
onRecover.setRequesterDOI("empty");
|
|
||||||
}
|
|
||||||
FunctionNode funNode = cn.getFunction("onRecover");
|
FunctionNode funNode = cn.getFunction("onRecover");
|
||||||
return invoke(onRecover, funNode);
|
return invoke(onRecover, funNode);
|
||||||
}
|
}
|
||||||
@@ -927,8 +908,7 @@ public class ContractProcess {
|
|||||||
List<Long> hashes = logIndex.request(offset, size);
|
List<Long> hashes = logIndex.request(offset, size);
|
||||||
List<Map<String, String>> jo = new ArrayList<>();
|
List<Map<String, String>> jo = new ArrayList<>();
|
||||||
|
|
||||||
TypeToken<Map<String, String>> token = new TypeToken<Map<String, String>>() {
|
TypeToken<Map<String, String>> token = new TypeToken<Map<String, String>>() {};
|
||||||
};
|
|
||||||
for (Long hash : hashes)
|
for (Long hash : hashes)
|
||||||
try {
|
try {
|
||||||
Map<String, String> obj =
|
Map<String, String> obj =
|
||||||
@@ -943,8 +923,7 @@ public class ContractProcess {
|
|||||||
public String requestLast(int count) {
|
public String requestLast(int count) {
|
||||||
List<Long> hashes = logIndex.requestLast(count);
|
List<Long> hashes = logIndex.requestLast(count);
|
||||||
List<Map<String, String>> jo = new ArrayList<>();
|
List<Map<String, String>> jo = new ArrayList<>();
|
||||||
TypeToken<Map<String, String>> token = new TypeToken<Map<String, String>>() {
|
TypeToken<Map<String, String>> token = new TypeToken<Map<String, String>>() {};
|
||||||
};
|
|
||||||
String log;
|
String log;
|
||||||
for (Long hash : hashes)
|
for (Long hash : hashes)
|
||||||
try {
|
try {
|
||||||
@@ -954,8 +933,8 @@ public class ContractProcess {
|
|||||||
}
|
}
|
||||||
Map<String, String> obj = JsonUtil.fromJson(log, token.getType());
|
Map<String, String> obj = JsonUtil.fromJson(log, token.getType());
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
System.out.println(
|
System.out
|
||||||
"[ContractProcess] requestLast, parseJsonError:" + log + "==");
|
.println("[ContractProcess] requestLast, parseJsonError:" + log + "==");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
obj.put("hash", hash + "");
|
obj.put("hash", hash + "");
|
||||||
@@ -998,9 +977,8 @@ public class ContractProcess {
|
|||||||
try {
|
try {
|
||||||
request = JsonUtil.fromJson(arg, ContractRequest.class);
|
request = JsonUtil.fromJson(arg, ContractRequest.class);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
result =
|
result = new ContractResult(ContractResult.Status.Error,
|
||||||
new ContractResult(
|
new JsonPrimitive("Illegal Arguments!"));
|
||||||
ContractResult.Status.Error, new JsonPrimitive("Illegal Arguments!"));
|
|
||||||
return JsonUtil.toJson(result);
|
return JsonUtil.toJson(result);
|
||||||
}
|
}
|
||||||
String reqID = request.getRequestID();
|
String reqID = request.getRequestID();
|
||||||
@@ -1021,9 +999,9 @@ public class ContractProcess {
|
|||||||
engine.redirectTracePS(new Logger(bo, this));
|
engine.redirectTracePS(new Logger(bo, this));
|
||||||
result = engine.executeContract(request);
|
result = engine.executeContract(request);
|
||||||
result.analysis = bo.toString();
|
result.analysis = bo.toString();
|
||||||
System.out.println(
|
System.out.println("[ContractProcess] result.analysis = " + result.analysis); // 动态分析bug
|
||||||
"[ContractProcess] result.analysis = "
|
// null
|
||||||
+ result.analysis); // 动态分析bug null pointer
|
// pointer
|
||||||
// branchResult = JsonUtil.toJson(result);
|
// branchResult = JsonUtil.toJson(result);
|
||||||
// branchTrace = result.analysis;
|
// branchTrace = result.analysis;
|
||||||
engine.redirectTracePS(previous);
|
engine.redirectTracePS(previous);
|
||||||
@@ -1042,16 +1020,8 @@ public class ContractProcess {
|
|||||||
evaluatesAnalysis(request.getAction());
|
evaluatesAnalysis(request.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.redirectTracePS(
|
engine.redirectTracePS(new ProgramPointCounter(bo, this, gasLimit, functionIndex,
|
||||||
new ProgramPointCounter(
|
request.getValue(), 0L, request.getAction(), ppCountMap));
|
||||||
bo,
|
|
||||||
this,
|
|
||||||
gasLimit,
|
|
||||||
functionIndex,
|
|
||||||
request.getValue(),
|
|
||||||
0L,
|
|
||||||
request.getAction(),
|
|
||||||
ppCountMap));
|
|
||||||
result = engine.executeContract(request);
|
result = engine.executeContract(request);
|
||||||
|
|
||||||
result.analysis = bo.toString();
|
result.analysis = bo.toString();
|
||||||
@@ -1092,13 +1062,12 @@ public class ContractProcess {
|
|||||||
for (String s : function) {
|
for (String s : function) {
|
||||||
MethodNode mn = methods.get(s);
|
MethodNode mn = methods.get(s);
|
||||||
if (mn != null) {
|
if (mn != null) {
|
||||||
CFGraph cfg =
|
CFGraph cfg = new CFGraph(mn) {
|
||||||
new CFGraph(mn) {
|
@Override
|
||||||
@Override
|
public BasicBlock getBasicBlock(int id) {
|
||||||
public BasicBlock getBasicBlock(int id) {
|
return new BasicBlock(id);
|
||||||
return new BasicBlock(id);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
// cfg.printSelf();
|
// cfg.printSelf();
|
||||||
CFGmap.put(s, cfg);
|
CFGmap.put(s, cfg);
|
||||||
PPCount countFee = new PPCount(cfg, flag);
|
PPCount countFee = new PPCount(cfg, flag);
|
||||||
@@ -1160,11 +1129,8 @@ public class ContractProcess {
|
|||||||
|
|
||||||
TaintBB bb = cfg.getLastBlock();
|
TaintBB bb = cfg.getLastBlock();
|
||||||
result.analysis = bb.getResultWithTaintBit();
|
result.analysis = bb.getResultWithTaintBit();
|
||||||
System.out.println(
|
System.out.println("[ContractProcess] dynamically verify: " + ac.getAction() + "-->"
|
||||||
"[ContractProcess] dynamically verify: "
|
+ result.analysis);
|
||||||
+ ac.getAction()
|
|
||||||
+ "-->"
|
|
||||||
+ result.analysis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1186,8 +1152,7 @@ public class ContractProcess {
|
|||||||
return !JavaScriptEntry.topic_handlers.isEmpty();
|
return !JavaScriptEntry.topic_handlers.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beforeSuicide() {
|
public void beforeSuicide() {}
|
||||||
}
|
|
||||||
|
|
||||||
public String redo(String path) {
|
public String redo(String path) {
|
||||||
return engine.syncUtil.redo(path);
|
return engine.syncUtil.redo(path);
|
||||||
@@ -1226,7 +1191,7 @@ public class ContractProcess {
|
|||||||
public void writeContractDB(Map<String, String> data) {
|
public void writeContractDB(Map<String, String> data) {
|
||||||
String path = dbPath;
|
String path = dbPath;
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
// return "nopath";
|
// return "nopath";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -1236,14 +1201,13 @@ public class ContractProcess {
|
|||||||
edion.put(String.valueOf(hash), result);
|
edion.put(String.valueOf(hash), result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
// return "failed";
|
// return "failed";
|
||||||
}
|
}
|
||||||
// return "success";
|
// return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() {
|
protected void finalize() {}
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeclaredEvents() {
|
public String getDeclaredEvents() {
|
||||||
return JsonUtil.toJson(cn.events);
|
return JsonUtil.toJson(cn.events);
|
||||||
@@ -1258,8 +1222,8 @@ public class ContractProcess {
|
|||||||
for (FunctionNode fn : cn.getFunctions()) {
|
for (FunctionNode fn : cn.getFunctions()) {
|
||||||
if (fn.isExport() && !fn.functionName.equals("onCreate")) {
|
if (fn.isExport() && !fn.functionName.equals("onCreate")) {
|
||||||
function.add(fn.functionName);
|
function.add(fn.functionName);
|
||||||
FunctionDesp desp =
|
FunctionDesp desp = new FunctionDesp(fn.functionName, fn.annotations,
|
||||||
new FunctionDesp(fn.functionName, fn.annotations, fn.getRouteInfo(), fn.getJoinInfo(), fn.isView());
|
fn.getRouteInfo(), fn.getJoinInfo(), fn.isView());
|
||||||
ret.add(desp);
|
ret.add(desp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1280,11 +1244,8 @@ public class ContractProcess {
|
|||||||
|
|
||||||
public String startAutoDump() {
|
public String startAutoDump() {
|
||||||
String dumpPeriod = projectConfig.getDumpPeriod();
|
String dumpPeriod = projectConfig.getDumpPeriod();
|
||||||
System.out.println(
|
System.out.println("[ContractProcess] startAutoDump : " + cn.getContractName()
|
||||||
"[ContractProcess] startAutoDump : "
|
+ " period = " + dumpPeriod);
|
||||||
+ cn.getContractName()
|
|
||||||
+ " period = "
|
|
||||||
+ dumpPeriod);
|
|
||||||
String status = "startAutoDump status 0";
|
String status = "startAutoDump status 0";
|
||||||
if (null != dt) {
|
if (null != dt) {
|
||||||
if (null == dumpPeriod || dumpPeriod.isEmpty()) {
|
if (null == dumpPeriod || dumpPeriod.isEmpty()) {
|
||||||
@@ -1389,21 +1350,21 @@ public class ContractProcess {
|
|||||||
if (period != null && period.length() > 0) {
|
if (period != null && period.length() > 0) {
|
||||||
changeDumpPeriod(period);
|
changeDumpPeriod(period);
|
||||||
}
|
}
|
||||||
// System.out.println("ContractProcessMask");
|
// System.out.println("ContractProcessMask");
|
||||||
// JsonObject argsJS = JsonParser.parseString(args).getAsJsonObject();
|
// JsonObject argsJS = JsonParser.parseString(args).getAsJsonObject();
|
||||||
// String contractID = "";
|
// String contractID = "";
|
||||||
// String operation = "";
|
// String operation = "";
|
||||||
// JsonElement mask = JsonParser.parseString("");
|
// JsonElement mask = JsonParser.parseString("");
|
||||||
// if (argsJS.has("contractID") && argsJS.has("operation") && argsJS.has("maskInfo"))
|
// if (argsJS.has("contractID") && argsJS.has("operation") && argsJS.has("maskInfo"))
|
||||||
// {
|
// {
|
||||||
// contractID = argsJS.get("contractID").getAsString();
|
// contractID = argsJS.get("contractID").getAsString();
|
||||||
// System.out.println(contractID);
|
// System.out.println(contractID);
|
||||||
// operation = argsJS.get("operation").getAsString();
|
// operation = argsJS.get("operation").getAsString();
|
||||||
// System.out.println(operation);
|
// System.out.println(operation);
|
||||||
// mask = argsJS.get("maskInfo");
|
// mask = argsJS.get("maskInfo");
|
||||||
// System.out.println("mask" + mask);
|
// System.out.println("mask" + mask);
|
||||||
// this.contract.setMask(operation, mask);
|
// this.contract.setMask(operation, mask);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDependentContracts() {
|
public String getDependentContracts() {
|
||||||
@@ -1465,9 +1426,8 @@ public class ContractProcess {
|
|||||||
private class DumpTask extends TimerTask {
|
private class DumpTask extends TimerTask {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println(
|
System.out.println("[ContractProcess DumpTask] auto dump period : "
|
||||||
"[ContractProcess DumpTask] auto dump period : "
|
+ projectConfig.getDumpPeriod());
|
||||||
+ projectConfig.getDumpPeriod());
|
|
||||||
File file1 = new File(dir);
|
File file1 = new File(dir);
|
||||||
File file2 = new File(file1.getParent());
|
File file2 = new File(file1.getParent());
|
||||||
String dir2 = file2.getParent() + "/memory/";
|
String dir2 = file2.getParent() + "/memory/";
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ public class SM2Helper {
|
|||||||
backupFile(new File("./cmconfig.json"));
|
backupFile(new File("./cmconfig.json"));
|
||||||
System.out.println("Generate file: cmconfig.json");
|
System.out.println("Generate file: cmconfig.json");
|
||||||
String content = FileUtil.getFileContent("./cmconfig.json.template");
|
String content = FileUtil.getFileContent("./cmconfig.json.template");
|
||||||
JsonObject jo = JsonParser.parseReader(new FileReader("cmvar.json")).getAsJsonObject();
|
JsonObject jo =
|
||||||
|
JsonParser.parseReader(new FileReader("cmvar.json")).getAsJsonObject();
|
||||||
for (String key : jo.keySet()) {
|
for (String key : jo.keySet()) {
|
||||||
content = content.replaceAll(key, jo.get(key).getAsString());
|
content = content.replaceAll(key, jo.get(key).getAsString());
|
||||||
}
|
}
|
||||||
JsonObject keypair = JsonParser.parseReader(new FileReader("manager.keypair")).getAsJsonObject();
|
JsonObject keypair =
|
||||||
|
JsonParser.parseReader(new FileReader("manager.keypair")).getAsJsonObject();
|
||||||
content = content.replaceAll("_PRIVKEY", keypair.get("privateKey").getAsString());
|
content = content.replaceAll("_PRIVKEY", keypair.get("privateKey").getAsString());
|
||||||
content = content.replaceAll("_PUBKEY", keypair.get("publicKey").getAsString());
|
content = content.replaceAll("_PUBKEY", keypair.get("publicKey").getAsString());
|
||||||
content = content.replaceAll("CMI", System.currentTimeMillis() + "");
|
content = content.replaceAll("CMI", System.currentTimeMillis() + "");
|
||||||
@@ -58,15 +60,18 @@ public class SM2Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void backupFile(File file) {
|
private static void backupFile(File file) {
|
||||||
if (!file.exists()) return;
|
if (!file.exists())
|
||||||
|
return;
|
||||||
File backup = null;
|
File backup = null;
|
||||||
for (int i = 0; i <= 100; i++) {
|
for (int i = 0; i <= 100; i++) {
|
||||||
if (i == 100) throw new IllegalArgumentException("failed to backup:" + file.getAbsolutePath());
|
if (i == 100)
|
||||||
|
throw new IllegalArgumentException("failed to backup:" + file.getAbsolutePath());
|
||||||
backup = new File(file.getParent(), file.getName() + "." + i);
|
backup = new File(file.getParent(), file.getName() + "." + i);
|
||||||
if (!backup.exists())
|
if (!backup.exists())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FileUtil.copyFile(file, backup);
|
FileUtil.copyFile(file, backup);
|
||||||
System.out.println("Backup: " + file.getAbsolutePath() + " --> " + backup.getAbsolutePath());
|
System.out
|
||||||
|
.println("Backup: " + file.getAbsolutePath() + " --> " + backup.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.objectweb.asm.tree.ClassNode;
|
|||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
@@ -44,11 +43,8 @@ public class FSAnalysis extends BreadthFirstSearch<TaintResult, TaintBB> {
|
|||||||
setToAnalysis(toAnalysis);
|
setToAnalysis(toAnalysis);
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
System.out.println("===Method:" + cfg.getMethodNode().name + cfg.getMethodNode().desc);
|
System.out.println("===Method:" + cfg.getMethodNode().name + cfg.getMethodNode().desc);
|
||||||
System.out.println(
|
System.out.println("===Local:" + cfg.getMethodNode().maxLocals + " "
|
||||||
"===Local:"
|
+ cfg.getMethodNode().maxStack);
|
||||||
+ cfg.getMethodNode().maxLocals
|
|
||||||
+ " "
|
|
||||||
+ cfg.getMethodNode().maxStack);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,9 +77,8 @@ public class FSAnalysis extends BreadthFirstSearch<TaintResult, TaintBB> {
|
|||||||
ContractZipBundle czb = compiler.compile(zf);
|
ContractZipBundle czb = compiler.compile(zf);
|
||||||
cn = czb.mergeContractNode();
|
cn = czb.mergeContractNode();
|
||||||
} else {
|
} else {
|
||||||
cn =
|
cn = compiler.compile(new ByteArrayInputStream(script.getBytes()),
|
||||||
compiler.compile(
|
"contract_main.yjs");
|
||||||
new ByteArrayInputStream(script.getBytes()), "contract_main.yjs");
|
|
||||||
}
|
}
|
||||||
DesktopEngine engine = new DesktopEngine(); // engine.loadJar(zf);
|
DesktopEngine engine = new DesktopEngine(); // engine.loadJar(zf);
|
||||||
engine.loadContract(c, cn, false);
|
engine.loadContract(c, cn, false);
|
||||||
@@ -109,7 +104,8 @@ public class FSAnalysis extends BreadthFirstSearch<TaintResult, TaintBB> {
|
|||||||
FSAnalysis analysis = new FSAnalysis(cfg);
|
FSAnalysis analysis = new FSAnalysis(cfg);
|
||||||
analysis.analysis();
|
analysis.analysis();
|
||||||
TaintBB bb = cfg.getLastBlock();
|
TaintBB bb = cfg.getLastBlock();
|
||||||
if (bb != null) result.put(fn.functionName, bb.getResult());
|
if (bb != null)
|
||||||
|
result.put(fn.functionName, bb.getResult());
|
||||||
cfg.printSelf();
|
cfg.printSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ public class AccountIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LenVarTimeSerialIndex2 index = getIndexFile(getString(args, "account") + getString(args, "file"));
|
LenVarTimeSerialIndex2 index =
|
||||||
|
getIndexFile(getString(args, "account") + getString(args, "file"));
|
||||||
long startTime = getLong(args, "startTime");
|
long startTime = getLong(args, "startTime");
|
||||||
long endTime = getLong(args, "endTime");
|
long endTime = getLong(args, "endTime");
|
||||||
List<byte[]> result = index.requestByTime(startTime, endTime);
|
List<byte[]> result = index.requestByTime(startTime, endTime);
|
||||||
@@ -183,7 +184,8 @@ public class AccountIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LenVarTimeSerialIndex2 index = getIndexFile(getString(args, "account") + getString(args, "file"));
|
LenVarTimeSerialIndex2 index =
|
||||||
|
getIndexFile(getString(args, "account") + getString(args, "file"));
|
||||||
long date = getLong(args, "date");
|
long date = getLong(args, "date");
|
||||||
String content = getString(args, "content");
|
String content = getString(args, "content");
|
||||||
index.manullyIndex(date, HashUtil.str16ToBytes(content));
|
index.manullyIndex(date, HashUtil.str16ToBytes(content));
|
||||||
|
|||||||
@@ -44,15 +44,14 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
import static org.bdware.sc.event.REvent.REventType.*;
|
import static org.bdware.sc.event.REvent.REventType.*;
|
||||||
|
|
||||||
public class JavaScriptEntry {
|
public class JavaScriptEntry {
|
||||||
// private static final HostnameVerifier DO_NOT_VERIFY = (hostname, session) -> true;
|
// private static final HostnameVerifier DO_NOT_VERIFY = (hostname, session) -> true;
|
||||||
public static final Map<String, ScriptFunction> topic_handlers = new HashMap<>();
|
public static final Map<String, ScriptFunction> topic_handlers = new HashMap<>();
|
||||||
private static final Logger LOGGER = LogManager.getLogger(JavaScriptEntry.class);
|
private static final Logger LOGGER = LogManager.getLogger(JavaScriptEntry.class);
|
||||||
public static NashornScriptEngine currentEngine;
|
public static NashornScriptEngine currentEngine;
|
||||||
public static SyncMechUtil currentSyncUtil;
|
public static SyncMechUtil currentSyncUtil;
|
||||||
// public static int contractManagerPort;
|
// public static int contractManagerPort;
|
||||||
public static Random random;
|
public static Random random;
|
||||||
public static long invokeID;
|
public static long invokeID;
|
||||||
public static String doi;
|
|
||||||
public static String authInfoPersistDOI;
|
public static String authInfoPersistDOI;
|
||||||
public static SocketGet get; // public static CloseableHttpClient httpClient = getHttpClient();
|
public static SocketGet get; // public static CloseableHttpClient httpClient = getHttpClient();
|
||||||
public static int numOfCopies;
|
public static int numOfCopies;
|
||||||
@@ -79,9 +78,8 @@ public class JavaScriptEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setSM2KeyPair(String pubKey, String privKey) {
|
public static void setSM2KeyPair(String pubKey, String privKey) {
|
||||||
keyPair =
|
keyPair = new SM2KeyPair(SM2KeyPair.publicKeyStr2ECPoint(pubKey),
|
||||||
new SM2KeyPair(
|
new BigInteger(privKey, 16));
|
||||||
SM2KeyPair.publicKeyStr2ECPoint(pubKey), new BigInteger(privKey, 16));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SM2KeyPair getKeyPair() {
|
public static SM2KeyPair getKeyPair() {
|
||||||
@@ -127,17 +125,17 @@ public class JavaScriptEntry {
|
|||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String http(String baseUrl, String method, Map<String, String> header,
|
// public static String http(String baseUrl, String method, Map<String, String> header,
|
||||||
// Map<String, String> argMap,
|
// Map<String, String> argMap,
|
||||||
// List<String> reservedList) {
|
// List<String> reservedList) {
|
||||||
// return HttpUtil.request(baseUrl, method, header, argMap, reservedList);
|
// return HttpUtil.request(baseUrl, method, header, argMap, reservedList);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static byte[] inputStreamToBytes(InputStream in) {
|
public static byte[] inputStreamToBytes(InputStream in) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
byte[] buff = new byte[4 * 1024 * 1024];
|
byte[] buff = new byte[4 * 1024 * 1024];
|
||||||
try {
|
try {
|
||||||
for (int count; (count = in.read(buff)) > 0; ) {
|
for (int count; (count = in.read(buff)) > 0;) {
|
||||||
bo.write(buff, 0, count);
|
bo.write(buff, 0, count);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -169,8 +167,8 @@ public class JavaScriptEntry {
|
|||||||
return new ApiGate(ip, Integer.parseInt(port));
|
return new ApiGate(ip, Integer.parseInt(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String executeContractWithSig(
|
public static String executeContractWithSig(String contractID, String action, String arg,
|
||||||
String contractID, String action, String arg, String pubkey, String sig) {
|
String pubkey, String sig) {
|
||||||
try {
|
try {
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(arg);
|
app.setContractID(contractID).setAction(action).setArg(arg);
|
||||||
@@ -180,26 +178,14 @@ public class JavaScriptEntry {
|
|||||||
if (!app.verifySignature()) {
|
if (!app.verifySignature()) {
|
||||||
return "{\"status\":\"Exception\",\"data\":\"invalid signature\"}";
|
return "{\"status\":\"Exception\",\"data\":\"invalid signature\"}";
|
||||||
}
|
}
|
||||||
app.setRequesterDOI(doi);
|
|
||||||
app.setFromDebug(isDebug);
|
app.setFromDebug(isDebug);
|
||||||
if (numOfCopies > 1) {
|
if (numOfCopies > 1) {
|
||||||
// The caller is special.
|
// The caller is special.
|
||||||
app.setRequestID(
|
app.setRequestID(app.getPublicKey().hashCode() + "_" + numOfCopies + "_"
|
||||||
app.getPublicKey().hashCode()
|
+ (invokeID++) + "_" + random.nextInt() + "_mul");
|
||||||
+ "_"
|
|
||||||
+ numOfCopies
|
|
||||||
+ "_"
|
|
||||||
+ (invokeID++)
|
|
||||||
+ "_"
|
|
||||||
+ random.nextInt()
|
|
||||||
+ "_mul");
|
|
||||||
} else {
|
} else {
|
||||||
app.setRequestID(
|
app.setRequestID(app.getPublicKey().hashCode() + "_" + (invokeID++) + "_"
|
||||||
app.getPublicKey().hashCode()
|
+ random.nextInt());
|
||||||
+ "_"
|
|
||||||
+ (invokeID++)
|
|
||||||
+ "_"
|
|
||||||
+ random.nextInt());
|
|
||||||
}
|
}
|
||||||
return get.syncGet("dd", "executeContract", JsonUtil.toJson(app));
|
return get.syncGet("dd", "executeContract", JsonUtil.toJson(app));
|
||||||
|
|
||||||
@@ -212,9 +198,8 @@ public class JavaScriptEntry {
|
|||||||
|
|
||||||
public static Object executeContract(String contractID, String action, Object arg) {
|
public static Object executeContract(String contractID, String action, Object arg) {
|
||||||
if (currentSyncUtil.engine.recovering) {
|
if (currentSyncUtil.engine.recovering) {
|
||||||
String str =
|
String str = currentSyncUtil.transRecoverUtil.curRecoverRecord
|
||||||
currentSyncUtil.transRecoverUtil.curRecoverRecord.getExecuteResult(
|
.getExecuteResult(invokeID + "");
|
||||||
invokeID + "");
|
|
||||||
String[] strs = str.split("<seperate>");
|
String[] strs = str.split("<seperate>");
|
||||||
String flag1 = strs[0];
|
String flag1 = strs[0];
|
||||||
String flag = strs[1];
|
String flag = strs[1];
|
||||||
@@ -235,30 +220,22 @@ public class JavaScriptEntry {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(JSONTool.convertMirrorToJson(arg));
|
app.setContractID(contractID).setAction(action)
|
||||||
|
.setArg(JSONTool.convertMirrorToJson(arg));
|
||||||
app.doSignature(keyPair);
|
app.doSignature(keyPair);
|
||||||
app.setRequesterDOI(doi);
|
|
||||||
app.setFromDebug(isDebug);
|
app.setFromDebug(isDebug);
|
||||||
ContractExecType type = ContractProcess.instance.getContract().getType();
|
ContractExecType type = ContractProcess.instance.getContract().getType();
|
||||||
if (type.needSeq()) {
|
if (type.needSeq()) {
|
||||||
app.setRequestID(
|
app.setRequestID(
|
||||||
String.format(
|
String.format("%d_%d_%d_%d_mul", keyPair.getPublicKeyStr().hashCode(),
|
||||||
"%d_%d_%d_%d_mul",
|
numOfCopies, (invokeID++), random.nextInt()));
|
||||||
keyPair.getPublicKeyStr().hashCode(),
|
|
||||||
numOfCopies,
|
|
||||||
(invokeID++),
|
|
||||||
random.nextInt()));
|
|
||||||
// The caller is special.
|
// The caller is special.
|
||||||
flag = 1;
|
flag = 1;
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
LOGGER.warn("invoke contractExecution! " + JsonUtil.toJson(app));
|
LOGGER.warn("invoke contractExecution! " + JsonUtil.toJson(app));
|
||||||
} else {
|
} else {
|
||||||
app.setRequestID(
|
app.setRequestID(String.format("%d_%d_%d", keyPair.getPublicKeyStr().hashCode(),
|
||||||
String.format(
|
(invokeID++), random.nextInt()));
|
||||||
"%d_%d_%d",
|
|
||||||
keyPair.getPublicKeyStr().hashCode(),
|
|
||||||
(invokeID++),
|
|
||||||
random.nextInt()));
|
|
||||||
flag = 1;
|
flag = 1;
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
}
|
}
|
||||||
@@ -267,76 +244,64 @@ public class JavaScriptEntry {
|
|||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
String result = bo.toString();
|
String result = bo.toString();
|
||||||
if (currentSyncUtil.startFlag
|
if (currentSyncUtil.startFlag && currentSyncUtil.currType == SyncType.Trans
|
||||||
&& currentSyncUtil.currType == SyncType.Trans
|
|
||||||
&& !currentSyncUtil.engine.recovering) {
|
&& !currentSyncUtil.engine.recovering) {
|
||||||
currentSyncUtil.transRecordUtil.recordExecutes(
|
currentSyncUtil.transRecordUtil.recordExecutes(formerInvokeID + "",
|
||||||
formerInvokeID + "", flag1 + "<seperate>" + flag + "<seperate>" + result);
|
flag1 + "<seperate>" + flag + "<seperate>" + result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object executeContract(long formerInvokeID, int flag1, int flag, ContractRequest app) {
|
private static Object executeContract(long formerInvokeID, int flag1, int flag,
|
||||||
|
ContractRequest app) {
|
||||||
String result = get.syncGet("dd", "executeContract", JsonUtil.toJson(app));
|
String result = get.syncGet("dd", "executeContract", JsonUtil.toJson(app));
|
||||||
if (currentSyncUtil.startFlag
|
if (currentSyncUtil.startFlag && currentSyncUtil.currType == SyncType.Trans
|
||||||
&& currentSyncUtil.currType == SyncType.Trans
|
|
||||||
&& !currentSyncUtil.engine.recovering) {
|
&& !currentSyncUtil.engine.recovering) {
|
||||||
currentSyncUtil.transRecordUtil.recordExecutes(
|
currentSyncUtil.transRecordUtil.recordExecutes(formerInvokeID + "",
|
||||||
formerInvokeID + "",
|
|
||||||
flag1 + "<seperate>" + flag + "<seperate>" + result);
|
flag1 + "<seperate>" + flag + "<seperate>" + result);
|
||||||
}
|
}
|
||||||
JsonObject jo = JsonUtil.parseStringAsJsonObject(result);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(result);
|
||||||
return JSONTool.convertJsonElementToMirror(jo);
|
return JSONTool.convertJsonElementToMirror(jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeContractAsyncWithoutSig(
|
public static void executeContractAsyncWithoutSig(String contractID, String action, String arg,
|
||||||
String contractID, String action, String arg, final ScriptFunction cb) {
|
final ScriptFunction cb) {
|
||||||
try {
|
try {
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(arg);
|
app.setContractID(contractID).setAction(action).setArg(arg);
|
||||||
app.setRequestID((invokeID++) + "_" + random.nextInt());
|
app.setRequestID((invokeID++) + "_" + random.nextInt());
|
||||||
get.asyncGet(
|
get.asyncGet("dd", "executeContract", JsonUtil.toJson(app), new ResultCallback() {
|
||||||
"dd",
|
@Override
|
||||||
"executeContract",
|
public void onResult(String str) {
|
||||||
JsonUtil.toJson(app),
|
if (null != cb) {
|
||||||
new ResultCallback() {
|
DesktopEngine.applyWithGlobal(cb, currentEngine.getNashornGlobal(), str);
|
||||||
@Override
|
}
|
||||||
public void onResult(String str) {
|
}
|
||||||
if (null != cb) {
|
});
|
||||||
DesktopEngine.applyWithGlobal(
|
|
||||||
cb, currentEngine.getNashornGlobal(), str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String executeContractAsync(
|
public static String executeContractAsync(String contractID, String action, String arg,
|
||||||
String contractID, String action, String arg, final ScriptFunction cb) {
|
final ScriptFunction cb) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(arg);
|
app.setContractID(contractID).setAction(action).setArg(arg);
|
||||||
app.doSignature(keyPair);
|
app.doSignature(keyPair);
|
||||||
app.setRequestID((invokeID++) + "_" + random());
|
app.setRequestID((invokeID++) + "_" + random());
|
||||||
app.setRequesterDOI(doi);
|
get.asyncGet("dd", "executeContract", JsonUtil.toJson(app), new ResultCallback() {
|
||||||
get.asyncGet(
|
@Override
|
||||||
"dd",
|
public void onResult(String str) {
|
||||||
"executeContract",
|
if (cb != null) {
|
||||||
JsonUtil.toJson(app),
|
DesktopEngine.applyWithGlobal(cb, currentEngine.getNashornGlobal(), str,
|
||||||
new ResultCallback() {
|
arg);
|
||||||
@Override
|
}
|
||||||
public void onResult(String str) {
|
}
|
||||||
if (cb != null) {
|
});
|
||||||
DesktopEngine.applyWithGlobal(
|
|
||||||
cb, currentEngine.getNashornGlobal(), str, arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return "success";
|
return "success";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
@@ -345,7 +310,7 @@ public class JavaScriptEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//YancloudUtil.exceptionReturn({"msg":"missing arguments repoId ","code":1});
|
// YancloudUtil.exceptionReturn({"msg":"missing arguments repoId ","code":1});
|
||||||
public static void exceptionReturn(Object obj) throws ScriptReturnException {
|
public static void exceptionReturn(Object obj) throws ScriptReturnException {
|
||||||
throw new ScriptReturnException(JSONTool.convertMirrorToJson(obj));
|
throw new ScriptReturnException(JSONTool.convertMirrorToJson(obj));
|
||||||
}
|
}
|
||||||
@@ -353,7 +318,7 @@ public class JavaScriptEntry {
|
|||||||
/**
|
/**
|
||||||
* publish an event with semantic AT_LEAST_ONCE
|
* publish an event with semantic AT_LEAST_ONCE
|
||||||
*
|
*
|
||||||
* @param topic the topic
|
* @param topic the topic
|
||||||
* @param content the content
|
* @param content the content
|
||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
@@ -364,16 +329,14 @@ public class JavaScriptEntry {
|
|||||||
/**
|
/**
|
||||||
* publish an event with some semantic
|
* publish an event with some semantic
|
||||||
*
|
*
|
||||||
* @param topic the topic
|
* @param topic the topic
|
||||||
* @param content the content
|
* @param content the content
|
||||||
* @param constraint the constraint, AT_LEAST_ONCE, AT_MOST_ONCE, and ONLY_ONCE
|
* @param constraint the constraint, AT_LEAST_ONCE, AT_MOST_ONCE, and ONLY_ONCE
|
||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
public static void pubEventConstraint(String topic, String content, String constraint) {
|
public static void pubEventConstraint(String topic, String content, String constraint) {
|
||||||
String reqID =
|
String reqID = String.format("%d_%d_%d_%s_pe", keyPair.getPublicKeyStr().hashCode(),
|
||||||
String.format(
|
numOfCopies, invokeID, random());
|
||||||
"%d_%d_%d_%s_pe",
|
|
||||||
keyPair.getPublicKeyStr().hashCode(), numOfCopies, invokeID, random());
|
|
||||||
REvent msg = new REvent(topic, PUBLISH, content, reqID);
|
REvent msg = new REvent(topic, PUBLISH, content, reqID);
|
||||||
if (null != constraint) {
|
if (null != constraint) {
|
||||||
msg.setSemantics(REvent.REventSemantics.valueOf(constraint));
|
msg.setSemantics(REvent.REventSemantics.valueOf(constraint));
|
||||||
@@ -385,7 +348,7 @@ public class JavaScriptEntry {
|
|||||||
* subscribe a topic
|
* subscribe a topic
|
||||||
*
|
*
|
||||||
* @param topic event topic
|
* @param topic event topic
|
||||||
* @param fun related handler function
|
* @param fun related handler function
|
||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
public static String subscribe(String topic, ScriptFunction fun) {
|
public static String subscribe(String topic, ScriptFunction fun) {
|
||||||
@@ -401,8 +364,8 @@ public class JavaScriptEntry {
|
|||||||
* subscribe a local event
|
* subscribe a local event
|
||||||
*
|
*
|
||||||
* @param contractID contractID
|
* @param contractID contractID
|
||||||
* @param event local event topic
|
* @param event local event topic
|
||||||
* @param fun related handler function
|
* @param fun related handler function
|
||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
public static String subscribe(String contractID, String event, ScriptFunction fun) {
|
public static String subscribe(String contractID, String event, ScriptFunction fun) {
|
||||||
@@ -416,19 +379,13 @@ public class JavaScriptEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void subscribe(String topic, ScriptFunction fun, boolean fromPreSub) {
|
private static void subscribe(String topic, ScriptFunction fun, boolean fromPreSub) {
|
||||||
String reqID =
|
String reqID = String.format("%d_%d_%d_%s_se", keyPair.getPublicKeyStr().hashCode(),
|
||||||
String.format(
|
numOfCopies, invokeID, random());
|
||||||
"%d_%d_%d_%s_se",
|
|
||||||
keyPair.getPublicKeyStr().hashCode(), numOfCopies, invokeID, random());
|
|
||||||
|
|
||||||
REvent msg =
|
REvent msg = new REvent(topic, SUBSCRIBE,
|
||||||
new REvent(
|
String.format("{\"subscriber\":\"%s\",\"handler\":\"%s\"}",
|
||||||
topic,
|
ContractProcess.instance.getContractName(), fun.getName()),
|
||||||
SUBSCRIBE,
|
reqID);
|
||||||
String.format(
|
|
||||||
"{\"subscriber\":\"%s\",\"handler\":\"%s\"}",
|
|
||||||
ContractProcess.instance.getContractName(), fun.getName()),
|
|
||||||
reqID);
|
|
||||||
if (fromPreSub) {
|
if (fromPreSub) {
|
||||||
msg.setSemantics(REvent.REventSemantics.ONLY_ONCE);
|
msg.setSemantics(REvent.REventSemantics.ONLY_ONCE);
|
||||||
}
|
}
|
||||||
@@ -438,10 +395,8 @@ public class JavaScriptEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void unsubscribe(String topic) {
|
public static void unsubscribe(String topic) {
|
||||||
String reqID =
|
String reqID = String.format("%d_%d_%d_%s_us", keyPair.getPublicKeyStr().hashCode(),
|
||||||
String.format(
|
numOfCopies, invokeID, random());
|
||||||
"%d_%d_%d_%s_us",
|
|
||||||
keyPair.getPublicKeyStr().hashCode(), numOfCopies, invokeID, random());
|
|
||||||
String content;
|
String content;
|
||||||
if (null == topic) {
|
if (null == topic) {
|
||||||
content = "{\"subscriber\":\"" + ContractProcess.instance.getContractName() + "\"}";
|
content = "{\"subscriber\":\"" + ContractProcess.instance.getContractName() + "\"}";
|
||||||
@@ -451,10 +406,8 @@ public class JavaScriptEntry {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
String handler = topic_handlers.get(topic).getName();
|
String handler = topic_handlers.get(topic).getName();
|
||||||
content =
|
content = String.format("{\"subscriber\":\"%s\",\"handler\":\"%s\"}",
|
||||||
String.format(
|
ContractProcess.instance.getContractName(), handler);
|
||||||
"{\"subscriber\":\"%s\",\"handler\":\"%s\"}",
|
|
||||||
ContractProcess.instance.getContractName(), handler);
|
|
||||||
topic_handlers.remove(topic);
|
topic_handlers.remove(topic);
|
||||||
ContractProcess.instance.unSubscribe(handler);
|
ContractProcess.instance.unSubscribe(handler);
|
||||||
}
|
}
|
||||||
@@ -465,17 +418,15 @@ public class JavaScriptEntry {
|
|||||||
/**
|
/**
|
||||||
* pre-sub in ONLY_ONCE
|
* pre-sub in ONLY_ONCE
|
||||||
*
|
*
|
||||||
* @param topic the topic
|
* @param topic the topic
|
||||||
* @param content the content
|
* @param content the content
|
||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
public static void preSub(String topic, String content) {
|
public static void preSub(String topic, String content) {
|
||||||
String newTopic = topic + "|" + content + "|" + ContractProcess.instance.getContractName();
|
String newTopic = topic + "|" + content + "|" + ContractProcess.instance.getContractName();
|
||||||
subscribe(newTopic, topic_handlers.get(topic), true);
|
subscribe(newTopic, topic_handlers.get(topic), true);
|
||||||
String reqID =
|
String reqID = String.format("%d_%d_%d_%s_pse", keyPair.getPublicKeyStr().hashCode(),
|
||||||
String.format(
|
numOfCopies, (invokeID++), random());
|
||||||
"%d_%d_%d_%s_pse",
|
|
||||||
keyPair.getPublicKeyStr().hashCode(), numOfCopies, (invokeID++), random());
|
|
||||||
REvent msg = new REvent(topic, REvent.REventType.PRESUB, newTopic, reqID);
|
REvent msg = new REvent(topic, REvent.REventType.PRESUB, newTopic, reqID);
|
||||||
msg.setSemantics(REvent.REventSemantics.ONLY_ONCE);
|
msg.setSemantics(REvent.REventSemantics.ONLY_ONCE);
|
||||||
msgList.add(msg);
|
msgList.add(msg);
|
||||||
@@ -486,7 +437,8 @@ public class JavaScriptEntry {
|
|||||||
* @author Kaidong Wu
|
* @author Kaidong Wu
|
||||||
*/
|
*/
|
||||||
public static String random() {
|
public static String random() {
|
||||||
String seed = String.valueOf(null == random ? System.currentTimeMillis() : random.nextInt());
|
String seed =
|
||||||
|
String.valueOf(null == random ? System.currentTimeMillis() : random.nextInt());
|
||||||
return HashUtil.sha3(seed);
|
return HashUtil.sha3(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.util.Scanner;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
public class Resources {
|
public class Resources {
|
||||||
private final ZipFile zf;
|
private final ZipFile zf;
|
||||||
YJSClassLoader loader;
|
YJSClassLoader loader;
|
||||||
@@ -49,7 +48,7 @@ public class Resources {
|
|||||||
InputStream sc = loadAsInputStream(path);
|
InputStream sc = loadAsInputStream(path);
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
byte[] buff = new byte[1024];
|
byte[] buff = new byte[1024];
|
||||||
for (int k = 0; (k = sc.read(buff)) > 0; ) {
|
for (int k = 0; (k = sc.read(buff)) > 0;) {
|
||||||
bo.write(buff, 0, k);
|
bo.write(buff, 0, k);
|
||||||
}
|
}
|
||||||
return new String(bo.toByteArray());
|
return new String(bo.toByteArray());
|
||||||
@@ -67,7 +66,8 @@ public class Resources {
|
|||||||
ZipEntry entry = zf.getEntry(path);
|
ZipEntry entry = zf.getEntry(path);
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
return null;
|
return null;
|
||||||
reader = new BufferedReader(new InputStreamReader(zf.getInputStream(entry), StandardCharsets.UTF_8));
|
reader = new BufferedReader(
|
||||||
|
new InputStreamReader(zf.getInputStream(entry), StandardCharsets.UTF_8));
|
||||||
String line = null;
|
String line = null;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
fileList.add(line);
|
fileList.add(line);
|
||||||
@@ -84,7 +84,8 @@ public class Resources {
|
|||||||
public String unzipToDir(String path) {
|
public String unzipToDir(String path) {
|
||||||
ZipEntry entry = zf.getEntry(path);
|
ZipEntry entry = zf.getEntry(path);
|
||||||
try {
|
try {
|
||||||
return loader.unzipLibrary(zf.getInputStream(entry), entry.getName().replaceAll(".*/", ""));
|
return loader.unzipLibrary(zf.getInputStream(entry),
|
||||||
|
entry.getName().replaceAll(".*/", ""));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,16 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
|
|
||||||
@PermissionStub(permission = Permission.AES)
|
@PermissionStub(permission = Permission.AES)
|
||||||
public class AESUtil {
|
public class AESUtil {
|
||||||
public static ScriptObject encrypt(String key, String plaintext) throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException {
|
public static ScriptObject encrypt(String key, String plaintext)
|
||||||
|
throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException,
|
||||||
|
IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||||
JO ret = new JO(PropertyMap.newMap());
|
JO ret = new JO(PropertyMap.newMap());
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
String iv = generateKey(128);
|
String iv = generateKey(128);
|
||||||
IvParameterSpec ivSpec = new IvParameterSpec(DatatypeConverter.parseHexBinary(iv));
|
IvParameterSpec ivSpec = new IvParameterSpec(DatatypeConverter.parseHexBinary(iv));
|
||||||
byte[] byteContent = plaintext.getBytes();
|
byte[] byteContent = plaintext.getBytes();
|
||||||
SecretKeySpec secretKeySpecSpec = new SecretKeySpec(DatatypeConverter.parseHexBinary(key), "AES");
|
SecretKeySpec secretKeySpecSpec =
|
||||||
|
new SecretKeySpec(DatatypeConverter.parseHexBinary(key), "AES");
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpecSpec, ivSpec);
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpecSpec, ivSpec);
|
||||||
byte[] result = cipher.doFinal(byteContent);
|
byte[] result = cipher.doFinal(byteContent);
|
||||||
ret.put("iv", iv, false);
|
ret.put("iv", iv, false);
|
||||||
@@ -30,12 +33,16 @@ public class AESUtil {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String decrypt(String key, String ciphertext, String iv) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
public static String decrypt(String key, String ciphertext, String iv)
|
||||||
// JO ret = new JO(PropertyMap.newMap());
|
throws NoSuchPaddingException, NoSuchAlgorithmException,
|
||||||
|
InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException,
|
||||||
|
IllegalBlockSizeException {
|
||||||
|
// JO ret = new JO(PropertyMap.newMap());
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
IvParameterSpec ivSpec = new IvParameterSpec(DatatypeConverter.parseHexBinary(iv));
|
IvParameterSpec ivSpec = new IvParameterSpec(DatatypeConverter.parseHexBinary(iv));
|
||||||
byte[] byteContent = DatatypeConverter.parseHexBinary(ciphertext);
|
byte[] byteContent = DatatypeConverter.parseHexBinary(ciphertext);
|
||||||
SecretKeySpec secretKeySpecSpec = new SecretKeySpec(DatatypeConverter.parseHexBinary(key), "AES");
|
SecretKeySpec secretKeySpecSpec =
|
||||||
|
new SecretKeySpec(DatatypeConverter.parseHexBinary(key), "AES");
|
||||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpecSpec, ivSpec);
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpecSpec, ivSpec);
|
||||||
byte[] result = cipher.doFinal(byteContent);
|
byte[] result = cipher.doFinal(byteContent);
|
||||||
return new String(result);
|
return new String(result);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.util.TimerTask;
|
|||||||
@PermissionStub(permission = Permission.Async)
|
@PermissionStub(permission = Permission.Async)
|
||||||
public class AsyncUtil {
|
public class AsyncUtil {
|
||||||
private static final Timer TIMER = new Timer();
|
private static final Timer TIMER = new Timer();
|
||||||
// public static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
// public static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||||
|
|
||||||
public static String sleep(long sleep) {
|
public static String sleep(long sleep) {
|
||||||
try {
|
try {
|
||||||
@@ -30,53 +30,47 @@ public class AsyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String postFunction(final ScriptFunction callback, Object wrapper) {
|
public static String postFunction(final ScriptFunction callback, Object wrapper) {
|
||||||
ServiceServer.executor.execute(
|
ServiceServer.executor.execute(() -> JavaScriptEntry.executeFunction(callback, wrapper));
|
||||||
() -> JavaScriptEntry.executeFunction(callback, wrapper));
|
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimerTask setTimeOut(
|
public static TimerTask setTimeOut(final ScriptFunction callback, long delay,
|
||||||
final ScriptFunction callback, long delay, final Object arg) {
|
final Object arg) {
|
||||||
TimerTask task =
|
TimerTask task = new TimerTask() {
|
||||||
new TimerTask() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
JavaScriptEntry.executeFunction(callback, arg);
|
||||||
JavaScriptEntry.executeFunction(callback, arg);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
TIMER.schedule(task, delay);
|
TIMER.schedule(task, delay);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimerTask setInterval(
|
public static TimerTask setInterval(final ScriptFunction callback, long delay, long interval,
|
||||||
final ScriptFunction callback, long delay, long interval, final Object arg) {
|
final Object arg) {
|
||||||
TimerTask task =
|
TimerTask task = new TimerTask() {
|
||||||
new TimerTask() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
JavaScriptEntry.executeFunction(callback, arg);
|
||||||
JavaScriptEntry.executeFunction(callback, arg);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
TIMER.schedule(task, delay, interval);
|
TIMER.schedule(task, delay, interval);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeContractAsyncWithoutSig(
|
public static void executeContractAsyncWithoutSig(String contractID, String action, String arg,
|
||||||
String contractID, String action, String arg, final ScriptFunction cb) {
|
final ScriptFunction cb) {
|
||||||
try {
|
try {
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(arg);
|
app.setContractID(contractID).setAction(action).setArg(arg);
|
||||||
app.setRequestID((JavaScriptEntry.invokeID++) + "_" + JavaScriptEntry.random.nextInt());
|
app.setRequestID((JavaScriptEntry.invokeID++) + "_" + JavaScriptEntry.random.nextInt());
|
||||||
JavaScriptEntry.get.asyncGet(
|
JavaScriptEntry.get.asyncGet("dd", "executeContract", JsonUtil.toJson(app),
|
||||||
"dd",
|
|
||||||
"executeContract",
|
|
||||||
JsonUtil.toJson(app),
|
|
||||||
new ResultCallback() {
|
new ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(String str) {
|
public void onResult(String str) {
|
||||||
if (null != cb) {
|
if (null != cb) {
|
||||||
DesktopEngine.applyWithGlobal(
|
DesktopEngine.applyWithGlobal(cb,
|
||||||
cb, JavaScriptEntry.currentEngine.getNashornGlobal(), str);
|
JavaScriptEntry.currentEngine.getNashornGlobal(), str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -85,25 +79,22 @@ public class AsyncUtil {
|
|||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static String executeContractAsync(
|
|
||||||
String contractID, String action, String arg, final ScriptFunction cb) {
|
public static String executeContractAsync(String contractID, String action, String arg,
|
||||||
|
final ScriptFunction cb) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ContractRequest app = new ContractRequest();
|
ContractRequest app = new ContractRequest();
|
||||||
app.setContractID(contractID).setAction(action).setArg(arg);
|
app.setContractID(contractID).setAction(action).setArg(arg);
|
||||||
app.doSignature(JavaScriptEntry.getKeyPair());
|
app.doSignature(JavaScriptEntry.getKeyPair());
|
||||||
app.setRequestID((JavaScriptEntry.invokeID++) + "_" + JavaScriptEntry.random());
|
app.setRequestID((JavaScriptEntry.invokeID++) + "_" + JavaScriptEntry.random());
|
||||||
app.setRequesterDOI(JavaScriptEntry.doi);
|
JavaScriptEntry.get.asyncGet("dd", "executeContract", JsonUtil.toJson(app),
|
||||||
JavaScriptEntry.get.asyncGet(
|
|
||||||
"dd",
|
|
||||||
"executeContract",
|
|
||||||
JsonUtil.toJson(app),
|
|
||||||
new ResultCallback() {
|
new ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(String str) {
|
public void onResult(String str) {
|
||||||
if (cb != null) {
|
if (cb != null) {
|
||||||
DesktopEngine.applyWithGlobal(
|
DesktopEngine.applyWithGlobal(cb,
|
||||||
cb, JavaScriptEntry.currentEngine.getNashornGlobal(), str, arg);
|
JavaScriptEntry.currentEngine.getNashornGlobal(), str, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.bdware.sc.boundry.utils;
|
|||||||
|
|
||||||
import org.bdware.sc.ContractProcess;
|
import org.bdware.sc.ContractProcess;
|
||||||
import org.bdware.sc.compiler.PermissionStub;
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
import org.bdware.sc.db.TimeDBUtil;
|
|
||||||
import org.bdware.sc.db.TimeRocksDBUtil;
|
import org.bdware.sc.db.TimeRocksDBUtil;
|
||||||
import org.bdware.sc.node.Permission;
|
import org.bdware.sc.node.Permission;
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ public class DOIPUtil {
|
|||||||
msg = ret.get(0);
|
msg = ret.get(0);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
return msg;
|
return msg;
|
||||||
} else return DoipMessageFactory.createTimeoutResponse(message.requestID);
|
} else
|
||||||
|
return DoipMessageFactory.createTimeoutResponse(message.requestID, "timeout");
|
||||||
} catch (Exception ie) {
|
} catch (Exception ie) {
|
||||||
ie.printStackTrace();
|
ie.printStackTrace();
|
||||||
return DoipMessageFactory.createConnectFailedResponse(message.requestID);
|
return DoipMessageFactory.createConnectFailedResponse(message.requestID);
|
||||||
@@ -97,13 +98,14 @@ public class DOIPUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String hello(String repoID) {
|
public String hello(String repoID) {
|
||||||
DoipMessage msg = (new DoipMessageFactory.DoipMessageBuilder()).createRequest(repoID, BasicOperations.Hello.getName()).create();
|
DoipMessage msg = (new DoipMessageFactory.DoipMessageBuilder())
|
||||||
|
.createRequest(repoID, BasicOperations.Hello.getName()).create();
|
||||||
return convertDoipMsgToString(syncGetMessage(msg));
|
return convertDoipMsgToString(syncGetMessage(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String retrieve(String doi, String args) {
|
public String retrieve(String doi, String args) {
|
||||||
DoipMessage msg = (new DoipMessageFactory.DoipMessageBuilder()).createRequest(doi, BasicOperations.Retrieve.getName())
|
DoipMessage msg = (new DoipMessageFactory.DoipMessageBuilder())
|
||||||
.create();
|
.createRequest(doi, BasicOperations.Retrieve.getName()).create();
|
||||||
msg.header.parameters.addAttribute("element", "");
|
msg.header.parameters.addAttribute("element", "");
|
||||||
return convertDoipMsgToString(syncGetMessage(msg));
|
return convertDoipMsgToString(syncGetMessage(msg));
|
||||||
}
|
}
|
||||||
@@ -126,27 +128,21 @@ public class DOIPUtil {
|
|||||||
}
|
}
|
||||||
e.dataString = null;
|
e.dataString = null;
|
||||||
}
|
}
|
||||||
DoipMessage msg =
|
DoipMessage msg = new DoipMessageFactory.DoipMessageBuilder()
|
||||||
new DoipMessageFactory.DoipMessageBuilder()
|
.createRequest(repoID, BasicOperations.Create.getName()).setBody(digitalObject)
|
||||||
.createRequest(repoID, BasicOperations.Create.getName())
|
.create();
|
||||||
.setBody(digitalObject)
|
|
||||||
.create();
|
|
||||||
return convertDoipMsgToString(syncGetMessage(msg));
|
return convertDoipMsgToString(syncGetMessage(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String delete(String doID) {
|
public String delete(String doID) {
|
||||||
DoipMessage msg =
|
DoipMessage msg = new DoipMessageFactory.DoipMessageBuilder()
|
||||||
new DoipMessageFactory.DoipMessageBuilder()
|
.createRequest(doID, BasicOperations.Delete.getName()).create();
|
||||||
.createRequest(doID, BasicOperations.Delete.getName())
|
|
||||||
.create();
|
|
||||||
return convertDoipMsgToString(syncGetMessage(msg));
|
return convertDoipMsgToString(syncGetMessage(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String listOperation(String doID) {
|
public String listOperation(String doID) {
|
||||||
DoipMessage msg =
|
DoipMessage msg = new DoipMessageFactory.DoipMessageBuilder()
|
||||||
new DoipMessageFactory.DoipMessageBuilder()
|
.createRequest(doID, BasicOperations.ListOps.getName()).create();
|
||||||
.createRequest(doID, BasicOperations.ListOps.getName())
|
|
||||||
.create();
|
|
||||||
return convertDoipMsgToString(syncGetMessage(msg));
|
return convertDoipMsgToString(syncGetMessage(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +218,8 @@ public class DOIPUtil {
|
|||||||
return createIrpClient(uri, null, null, null);
|
return createIrpClient(uri, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRPClientWrapper createIrpClient(String uri, String pubkey, String privateKey, String repoName) {
|
public static IRPClientWrapper createIrpClient(String uri, String pubkey, String privateKey,
|
||||||
|
String repoName) {
|
||||||
EndpointConfig config = new EndpointConfig();
|
EndpointConfig config = new EndpointConfig();
|
||||||
config.routerURI = uri;
|
config.routerURI = uri;
|
||||||
config.repoName = repoName;
|
config.repoName = repoName;
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ public class DOMUtil {
|
|||||||
public static Document parse(String html) {
|
public static Document parse(String html) {
|
||||||
return Jsoup.parse(html);
|
return Jsoup.parse(html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main/java/org/bdware/sc/boundry/utils/DigestUtil.java
Normal file
15
src/main/java/org/bdware/sc/boundry/utils/DigestUtil.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package org.bdware.sc.boundry.utils;
|
||||||
|
|
||||||
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
|
import org.bdware.sc.node.Permission;
|
||||||
|
|
||||||
|
@PermissionStub(permission = Permission.Digest)
|
||||||
|
public class DigestUtil {
|
||||||
|
public static String md5Hex(String arg) {
|
||||||
|
return org.apache.commons.codec.digest.DigestUtils.md5Hex(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha256Hex(String arg) {
|
||||||
|
return org.apache.commons.codec.digest.DigestUtils.sha256Hex(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,24 +25,20 @@ public class EmailUtil {
|
|||||||
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
|
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
|
||||||
props.setProperty("mail.smtp.socketFactory.fallback", "false");
|
props.setProperty("mail.smtp.socketFactory.fallback", "false");
|
||||||
props.setProperty("mail.smtp.socketFactory.port", jo.get("port").getAsString());
|
props.setProperty("mail.smtp.socketFactory.port", jo.get("port").getAsString());
|
||||||
Session session =
|
Session session = Session.getDefaultInstance(props, new Authenticator() {
|
||||||
Session.getDefaultInstance(
|
public PasswordAuthentication getPasswordAuthentication() {
|
||||||
props,
|
return new PasswordAuthentication(jo.get("from").getAsString(),
|
||||||
new Authenticator() {
|
jo.get("pwd").getAsString()); // 发件人邮件用户名、密码
|
||||||
public PasswordAuthentication getPasswordAuthentication() {
|
}
|
||||||
return new PasswordAuthentication(
|
});
|
||||||
jo.get("from").getAsString(),
|
|
||||||
jo.get("pwd").getAsString()); // 发件人邮件用户名、密码
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 创建邮件对象
|
// 创建邮件对象
|
||||||
|
|
||||||
Message msg = new MimeMessage(session);
|
Message msg = new MimeMessage(session);
|
||||||
msg.setSubject(jo.get("subject").getAsString());
|
msg.setSubject(jo.get("subject").getAsString());
|
||||||
msg.setText(jo.get("content").getAsString());
|
msg.setText(jo.get("content").getAsString());
|
||||||
msg.setFrom(new InternetAddress(jo.get("from").getAsString()));
|
msg.setFrom(new InternetAddress(jo.get("from").getAsString()));
|
||||||
msg.addRecipient(
|
msg.addRecipient(Message.RecipientType.TO,
|
||||||
Message.RecipientType.TO, new InternetAddress(jo.get("to").getAsString()));
|
new InternetAddress(jo.get("to").getAsString()));
|
||||||
Transport.send(msg);
|
Transport.send(msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ public class HttpUtil {
|
|||||||
ScriptObjectMirror som = (ScriptObjectMirror) headers;
|
ScriptObjectMirror som = (ScriptObjectMirror) headers;
|
||||||
for (String key : som.getOwnKeys(true)) {
|
for (String key : som.getOwnKeys(true)) {
|
||||||
Object val = som.get(key);
|
Object val = som.get(key);
|
||||||
if (val instanceof String) connection.setRequestProperty(key, (String) val);
|
if (val instanceof String)
|
||||||
|
connection.setRequestProperty(key, (String) val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
connection.setRequestProperty("Accept", "application/json");
|
connection.setRequestProperty("Accept", "application/json");
|
||||||
@@ -64,7 +65,7 @@ public class HttpUtil {
|
|||||||
InputStream input = connection.getInputStream();
|
InputStream input = connection.getInputStream();
|
||||||
Scanner sc = new Scanner(input);
|
Scanner sc = new Scanner(input);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (; sc.hasNextLine(); ) {
|
for (; sc.hasNextLine();) {
|
||||||
sb.append(sc.nextLine()).append("\n");
|
sb.append(sc.nextLine()).append("\n");
|
||||||
}
|
}
|
||||||
sc.close();
|
sc.close();
|
||||||
@@ -77,10 +78,12 @@ public class HttpUtil {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public static String encodeURI(String str){
|
|
||||||
|
public static String encodeURI(String str) {
|
||||||
return URLEncoder.encode(str);
|
return URLEncoder.encode(str);
|
||||||
}
|
}
|
||||||
public static String decodeURI(String str){
|
|
||||||
|
public static String decodeURI(String str) {
|
||||||
return URLDecoder.decode(str);
|
return URLDecoder.decode(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +134,8 @@ public class HttpUtil {
|
|||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
}
|
}
|
||||||
connection.connect();
|
connection.connect();
|
||||||
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
|
OutputStreamWriter out =
|
||||||
|
new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
|
||||||
out.append((String) str.get("data"));
|
out.append((String) str.get("data"));
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
@@ -156,74 +160,67 @@ public class HttpUtil {
|
|||||||
private static CloseableHttpClient getHttpClient(String url) {
|
private static CloseableHttpClient getHttpClient(String url) {
|
||||||
try {
|
try {
|
||||||
SSLContext sslcontext =
|
SSLContext sslcontext =
|
||||||
SSLContexts.custom()
|
SSLContexts.custom().loadTrustMaterial(null, (arg0, arg1) -> true).build();
|
||||||
.loadTrustMaterial(
|
|
||||||
null,
|
|
||||||
(arg0, arg1) -> true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
SSLConnectionSocketFactory sslSf =
|
SSLConnectionSocketFactory sslSf = new SSLConnectionSocketFactory(sslcontext, null,
|
||||||
new SSLConnectionSocketFactory(
|
null, new NoopHostnameVerifier());
|
||||||
sslcontext, null, null, new NoopHostnameVerifier());
|
|
||||||
int tle = 10;
|
int tle = 10;
|
||||||
if (url.contains("data.tj.gov.cn")) {
|
if (url.contains("data.tj.gov.cn")) {
|
||||||
tle = 3;
|
tle = 3;
|
||||||
}
|
}
|
||||||
return HttpClients.custom()
|
return HttpClients.custom().setSSLSocketFactory(sslSf)
|
||||||
.setSSLSocketFactory(sslSf)
|
|
||||||
.setKeepAliveStrategy((arg0, arg1) -> 0)
|
.setKeepAliveStrategy((arg0, arg1) -> 0)
|
||||||
.setConnectionTimeToLive(tle, TimeUnit.SECONDS)
|
.setConnectionTimeToLive(tle, TimeUnit.SECONDS).build();
|
||||||
.build();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String httpPost(String str) {
|
// public static String httpPost(String str) {
|
||||||
// System.out.println("JavaSScriptEntry httpPost:" + str);
|
// System.out.println("JavaSScriptEntry httpPost:" + str);
|
||||||
// PostRequest req = new PostRequest();
|
// PostRequest req = new PostRequest();
|
||||||
// req = JsonUtil.fromJson(str, PostRequest.class);
|
// req = JsonUtil.fromJson(str, PostRequest.class);
|
||||||
// // System.out.println("url========>" + req.url);
|
// // System.out.println("url========>" + req.url);
|
||||||
// // System.out.println("data=======>" + req.data);
|
// // System.out.println("data=======>" + req.data);
|
||||||
//
|
//
|
||||||
// Result r = new Result();
|
// Result r = new Result();
|
||||||
// try {
|
// try {
|
||||||
// URL url = new URL(req.url);//
|
// URL url = new URL(req.url);//
|
||||||
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
// connection.setDoOutput(true);
|
// connection.setDoOutput(true);
|
||||||
// connection.setDoInput(true);
|
// connection.setDoInput(true);
|
||||||
// connection.setUseCaches(false);
|
// connection.setUseCaches(false);
|
||||||
// connection.setInstanceFollowRedirects(true);
|
// connection.setInstanceFollowRedirects(true);
|
||||||
// connection.setRequestMethod("POST");
|
// connection.setRequestMethod("POST");
|
||||||
// connection.setRequestProperty("Accept", "application/json");
|
// connection.setRequestProperty("Accept", "application/json");
|
||||||
// connection.setRequestProperty("Content-Type", "application/json");
|
// connection.setRequestProperty("Content-Type", "application/json");
|
||||||
// connection.connect();
|
// connection.connect();
|
||||||
// OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); //
|
// OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); //
|
||||||
// utf-8缂栫爜
|
// utf-8缂栫爜
|
||||||
// out.append(req.data);
|
// out.append(req.data);
|
||||||
// out.flush();
|
// out.flush();
|
||||||
// out.close();
|
// out.close();
|
||||||
//
|
//
|
||||||
// r.resposeCode = connection.getResponseCode();
|
// r.resposeCode = connection.getResponseCode();
|
||||||
// InputStream input = connection.getInputStream();
|
// InputStream input = connection.getInputStream();
|
||||||
//
|
//
|
||||||
// Scanner sc = new Scanner(input);
|
// Scanner sc = new Scanner(input);
|
||||||
// StringBuilder sb = new StringBuilder();
|
// StringBuilder sb = new StringBuilder();
|
||||||
// for (; sc.hasNextLine();) {
|
// for (; sc.hasNextLine();) {
|
||||||
// sb.append(sc.nextLine()).append("\n");
|
// sb.append(sc.nextLine()).append("\n");
|
||||||
// }
|
// }
|
||||||
// sc.close();
|
// sc.close();
|
||||||
// r.response = sb.toString();
|
// r.response = sb.toString();
|
||||||
// return JsonUtil.toJson(r);
|
// return JsonUtil.toJson(r);
|
||||||
// } catch (Throwable e) {
|
// } catch (Throwable e) {
|
||||||
// r.resposeCode = 505;
|
// r.resposeCode = 505;
|
||||||
// // ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
// // ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
// // e.printStackTrace(new PrintStream(bo));
|
// // e.printStackTrace(new PrintStream(bo));
|
||||||
// r.response = e.getMessage();
|
// r.response = e.getMessage();
|
||||||
// return JsonUtil.toJson(r);
|
// return JsonUtil.toJson(r);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static String postTask(String args, final ScriptFunction callback) {
|
public static String postTask(String args, final ScriptFunction callback) {
|
||||||
System.out.println("[JavaScriptEntry]" + args);
|
System.out.println("[JavaScriptEntry]" + args);
|
||||||
@@ -235,62 +232,59 @@ public class HttpUtil {
|
|||||||
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), req.data);
|
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), req.data);
|
||||||
Request request = new Request.Builder().url(req.url).post(body).build(); // 2.瀹氫箟涓<E7AE9F>涓猺equest
|
Request request = new Request.Builder().url(req.url).post(body).build(); // 2.瀹氫箟涓<E7AE9F>涓猺equest
|
||||||
Call call = okHttpClient.newCall(request); //
|
Call call = okHttpClient.newCall(request); //
|
||||||
call.enqueue(
|
call.enqueue(new Callback() { //
|
||||||
new Callback() { //
|
@Override
|
||||||
@Override
|
public void onFailure(Call call, IOException e) {}
|
||||||
public void onFailure(Call call, IOException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call call, Response response) throws IOException {
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
String result = response.body().string(); //
|
String result = response.body().string(); //
|
||||||
System.out.println("currentEngine:");
|
System.out.println("currentEngine:");
|
||||||
DesktopEngine.applyWithGlobal(
|
DesktopEngine.applyWithGlobal(callback, currentEngine.getNashornGlobal(), result);
|
||||||
callback, currentEngine.getNashornGlobal(), result);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String httpGet(String str) {
|
// public static String httpGet(String str) {
|
||||||
// // System.out.println("JavaScriptEntry httpGet:" + str);
|
// // System.out.println("JavaScriptEntry httpGet:" + str);
|
||||||
// Result r = new Result();
|
// Result r = new Result();
|
||||||
// try {
|
// try {
|
||||||
// HttpGet httpGet = new HttpGet(str);
|
// HttpGet httpGet = new HttpGet(str);
|
||||||
// RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(60000)
|
// RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(60000)
|
||||||
// .setConnectTimeout(60000).setSocketTimeout(60000).build();
|
// .setConnectTimeout(60000).setSocketTimeout(60000).build();
|
||||||
// httpGet.setConfig(requestConfig);
|
// httpGet.setConfig(requestConfig);
|
||||||
// httpGet.addHeader("Pragma", "no-cache");
|
// httpGet.addHeader("Pragma", "no-cache");
|
||||||
// httpGet.addHeader("Cache-Control", "no-cache");
|
// httpGet.addHeader("Cache-Control", "no-cache");
|
||||||
// httpGet.addHeader("Upgrade-Insecure-Requests", "1");
|
// httpGet.addHeader("Upgrade-Insecure-Requests", "1");
|
||||||
// httpGet.addHeader("User-Agent",
|
// httpGet.addHeader("User-Agent",
|
||||||
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko)
|
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko)
|
||||||
// Chrome/78.0.3904.97 Safari/537.36");
|
// Chrome/78.0.3904.97 Safari/537.36");
|
||||||
// httpGet.addHeader("Sec-Fetch-User", "?1");
|
// httpGet.addHeader("Sec-Fetch-User", "?1");
|
||||||
// httpGet.addHeader("Accept",
|
// httpGet.addHeader("Accept",
|
||||||
//
|
//
|
||||||
// "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
|
// "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
|
||||||
// httpGet.addHeader("Sec-Fetch-Site", "none");
|
// httpGet.addHeader("Sec-Fetch-Site", "none");
|
||||||
// httpGet.addHeader("Sec-Fetch-Mode", "navigate");
|
// httpGet.addHeader("Sec-Fetch-Mode", "navigate");
|
||||||
// httpGet.addHeader("Accept-Encoding", "gzip, deflate, br");
|
// httpGet.addHeader("Accept-Encoding", "gzip, deflate, br");
|
||||||
// httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9");
|
// httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.9");
|
||||||
// CloseableHttpResponse response1 = getHttpClient(str).execute(httpGet);
|
// CloseableHttpResponse response1 = getHttpClient(str).execute(httpGet);
|
||||||
// InputStream content = response1.getEntity().getContent();
|
// InputStream content = response1.getEntity().getContent();
|
||||||
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
// byte[] buff = new byte[4096];
|
// byte[] buff = new byte[4096];
|
||||||
// for (int k = 0; (k = content.read(buff)) > 0;) {
|
// for (int k = 0; (k = content.read(buff)) > 0;) {
|
||||||
// bo.write(buff, 0, k);
|
// bo.write(buff, 0, k);
|
||||||
// }
|
// }
|
||||||
// r.response = bo.toString();
|
// r.response = bo.toString();
|
||||||
// return JsonUtil.toJson(r);
|
// return JsonUtil.toJson(r);
|
||||||
// } catch (Throwable e) {
|
// } catch (Throwable e) {
|
||||||
// r.resposeCode = 505;
|
// r.resposeCode = 505;
|
||||||
// // ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
// // ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
// // e.printStackTrace(new PrintStream(bo));
|
// // e.printStackTrace(new PrintStream(bo));
|
||||||
// r.response = e.getMessage();
|
// r.response = e.getMessage();
|
||||||
// return JsonUtil.toJson(r);
|
// return JsonUtil.toJson(r);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static ApiGate createAPIGate(String ip) {
|
public static ApiGate createAPIGate(String ip) {
|
||||||
return new ApiGate(ip);
|
return new ApiGate(ip);
|
||||||
|
|||||||
@@ -1,33 +1,17 @@
|
|||||||
package org.bdware.sc.boundry.utils;
|
package org.bdware.sc.boundry.utils;
|
||||||
|
|
||||||
import com.google.api.client.json.Json;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.doip.audit.EndpointConfig;
|
import org.bdware.doip.audit.EndpointConfig;
|
||||||
import org.bdware.doip.audit.client.AuditIrpClient;
|
import org.bdware.doip.audit.client.AuditIrpClient;
|
||||||
import org.bdware.doip.audit.config.TempConfigStorage;
|
import org.bdware.doip.audit.config.TempConfigStorage;
|
||||||
import org.bdware.doip.codec.digitalObject.DigitalObject;
|
|
||||||
import org.bdware.doip.codec.digitalObject.Element;
|
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
|
||||||
import org.bdware.doip.codec.operations.BasicOperations;
|
|
||||||
import org.bdware.doip.endpoint.client.ClientConfig;
|
|
||||||
import org.bdware.doip.endpoint.client.DoipClientImpl;
|
|
||||||
import org.bdware.doip.endpoint.client.DoipMessageCallback;
|
|
||||||
import org.bdware.irp.exception.IrpClientException;
|
|
||||||
import org.bdware.irp.stateinfo.StateInfoBase;
|
import org.bdware.irp.stateinfo.StateInfoBase;
|
||||||
import org.bdware.sc.compiler.PermissionStub;
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
import org.bdware.sc.node.Permission;
|
import org.bdware.sc.node.Permission;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@PermissionStub(permission = Permission.IRP)
|
@PermissionStub(permission = Permission.IRP)
|
||||||
public class IRPUtil {
|
public class IRPUtil {
|
||||||
@@ -40,7 +24,8 @@ public class IRPUtil {
|
|||||||
EndpointConfig endpointConfig = configStorage.loadAsEndpointConfig();
|
EndpointConfig endpointConfig = configStorage.loadAsEndpointConfig();
|
||||||
|
|
||||||
if (jo.has("clientDoId")) {
|
if (jo.has("clientDoId")) {
|
||||||
this.auditIrpClient = new AuditIrpClient(jo.get("clientDoId").getAsString(), endpointConfig);
|
this.auditIrpClient =
|
||||||
|
new AuditIrpClient(jo.get("clientDoId").getAsString(), endpointConfig);
|
||||||
} else {
|
} else {
|
||||||
this.auditIrpClient = new AuditIrpClient(endpointConfig);
|
this.auditIrpClient = new AuditIrpClient(endpointConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class LedgerUtil {
|
|||||||
static SecureRandom random = new SecureRandom((System.currentTimeMillis() + "").getBytes());
|
static SecureRandom random = new SecureRandom((System.currentTimeMillis() + "").getBytes());
|
||||||
|
|
||||||
public static Object getLedgerParams() {
|
public static Object getLedgerParams() {
|
||||||
//format:{nodes:[{ip:ip,port:port}]}
|
// format:{nodes:[{ip:ip,port:port}]}
|
||||||
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
||||||
JsonElement jo = JsonParser.parseString(ledgerParam);
|
JsonElement jo = JsonParser.parseString(ledgerParam);
|
||||||
return JSONTool.convertJsonElementToMirror(jo);
|
return JSONTool.convertJsonElementToMirror(jo);
|
||||||
@@ -36,7 +36,8 @@ public class LedgerUtil {
|
|||||||
public static Client getDefaultClient() {
|
public static Client getDefaultClient() {
|
||||||
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
||||||
JsonElement jo = JsonParser.parseString(ledgerParam);
|
JsonElement jo = JsonParser.parseString(ledgerParam);
|
||||||
JsonObject param = jo.getAsJsonObject().get("nodes").getAsJsonArray().get(0).getAsJsonObject();
|
JsonObject param =
|
||||||
|
jo.getAsJsonObject().get("nodes").getAsJsonArray().get(0).getAsJsonObject();
|
||||||
return new Client(param.get("ip").getAsString(), param.get("port").getAsInt());
|
return new Client(param.get("ip").getAsString(), param.get("port").getAsInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +58,8 @@ public class LedgerUtil {
|
|||||||
ret.put("to", HashUtil.byteArray2Str(transaction.getTo().toByteArray(), 0), false);
|
ret.put("to", HashUtil.byteArray2Str(transaction.getTo().toByteArray(), 0), false);
|
||||||
ret.put("type", transaction.getType().toString(), false);
|
ret.put("type", transaction.getType().toString(), false);
|
||||||
ret.put("data", new String(transaction.getData().toByteArray()), false);
|
ret.put("data", new String(transaction.getData().toByteArray()), false);
|
||||||
ret.put("blockHsah", HashUtil.byteArray2Str(transaction.getBlockHash().toByteArray(), 0), false);
|
ret.put("blockHsah", HashUtil.byteArray2Str(transaction.getBlockHash().toByteArray(), 0),
|
||||||
|
false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,14 +68,8 @@ public class LedgerUtil {
|
|||||||
String from = str.get("from").toString();
|
String from = str.get("from").toString();
|
||||||
String to = str.get("to").toString();
|
String to = str.get("to").toString();
|
||||||
String data = str.get("data").toString();
|
String data = str.get("data").toString();
|
||||||
SendTransactionResponse result =
|
SendTransactionResponse result = c.sendTransactionSync(ledger, TransactionType.MESSAGE,
|
||||||
c.sendTransactionSync(
|
from, random.nextLong(), to, data.getBytes());
|
||||||
ledger,
|
|
||||||
TransactionType.MESSAGE,
|
|
||||||
from,
|
|
||||||
random.nextLong(),
|
|
||||||
to,
|
|
||||||
data.getBytes());
|
|
||||||
return HashUtil.byteArray2Str(result.getHash().toByteArray(), 0);
|
return HashUtil.byteArray2Str(result.getHash().toByteArray(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,8 @@ public class MongoDBUtil {
|
|||||||
List addrs = new ArrayList<>();
|
List addrs = new ArrayList<>();
|
||||||
addrs.add(serverAddress);
|
addrs.add(serverAddress);
|
||||||
Method createeScramSha1 =
|
Method createeScramSha1 =
|
||||||
Class.forName("com.mongodb.MongoCredential")
|
Class.forName("com.mongodb.MongoCredential").getDeclaredMethod(
|
||||||
.getDeclaredMethod(
|
"createScramSha1Credential", String.class, String.class, char[].class);
|
||||||
"createScramSha1Credential",
|
|
||||||
String.class,
|
|
||||||
String.class,
|
|
||||||
char[].class);
|
|
||||||
Object credential = createeScramSha1.invoke(null, usrName, dbName, pwd.toCharArray());
|
Object credential = createeScramSha1.invoke(null, usrName, dbName, pwd.toCharArray());
|
||||||
List credentials = new ArrayList<>();
|
List credentials = new ArrayList<>();
|
||||||
credentials.add(credential);
|
credentials.add(credential);
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ public class MultiTagIndexDBUtil {
|
|||||||
|
|
||||||
public List<Long> countInInterval(String tag, long startTime, long endTime, long interval) {
|
public List<Long> countInInterval(String tag, long startTime, long endTime, long interval) {
|
||||||
List<Long> ret = new ArrayList<>();
|
List<Long> ret = new ArrayList<>();
|
||||||
if (interval <= 0) return ret;
|
if (interval <= 0)
|
||||||
|
return ret;
|
||||||
long start = rocksDB.queryOffset(tag, startTime);
|
long start = rocksDB.queryOffset(tag, startTime);
|
||||||
long delta;
|
long delta;
|
||||||
startTime += interval;
|
startTime += interval;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class RocksDBUtil {
|
|||||||
options.setCreateIfMissing(true);
|
options.setCreateIfMissing(true);
|
||||||
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
|
File parent = new File("./ContractDB/" + ContractProcess.getContractDir());
|
||||||
File dir = new File(parent, path);
|
File dir = new File(parent, path);
|
||||||
//LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
|
// LOGGER.info("init RocksDB in " + dir.getAbsolutePath());
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
LOGGER.info("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
|
LOGGER.info("create directory " + dir.getAbsolutePath() + ": " + dir.mkdirs());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,14 +46,13 @@ public class SM2Util {
|
|||||||
JO ret = new JO(PropertyMap.newMap());
|
JO ret = new JO(PropertyMap.newMap());
|
||||||
try {
|
try {
|
||||||
byte[] sig = ByteUtils.fromHexString(signature);
|
byte[] sig = ByteUtils.fromHexString(signature);
|
||||||
ECPublicKeyParameters pubKey =
|
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(pubKeyStr,
|
||||||
BCECUtil.createECPublicKeyFromStrParameters(
|
org.zz.gmhelper.SM2Util.CURVE, org.zz.gmhelper.SM2Util.DOMAIN_PARAMS);
|
||||||
pubKeyStr,
|
|
||||||
org.zz.gmhelper.SM2Util.CURVE,
|
|
||||||
org.zz.gmhelper.SM2Util.DOMAIN_PARAMS);
|
|
||||||
boolean value = org.zz.gmhelper.SM2Util.verify(pubKey, content.getBytes(), sig);
|
boolean value = org.zz.gmhelper.SM2Util.verify(pubKey, content.getBytes(), sig);
|
||||||
if (value) ret.put("status", "success", false);
|
if (value)
|
||||||
else ret.put("status", "failed", false);
|
ret.put("status", "success", false);
|
||||||
|
else
|
||||||
|
ret.put("status", "failed", false);
|
||||||
ret.put("result", value, false);
|
ret.put("result", value, false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ret.put("status", "failed", false);
|
ret.put("status", "failed", false);
|
||||||
@@ -65,9 +64,8 @@ public class SM2Util {
|
|||||||
|
|
||||||
public static String encrypt(String content, String pubkey) {
|
public static String encrypt(String content, String pubkey) {
|
||||||
try {
|
try {
|
||||||
return ByteUtils.toHexString(
|
return ByteUtils.toHexString(org.zz.gmhelper.SM2Util
|
||||||
org.zz.gmhelper.SM2Util.encrypt(
|
.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), content.getBytes()));
|
||||||
SM2KeyPair.publicKeyStr2ECPoint(pubkey), content.getBytes()));
|
|
||||||
} catch (InvalidCipherTextException e) {
|
} catch (InvalidCipherTextException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -76,12 +74,10 @@ public class SM2Util {
|
|||||||
|
|
||||||
public static String decrypt(String content, String privateKey) {
|
public static String decrypt(String content, String privateKey) {
|
||||||
try {
|
try {
|
||||||
ECPrivateKeyParameters privateKeyParam =
|
ECPrivateKeyParameters privateKeyParam = new ECPrivateKeyParameters(
|
||||||
new ECPrivateKeyParameters(
|
new BigInteger(privateKey, 16), org.zz.gmhelper.SM2Util.DOMAIN_PARAMS);
|
||||||
new BigInteger(privateKey, 16), org.zz.gmhelper.SM2Util.DOMAIN_PARAMS);
|
return new String(org.zz.gmhelper.SM2Util.decrypt(privateKeyParam,
|
||||||
return new String(
|
ByteUtils.fromHexString(content)));
|
||||||
org.zz.gmhelper.SM2Util.decrypt(
|
|
||||||
privateKeyParam, ByteUtils.fromHexString(content)));
|
|
||||||
} catch (InvalidCipherTextException e) {
|
} catch (InvalidCipherTextException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ public class SQLUtil {
|
|||||||
.setContextClassLoader(ContractProcess.instance.engine.getClassLoad());
|
.setContextClassLoader(ContractProcess.instance.engine.getClassLoad());
|
||||||
Class.forName(driver, true, ContractProcess.instance.engine.getClassLoad());
|
Class.forName(driver, true, ContractProcess.instance.engine.getClassLoad());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(
|
System.out.println("Still can't find class! Cl of SQLUtil:\n\t\t"
|
||||||
"Still can't find class! Cl of SQLUtil:\n\t\t"
|
+ SQLUtil.class.getClassLoader());
|
||||||
+ SQLUtil.class.getClassLoader());
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Cl of DEgine:\n\t\t" + ContractProcess.instance.engine.getClassLoad());
|
"Cl of DEgine:\n\t\t" + ContractProcess.instance.engine.getClassLoad());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -40,18 +39,15 @@ public class SQLUtil {
|
|||||||
if (password != null && !"undefined".equals(password)) {
|
if (password != null && !"undefined".equals(password)) {
|
||||||
info.put("password", password);
|
info.put("password", password);
|
||||||
}
|
}
|
||||||
if (url.startsWith("jdbc:postgresql")) info.put("sslmode", "allow");
|
if (url.startsWith("jdbc:postgresql"))
|
||||||
|
info.put("sslmode", "allow");
|
||||||
|
|
||||||
Class<?> clz =
|
Class<?> clz = Class.forName("java.sql.DriverManager", true,
|
||||||
Class.forName(
|
ContractProcess.instance.engine.getClassLoad());
|
||||||
"java.sql.DriverManager",
|
|
||||||
true,
|
|
||||||
ContractProcess.instance.engine.getClassLoad());
|
|
||||||
// set caller class into null, thus use YJSClassLoader in
|
// set caller class into null, thus use YJSClassLoader in
|
||||||
// DriverManager.isDriverAllowed(driver,classloader);
|
// DriverManager.isDriverAllowed(driver,classloader);
|
||||||
Method m =
|
Method m = clz.getDeclaredMethod("getConnection", String.class, Properties.class,
|
||||||
clz.getDeclaredMethod(
|
Class.class);
|
||||||
"getConnection", String.class, Properties.class, Class.class);
|
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return (Connection) m.invoke(null, url, info, null);
|
return (Connection) m.invoke(null, url, info, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ public class UtilRegistry {
|
|||||||
for (String name : allName) {
|
for (String name : allName) {
|
||||||
Class<?> clz;
|
Class<?> clz;
|
||||||
try {
|
try {
|
||||||
clz = Class.forName(String.format("%s.%sUtil", UtilRegistry.class.getPackage().getName(), name));
|
clz = Class.forName(String.format("%s.%sUtil",
|
||||||
|
UtilRegistry.class.getPackage().getName(), name));
|
||||||
ret.add(clz);
|
ret.add(clz);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -52,10 +53,8 @@ public class UtilRegistry {
|
|||||||
|
|
||||||
public static String getInitStr(String s, boolean open) {
|
public static String getInitStr(String s, boolean open) {
|
||||||
if (stubClzNameMap.containsKey(s)) {
|
if (stubClzNameMap.containsKey(s)) {
|
||||||
String ret =
|
String ret = String.format("%sUtil = %s.%sUtil%s;\n", s,
|
||||||
String.format(
|
UtilRegistry.class.getPackage().getName(), s, open ? "" : "Stub");
|
||||||
"%sUtil = %s.%sUtil%s;\n",
|
|
||||||
s, UtilRegistry.class.getPackage().getName(), s, open ? "" : "Stub");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -3,14 +3,20 @@ package org.bdware.sc.compiler;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public abstract class AnnotationProcessor {
|
public abstract class AnnotationProcessor {
|
||||||
public void processContract(AnnotationNode anno, ContractNode contractNode) {
|
public void processContract(AnnotationNode anno, ContractNode contractNode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception {
|
FunctionNode functionNode) throws Exception {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode functionNode) throws Exception {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ import java.lang.annotation.Target;
|
|||||||
public @interface PermissionStub {
|
public @interface PermissionStub {
|
||||||
Permission permission();
|
Permission permission();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public class PermissionStubGenerator extends ClassVisitor implements Opcodes {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
public void visit(int version, int access, String name, String signature, String superName,
|
||||||
|
String[] interfaces) {
|
||||||
if (cv != null) {
|
if (cv != null) {
|
||||||
cv.visit(version, access, name + "Stub", null, "java/lang/Object", null);
|
cv.visit(version, access, name + "Stub", null, "java/lang/Object", null);
|
||||||
}
|
}
|
||||||
@@ -53,7 +54,8 @@ public class PermissionStubGenerator extends ClassVisitor implements Opcodes {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
|
||||||
|
String[] exceptions) {
|
||||||
if (cv != null) {
|
if (cv != null) {
|
||||||
if (name.equals("<clinit>"))
|
if (name.equals("<clinit>"))
|
||||||
return null;
|
return null;
|
||||||
@@ -62,14 +64,15 @@ public class PermissionStubGenerator extends ClassVisitor implements Opcodes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
|
MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
|
||||||
new String[]{"javax/script/ScriptException"});
|
new String[] {"javax/script/ScriptException"});
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
Label l0 = new Label();
|
Label l0 = new Label();
|
||||||
mv.visitLabel(l0);
|
mv.visitLabel(l0);
|
||||||
mv.visitTypeInsn(NEW, "javax/script/ScriptException");
|
mv.visitTypeInsn(NEW, "javax/script/ScriptException");
|
||||||
mv.visitInsn(DUP);
|
mv.visitInsn(DUP);
|
||||||
mv.visitLdcInsn("Do not have " + p + " Permission");
|
mv.visitLdcInsn("Do not have " + p + " Permission");
|
||||||
mv.visitMethodInsn(INVOKESPECIAL, "javax/script/ScriptException", "<init>", "(Ljava/lang/String;)V");
|
mv.visitMethodInsn(INVOKESPECIAL, "javax/script/ScriptException", "<init>",
|
||||||
|
"(Ljava/lang/String;)V");
|
||||||
mv.visitInsn(ATHROW);
|
mv.visitInsn(ATHROW);
|
||||||
mv.visitMaxs(5, 20);
|
mv.visitMaxs(5, 20);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||||||
import org.antlr.v4.runtime.DiagnosticErrorListener;
|
import org.antlr.v4.runtime.DiagnosticErrorListener;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.doip.audit.EndpointConfig;
|
|
||||||
import org.bdware.sc.engine.YJSFilter;
|
import org.bdware.sc.engine.YJSFilter;
|
||||||
import org.bdware.sc.node.*;
|
import org.bdware.sc.node.*;
|
||||||
import org.bdware.sc.parser.JavaScriptLexer;
|
import org.bdware.sc.parser.JavaScriptLexer;
|
||||||
import org.bdware.sc.parser.YJSParser;
|
import org.bdware.sc.parser.YJSParser;
|
||||||
import org.bdware.sc.parser.YJSParser.ProgramContext;
|
import org.bdware.sc.parser.YJSParser.ProgramContext;
|
||||||
import org.bdware.sc.server.DoipClusterServer;
|
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.sc.visitor.ContractReader;
|
import org.bdware.sc.visitor.ContractReader;
|
||||||
import wrp.jdk.nashorn.internal.objects.Global;
|
import wrp.jdk.nashorn.internal.objects.Global;
|
||||||
@@ -23,6 +21,7 @@ import wrp.jdk.nashorn.internal.runtime.options.Options;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -35,8 +34,7 @@ public class YJSCompiler {
|
|||||||
ContractNode contract;
|
ContractNode contract;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class);
|
private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class);
|
||||||
|
|
||||||
public YJSCompiler() {
|
public YJSCompiler() {}
|
||||||
}
|
|
||||||
|
|
||||||
public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) {
|
public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) {
|
||||||
Global oldGlobal = Context.getGlobal();
|
Global oldGlobal = Context.getGlobal();
|
||||||
@@ -56,8 +54,8 @@ public class YJSCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Context makeContext(
|
private static Context makeContext(final InputStream in, final OutputStream out,
|
||||||
final InputStream in, final OutputStream out, final OutputStream err) {
|
final OutputStream err) {
|
||||||
final PrintStream pout =
|
final PrintStream pout =
|
||||||
out instanceof PrintStream ? (PrintStream) out : new PrintStream(out);
|
out instanceof PrintStream ? (PrintStream) out : new PrintStream(out);
|
||||||
final PrintStream perr =
|
final PrintStream perr =
|
||||||
@@ -69,7 +67,7 @@ public class YJSCompiler {
|
|||||||
final ErrorManager errors = new ErrorManager(werr);
|
final ErrorManager errors = new ErrorManager(werr);
|
||||||
// Set up options.
|
// Set up options.
|
||||||
final Options options = new Options("nashorn", werr);
|
final Options options = new Options("nashorn", werr);
|
||||||
options.process(new String[]{});
|
options.process(new String[] {});
|
||||||
// detect scripting mode by any source's first character being '#'
|
// detect scripting mode by any source's first character being '#'
|
||||||
options.set("persistent.code.cache", true);
|
options.set("persistent.code.cache", true);
|
||||||
options.set("print.code", "true");
|
options.set("print.code", "true");
|
||||||
@@ -93,14 +91,8 @@ public class YJSCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Context(
|
return new Context(options, errors, wout, werr,
|
||||||
options,
|
Thread.currentThread().getContextClassLoader(), new YJSFilter(), null);
|
||||||
errors,
|
|
||||||
wout,
|
|
||||||
werr,
|
|
||||||
Thread.currentThread().getContextClassLoader(),
|
|
||||||
new YJSFilter(),
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContractZipBundle compile(ZipFile zf) throws Exception {
|
public ContractZipBundle compile(ZipFile zf) throws Exception {
|
||||||
@@ -116,9 +108,8 @@ public class YJSCompiler {
|
|||||||
// Gson gson = new GsonBuilder().registerTypeAdapter(Contract.Type.class,
|
// Gson gson = new GsonBuilder().registerTypeAdapter(Contract.Type.class,
|
||||||
// typeAdapter)
|
// typeAdapter)
|
||||||
|
|
||||||
ContractManifest cm =
|
ContractManifest cm = JsonUtil.GSON.fromJson(new InputStreamReader(manifestInput),
|
||||||
JsonUtil.GSON.fromJson(
|
ContractManifest.class);
|
||||||
new InputStreamReader(manifestInput), ContractManifest.class);
|
|
||||||
// 如果没有就不限制,根据gas进行插装
|
// 如果没有就不限制,根据gas进行插装
|
||||||
if (0L != cm.getInsnLimit()) {
|
if (0L != cm.getInsnLimit()) {
|
||||||
LOGGER.info("++++++++++++++++++++++true");
|
LOGGER.info("++++++++++++++++++++++true");
|
||||||
@@ -127,26 +118,49 @@ public class YJSCompiler {
|
|||||||
Set<String> toParse = new HashSet<>();
|
Set<String> toParse = new HashSet<>();
|
||||||
toParse.add(cm.main);
|
toParse.add(cm.main);
|
||||||
Set<String> todo = new HashSet<>();
|
Set<String> todo = new HashSet<>();
|
||||||
|
Set<String> allEntries = new HashSet<>();
|
||||||
|
Enumeration<? extends ZipEntry> iter = zf.entries();
|
||||||
|
for (; iter.hasMoreElements();) {
|
||||||
|
ZipEntry ele = iter.nextElement();
|
||||||
|
if (ele != null)
|
||||||
|
allEntries.add(ele.getName());
|
||||||
|
}
|
||||||
while (toParse.size() > 0) {
|
while (toParse.size() > 0) {
|
||||||
for (String str : toParse) {
|
for (String str : toParse) {
|
||||||
if (czb.containsPath(str)) {
|
if (czb.containsPath(str)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
|
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
|
||||||
|
LOGGER.info("load yjs:" + str);
|
||||||
if (null == entry) {
|
if (null == entry) {
|
||||||
throw new IllegalStateException("missing import:" + str);
|
throw new IllegalStateException("missing import:" + str);
|
||||||
}
|
}
|
||||||
ContractNode cn = compile(zf.getInputStream(entry), str);
|
ContractNode cn = compile(zf.getInputStream(entry), str);
|
||||||
|
String cnPath = entry.getName();
|
||||||
|
int i = cnPath.lastIndexOf("/");
|
||||||
|
String cnDir = "";
|
||||||
|
if (i != -1)
|
||||||
|
cnDir = cnPath.substring(0, i);
|
||||||
czb.put(str, cn);
|
czb.put(str, cn);
|
||||||
for (ImportNode in : cn.getImports()) {
|
for (ImportNode in : cn.getImports()) {
|
||||||
todo.add(in.getPath());
|
String path = in.getPath();
|
||||||
|
if (!path.startsWith("/"))
|
||||||
|
path = cnDir + "/" + path;
|
||||||
|
path = path.replaceAll("/\\./", "/");
|
||||||
|
todo.add(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toParse.clear();
|
toParse.clear();
|
||||||
for (String str : todo) {
|
for (String str : todo) {
|
||||||
if (!czb.containsPath(str)) {
|
if (allEntries.contains(str))
|
||||||
toParse.add(str);
|
toParse.add(str);
|
||||||
|
else {
|
||||||
|
// TODO parse manifest.json first?
|
||||||
|
for (String entry : allEntries)
|
||||||
|
if (!czb.containsPath(entry) && entry.startsWith(str)
|
||||||
|
&& entry.endsWith(".yjs")) {
|
||||||
|
toParse.add(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
todo.clear();
|
todo.clear();
|
||||||
@@ -154,26 +168,26 @@ public class YJSCompiler {
|
|||||||
// add function _preSub
|
// add function _preSub
|
||||||
// Kaidong Wu
|
// Kaidong Wu
|
||||||
String preSubConName = cm.main.substring(0, cm.main.length() - 4) + "PreSub";
|
String preSubConName = cm.main.substring(0, cm.main.length() - 4) + "PreSub";
|
||||||
String preSubContract =
|
String preSubContract = "contract " + preSubConName
|
||||||
"contract "
|
+ " { function _preSub (e) { YancloudUtil.preSub(e.topic, e.content); }}";
|
||||||
+ preSubConName
|
|
||||||
+ " { function _preSub (e) { YancloudUtil.preSub(e.topic, e.content); }}";
|
|
||||||
ContractNode preSubNode =
|
ContractNode preSubNode =
|
||||||
compile(
|
compile(new ByteArrayInputStream(preSubContract.getBytes(StandardCharsets.UTF_8)),
|
||||||
new ByteArrayInputStream(preSubContract.getBytes(StandardCharsets.UTF_8)),
|
|
||||||
preSubConName + ".yjs");
|
preSubConName + ".yjs");
|
||||||
czb.put(preSubConName + ".yjs", preSubNode);
|
czb.put(preSubConName + ".yjs", preSubNode);
|
||||||
LOGGER.info("--compile-- " + preSubConName);
|
LOGGER.info("--compile-- " + preSubConName);
|
||||||
|
|
||||||
String globalBeanName = cm.main.substring(0, cm.main.length() - 4) + "GlobalBean";
|
String globalBeanName = cm.main.substring(0, cm.main.length() - 4) + "GlobalBean";
|
||||||
String globalBeanContract =
|
String globalBeanContract = "contract " + globalBeanName
|
||||||
"contract " + globalBeanName + "{ function setGlobal (_global) { Global = _global; }\n" +
|
+ "{ function setGlobal (_global) { Global = _global; }\n"
|
||||||
" function getGlobal () { return Global; }}";
|
+ " function getGlobal () { return Global; }}";
|
||||||
czb.put(globalBeanName + ".yjs",
|
czb.put(globalBeanName + ".yjs",
|
||||||
compile(new ByteArrayInputStream(globalBeanContract.getBytes(StandardCharsets.UTF_8)),
|
compile(new ByteArrayInputStream(
|
||||||
|
globalBeanContract.getBytes(StandardCharsets.UTF_8)),
|
||||||
globalBeanName + ".yjs"));
|
globalBeanName + ".yjs"));
|
||||||
LOGGER.info("--compile-- " + globalBeanName);
|
LOGGER.info("--compile-- " + globalBeanName);
|
||||||
|
czb.setMergedContractNode();
|
||||||
|
ContractNode node = czb.mergeContractNode();
|
||||||
|
handleFunctionAnnotation(node);
|
||||||
return czb;
|
return czb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,19 +207,24 @@ public class YJSCompiler {
|
|||||||
contract = reader.visitProgram(tree);
|
contract = reader.visitProgram(tree);
|
||||||
// 遍历完 获取 contract 里的 yjs type
|
// 遍历完 获取 contract 里的 yjs type
|
||||||
contract.initPlainText(cts);
|
contract.initPlainText(cts);
|
||||||
handleAnnotation(contract);//处理注解
|
handleModuleAnnotation(contract);// 处理注解
|
||||||
|
handleFunctionAnnotation(contract);
|
||||||
return contract;
|
return contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAnnotation(ContractNode contractNode) throws Exception {
|
private void handleModuleAnnotation(ContractNode contractNode) throws Exception {
|
||||||
for (AnnotationNode node : contract.annotations) {
|
for (AnnotationNode node : contract.annotations) {
|
||||||
AnnotationProcessor processor = findProcessor(node);
|
AnnotationProcessor processor = findProcessor(node);
|
||||||
if (processor != null) {
|
if (processor != null) {
|
||||||
processor.processContract(node, contractNode);
|
processor.processContract(node, contractNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFunctionAnnotation(ContractNode contractNode) throws Exception {
|
||||||
for (FunctionNode functionNode : contractNode.getFunctions()) {
|
for (FunctionNode functionNode : contractNode.getFunctions()) {
|
||||||
List<AnnotationNode> annos = functionNode.annotations;//函数里的annotation
|
List<AnnotationNode> annos = functionNode.annotations;// 函数里的annotation
|
||||||
if (annos != null)
|
if (annos != null)
|
||||||
for (AnnotationNode anno : annos) {
|
for (AnnotationNode anno : annos) {
|
||||||
AnnotationProcessor processor = findProcessor(anno);
|
AnnotationProcessor processor = findProcessor(anno);
|
||||||
@@ -213,9 +232,19 @@ public class YJSCompiler {
|
|||||||
processor.processFunction(anno, contractNode, functionNode);
|
processor.processFunction(anno, contractNode, functionNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (InterfaceNode interfaceNode : contractNode.getInterfaces()) {
|
||||||
|
List<AnnotationNode> annos = interfaceNode.annotations;// 函数里的annotation
|
||||||
|
if (annos != null)
|
||||||
|
for (AnnotationNode anno : annos) {
|
||||||
|
AnnotationProcessor processor = findProcessor(anno);
|
||||||
|
if (processor != null)
|
||||||
|
processor.processInterface(anno, contractNode, interfaceNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnnotationProcessor findProcessor(AnnotationNode node) {
|
public static AnnotationProcessor findProcessor(AnnotationNode node) {
|
||||||
try {
|
try {
|
||||||
String clzName = YJSCompiler.class.getPackage().getName();
|
String clzName = YJSCompiler.class.getPackage().getName();
|
||||||
clzName += ".ap." + node.getType();
|
clzName += ".ap." + node.getType();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
|
|
||||||
public class Confidential extends AnnotationProcessor {
|
public class Confidential extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
functionNode.setConfidential(true); }
|
FunctionNode functionNode) {
|
||||||
|
functionNode.setConfidential(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import org.bdware.sc.util.JsonUtil;
|
|||||||
|
|
||||||
public class Cost extends AnnotationProcessor {
|
public class Cost extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
CostDetail detail = JsonUtil.fromJson(anno.getArgs().get(0), CostDetail.class);
|
CostDetail detail = JsonUtil.fromJson(anno.getArgs().get(0), CostDetail.class);
|
||||||
functionNode.setCost(detail);
|
functionNode.setCost(detail);
|
||||||
if (detail.isCountGas())
|
if (detail.isCountGas())
|
||||||
|
|||||||
@@ -2,36 +2,27 @@ package org.bdware.sc.compiler.ap;
|
|||||||
|
|
||||||
import org.bdware.sc.bean.DoipOperationInfo;
|
import org.bdware.sc.bean.DoipOperationInfo;
|
||||||
import org.bdware.sc.compiler.AnnotationProcessor;
|
import org.bdware.sc.compiler.AnnotationProcessor;
|
||||||
import org.bdware.sc.engine.hook.DOOPAfterExecHandler;
|
|
||||||
import org.bdware.sc.engine.hook.DOOPBeforeExecHandler;
|
|
||||||
import org.bdware.sc.handler.DOOPRequestHandler;
|
|
||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
|
|
||||||
// DOOP is designed for DoipModule which contains specific functions for RepositoryHandler
|
// DOOP is designed for DoipModule which contains specific functions for RepositoryHandler
|
||||||
public class DOOP extends AnnotationProcessor {
|
public class DOOP extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception {
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
FunctionNode functionNode) throws Exception {
|
||||||
// 通过DOOP注解,解析对应的值,并放进对应的FunctionNode中
|
// 通过DOOP注解,解析对应的值,并放进对应的FunctionNode中
|
||||||
// 注解必须暴露出来昂!!!
|
|
||||||
functionNode.setIsExport(true);
|
functionNode.setIsExport(true);
|
||||||
functionNode.setIsDoipOperation(true);
|
functionNode.setIsDoipOperation(true);
|
||||||
functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
||||||
// functionNode.setFunctionName(functionNode.getDoipOperationInfo().operationName);
|
}
|
||||||
|
|
||||||
// 维护DOOPRequestHandler
|
@Override
|
||||||
DOOPRequestHandler.createHandler();
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
DOOPRequestHandler.instance.addDoipOperation(functionNode);
|
InterfaceNode interfaceNode) throws Exception {
|
||||||
|
interfaceNode.setIsDoipOperation(true);
|
||||||
// 维护DOOPHandler
|
interfaceNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
||||||
DOOPBeforeExecHandler.createDOOPHandler();
|
|
||||||
DOOPBeforeExecHandler.instance.putFuncNameAndDoipOperationsMapping(functionNode);
|
|
||||||
DOOPAfterExecHandler.createDOOPHandler();
|
|
||||||
DOOPAfterExecHandler.instance.putFuncNameAndDoipOperationsMapping(functionNode);
|
|
||||||
|
|
||||||
// 维护ContractNode,functionName is useless, use BasicOperation to map the corresponding functionNode
|
|
||||||
// contractNode.updateFunctionMap(functionNode.functionName, functionNode.getDoipOperationInfo().operationName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/main/java/org/bdware/sc/compiler/ap/Fork.java
Normal file
22
src/main/java/org/bdware/sc/compiler/ap/Fork.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package org.bdware.sc.compiler.ap;
|
||||||
|
|
||||||
|
import org.bdware.sc.bean.ForkInfo;
|
||||||
|
import org.bdware.sc.compiler.AnnotationProcessor;
|
||||||
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
|
import org.bdware.sc.node.ContractNode;
|
||||||
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
|
public class Fork extends AnnotationProcessor {
|
||||||
|
@Override
|
||||||
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
FunctionNode functionNode) {
|
||||||
|
functionNode.setForkInfo(ForkInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) {
|
||||||
|
interfaceNode.setForkInfo(ForkInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,8 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
|
|
||||||
public class HomomorphicDecrypt extends AnnotationProcessor {
|
public class HomomorphicDecrypt extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
FunctionNode functionNode) {
|
||||||
functionNode.setHomomorphicDecrypt(true);
|
functionNode.setHomomorphicDecrypt(true);
|
||||||
functionNode.setKeyManagerID(anno.getArgs().get(0));
|
functionNode.setKeyManagerID(anno.getArgs().get(0));
|
||||||
functionNode.setSecretID(anno.getArgs().get(1));
|
functionNode.setSecretID(anno.getArgs().get(1));
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
|
|
||||||
public class HomomorphicEncrypt extends AnnotationProcessor {
|
public class HomomorphicEncrypt extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
FunctionNode functionNode) {
|
||||||
functionNode.setHomomorphicEncrypt(true);
|
functionNode.setHomomorphicEncrypt(true);
|
||||||
functionNode.setKeyManagerID(anno.getArgs().get(0));
|
functionNode.setKeyManagerID(anno.getArgs().get(0));
|
||||||
functionNode.setSecretID(anno.getArgs().get(1));
|
functionNode.setSecretID(anno.getArgs().get(1));
|
||||||
|
|||||||
@@ -5,13 +5,20 @@ import org.bdware.sc.compiler.AnnotationProcessor;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public class Join extends AnnotationProcessor {
|
public class Join extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
// functionNode.setRouteInfo(RouteInfo.create(anno,contractNode));
|
// functionNode.setRouteInfo(RouteInfo.create(anno,contractNode));
|
||||||
//增加标记,在ContractNode中记录Join相关的函数和Join规则
|
// 增加标记,在ContractNode中记录Join相关的函数和Join规则
|
||||||
functionNode.setJoinInfo(JoinInfo.create(anno,contractNode));
|
functionNode.setJoinInfo(JoinInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) {
|
||||||
|
interfaceNode.setJoinInfo(JoinInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ public class LogLocation extends AnnotationProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
if (anno != null && anno.getArgs() != null)
|
if (anno != null && anno.getArgs() != null)
|
||||||
for (String s : anno.getArgs()) {
|
for (String s : anno.getArgs()) {
|
||||||
if (s.equals("\"dataware\"")
|
if (s.equals("\"dataware\"") || s.equals("\"bdledger\"")
|
||||||
|| s.equals("\"bdledger\"")
|
|
||||||
|| s.equals("\"bdledger:\"")) {
|
|| s.equals("\"bdledger:\"")) {
|
||||||
functionNode.setLogToBDContract(true);
|
functionNode.setLogToBDContract(true);
|
||||||
} else if (s.startsWith("\"bdledger:") && s.length() > 11) {
|
} else if (s.startsWith("\"bdledger:") && s.length() > 11) {
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ public class LogType extends AnnotationProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
for (String str : anno.getArgs()) {
|
for (String str : anno.getArgs()) {
|
||||||
org.bdware.sc.node.LogType type = org.bdware.sc.node.LogType.parse(str);
|
org.bdware.sc.node.LogType type = org.bdware.sc.node.LogType.parse(str);
|
||||||
functionNode.addLogType(type);
|
functionNode.addLogType(type);
|
||||||
if (type == org.bdware.sc.node.LogType.Branch) contractNode.setInstrumentBranch(true);
|
if (type == org.bdware.sc.node.LogType.Branch)
|
||||||
|
contractNode.setInstrumentBranch(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package org.bdware.sc.compiler.ap;
|
package org.bdware.sc.compiler.ap;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.bdware.sc.bean.RouteInfo;
|
import org.bdware.sc.bean.RouteInfo;
|
||||||
import org.bdware.sc.compiler.AnnotationProcessor;
|
import org.bdware.sc.compiler.AnnotationProcessor;
|
||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.CostDetail;
|
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public class Route extends AnnotationProcessor {
|
public class Route extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
functionNode.setRouteInfo(RouteInfo.create(anno,contractNode));
|
functionNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) {
|
||||||
|
interfaceNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
public class Split extends AnnotationProcessor {
|
public class Split extends AnnotationProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processFunction(
|
public void processFunction(AnnotationNode anno, ContractNode contractNode,
|
||||||
AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
functionNode.setRouteInfo(RouteInfo.create(anno,contractNode));
|
functionNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
171
src/main/java/org/bdware/sc/crdt/SharableVarManager.java
Normal file
171
src/main/java/org/bdware/sc/crdt/SharableVarManager.java
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
package org.bdware.sc.crdt;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.bdware.crdt.basic.Constants;
|
||||||
|
import org.bdware.crdt.basic.JoinableCRDT;
|
||||||
|
import org.bdware.doip.audit.AuditDoaClient;
|
||||||
|
import org.bdware.doip.audit.EndpointConfig;
|
||||||
|
import org.bdware.doip.audit.client.AuditDoipClient;
|
||||||
|
import org.bdware.doip.audit.client.AuditIrpClient;
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
|
import org.bdware.doip.endpoint.client.DoipMessageCallback;
|
||||||
|
import org.bdware.irp.client.IrpClient;
|
||||||
|
import org.bdware.irp.stateinfo.StateInfoBase;
|
||||||
|
import org.bdware.sc.crdt.proxy.*;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class SharableVarManager {
|
||||||
|
static Logger LOGGER = LogManager.getLogger(SharableVarManager.class);
|
||||||
|
public static SharableVarManager instance;
|
||||||
|
public final String cpId;
|
||||||
|
Map<String, SharableVar> allVars;
|
||||||
|
IrpClient client;
|
||||||
|
AuditDoaClient doaClient;
|
||||||
|
|
||||||
|
public static final String SHARABLEOP = "86.100871/SyncVar";
|
||||||
|
|
||||||
|
public SharableVarManager(String cpId, EndpointConfig config) {
|
||||||
|
this.allVars = new ConcurrentHashMap<>();
|
||||||
|
this.client = new AuditIrpClient(config);
|
||||||
|
this.doaClient = new AuditDoaClient("", config, null);
|
||||||
|
this.cpId = cpId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initSharableVarManager(String id, EndpointConfig config) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new SharableVarManager(id, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoipMessage handleSyncMessage(DoipMessage message) {
|
||||||
|
try {
|
||||||
|
String varId = message.header.parameters.attributes.get("varId").getAsString();
|
||||||
|
String content = message.header.parameters.attributes.get("content").getAsString();
|
||||||
|
String type = message.header.parameters.attributes.get("type").getAsString();
|
||||||
|
SharableVar var = allVars.get(varId);
|
||||||
|
if (var != null) {
|
||||||
|
if (Objects.equals(type, "r2r") || Objects.equals(type, "w2r")) {
|
||||||
|
JoinableCRDT delta = JsonUtil.fromJson(content, var.readerVar.getClass());
|
||||||
|
var.readerVar.join(delta);
|
||||||
|
var.readerVarDeltaQueue.add(delta);
|
||||||
|
} else if (Objects.equals(type, "w2w")) {
|
||||||
|
JoinableCRDT delta = JsonUtil.fromJson(content, var.writerVar.getClass());
|
||||||
|
var.writerVar.join(delta);
|
||||||
|
var.writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder =
|
||||||
|
new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Success, message);
|
||||||
|
builder.addAttributes("msg", "success");
|
||||||
|
return builder.create();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
e.printStackTrace();
|
||||||
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder =
|
||||||
|
new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.UnKnownError, message);
|
||||||
|
builder.addAttributes("exception", bo.toString());
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DoipMessage createSyncMessage(String target, String varId, String content,
|
||||||
|
String type) {
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createRequest(target, SHARABLEOP);
|
||||||
|
builder.addAttributes("varId", varId);
|
||||||
|
builder.addAttributes("content", content);
|
||||||
|
builder.addAttributes("type", type);
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastSyncMessage(String varId, List<String> sendTo, String content,
|
||||||
|
String type) {
|
||||||
|
for (String target : sendTo) {
|
||||||
|
DoipMessage doipMessage = createSyncMessage(target, varId, content, type);
|
||||||
|
if (target.equals(cpId)) {
|
||||||
|
LOGGER.info("Handle Sync locally:"
|
||||||
|
+ JsonUtil.toJson(JsonDoipMessage.fromDoipMessage(doipMessage)));
|
||||||
|
handleSyncMessage(doipMessage);
|
||||||
|
} else {
|
||||||
|
AuditDoipClient client = getClient(target);
|
||||||
|
client.sendMessage(doipMessage, new DoipMessageCallback() {
|
||||||
|
@Override
|
||||||
|
public void onResult(DoipMessage doipMessage) {
|
||||||
|
LOGGER.info("RECV Sync:"
|
||||||
|
+ JsonUtil.toJson(JsonDoipMessage.fromDoipMessage(doipMessage)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AuditDoipClient getClient(String id) {
|
||||||
|
return doaClient.convertDoidToRepo(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized SharableVar createVar(String identifier, String type) {
|
||||||
|
try {
|
||||||
|
if (allVars.containsKey(identifier)) {
|
||||||
|
return allVars.get(identifier);
|
||||||
|
}
|
||||||
|
StateInfoBase stateInfoBase = client.resolve(identifier);
|
||||||
|
if (stateInfoBase.handleValues.has("bdwType") && stateInfoBase.handleValues
|
||||||
|
.get("bdwType").getAsString().equals("SharableVar")) {
|
||||||
|
SharableVarState.SharableVarConfiguration sharableVarConf =
|
||||||
|
JsonUtil.fromJson(stateInfoBase.handleValues,
|
||||||
|
SharableVarState.SharableVarConfiguration.class);
|
||||||
|
SharableVar sharableVar = createSharableVar(sharableVarConf, identifier, type);
|
||||||
|
if (sharableVar != null) {
|
||||||
|
allVars.put(identifier, sharableVar);
|
||||||
|
}
|
||||||
|
return sharableVar;
|
||||||
|
} else
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SharableVar createSharableVar(SharableVarState.SharableVarConfiguration conf,
|
||||||
|
String identifier, String type) {
|
||||||
|
switch (type) {
|
||||||
|
case Constants.TypeName.G_COUNTER:
|
||||||
|
return new GCounterProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.PN_COUNTER:
|
||||||
|
return new PNCounterProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.DW_FLAG:
|
||||||
|
return new DWFlagProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.LWW_REGISTER:
|
||||||
|
return new LWWRegisterProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.MV_REGISTER:
|
||||||
|
return new MVRegisterProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.G_SET:
|
||||||
|
return new GSetProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.TP_SET:
|
||||||
|
return new TPSetProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.AW_OR_SET:
|
||||||
|
return new AWORSetProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.RW_OR_SET:
|
||||||
|
return new RWORSetProxy(identifier, cpId, conf);
|
||||||
|
case Constants.TypeName.RW_LWW_SET:
|
||||||
|
return new RWLWWSetProxy(identifier, cpId, conf);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
304
src/main/java/org/bdware/sc/crdt/SharableVarState.java
Normal file
304
src/main/java/org/bdware/sc/crdt/SharableVarState.java
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
package org.bdware.sc.crdt;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class SharableVarState {
|
||||||
|
private String myId;
|
||||||
|
|
||||||
|
private SharableVarConfiguration sharableVarConfiguration;
|
||||||
|
|
||||||
|
private Integer myIndex;
|
||||||
|
|
||||||
|
// 是reader
|
||||||
|
private boolean readerFlag;
|
||||||
|
|
||||||
|
// 是writer
|
||||||
|
private boolean writerFlag;
|
||||||
|
|
||||||
|
// 是reader的根结点
|
||||||
|
private boolean readerRootFlag;
|
||||||
|
|
||||||
|
// 是writer的根结点
|
||||||
|
private boolean writerRootFlag;
|
||||||
|
|
||||||
|
// 作为writer的话,非根节点具有parent。根结点为null
|
||||||
|
private String writerParent;
|
||||||
|
|
||||||
|
// 作为reader的话,非叶子节点具有children,叶子节点为null
|
||||||
|
private List<String> readerChildren;
|
||||||
|
|
||||||
|
// reader森林的根结点们,用来给writer根结点同步数据用
|
||||||
|
private List<String> readerRoots;
|
||||||
|
|
||||||
|
private Long writeInterval;
|
||||||
|
|
||||||
|
private Long readerInterval;
|
||||||
|
|
||||||
|
public SharableVarState(String myId, SharableVarConfiguration sharableVarConfiguration) {
|
||||||
|
this.myId = myId;
|
||||||
|
this.sharableVarConfiguration = sharableVarConfiguration;
|
||||||
|
parseProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseProperties() {
|
||||||
|
for (int i = 0; i < sharableVarConfiguration.getNodeIds().length; i++) {
|
||||||
|
if (Objects.equals(sharableVarConfiguration.getNodeIds()[i], myId)) {
|
||||||
|
this.myIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.myIndex == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int writerParentIdx = sharableVarConfiguration.writerParents[this.myIndex];
|
||||||
|
if (writerParentIdx == -1) {
|
||||||
|
writerFlag = true;
|
||||||
|
writerRootFlag = true;
|
||||||
|
} else if (writerParentIdx >= 0) {
|
||||||
|
writerFlag = true;
|
||||||
|
writerParent = sharableVarConfiguration.nodeIds[writerParentIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
int readerParentIdx = sharableVarConfiguration.readerParents[this.myIndex];
|
||||||
|
if (readerParentIdx == -1) {
|
||||||
|
readerFlag = true;
|
||||||
|
readerRootFlag = true;
|
||||||
|
} else if (readerParentIdx >= 0) {
|
||||||
|
readerFlag = true;
|
||||||
|
}
|
||||||
|
if (readerFlag) {
|
||||||
|
readerChildren = new ArrayList<>();
|
||||||
|
for (int i = 0; i < sharableVarConfiguration.readerParents.length; i++) {
|
||||||
|
if (sharableVarConfiguration.readerParents[i] == myIndex) {
|
||||||
|
readerChildren.add(sharableVarConfiguration.nodeIds[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readerInterval = sharableVarConfiguration.readerIntervals[myIndex];
|
||||||
|
}
|
||||||
|
if (writerFlag) {
|
||||||
|
writeInterval = sharableVarConfiguration.writerIntervals[myIndex];
|
||||||
|
}
|
||||||
|
if (writerRootFlag) {
|
||||||
|
readerRoots = new ArrayList<>();
|
||||||
|
for (int i = 0; i < sharableVarConfiguration.readerParents.length; i++) {
|
||||||
|
if (sharableVarConfiguration.readerParents[i] == -1) {
|
||||||
|
readerRoots.add(sharableVarConfiguration.nodeIds[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMyId() {
|
||||||
|
return myId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMyId(String myId) {
|
||||||
|
this.myId = myId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SharableVarConfiguration getSharableVarConfiguration() {
|
||||||
|
return sharableVarConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSharableVarConfiguration(SharableVarConfiguration sharableVarConfiguration) {
|
||||||
|
this.sharableVarConfiguration = sharableVarConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMyIndex() {
|
||||||
|
return myIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMyIndex(Integer myIndex) {
|
||||||
|
this.myIndex = myIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReaderFlag() {
|
||||||
|
return readerFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderFlag(boolean readerFlag) {
|
||||||
|
this.readerFlag = readerFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWriterFlag() {
|
||||||
|
return writerFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterFlag(boolean writerFlag) {
|
||||||
|
this.writerFlag = writerFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReaderRootFlag() {
|
||||||
|
return readerRootFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderRootFlag(boolean readerRootFlag) {
|
||||||
|
this.readerRootFlag = readerRootFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWriterRootFlag() {
|
||||||
|
return writerRootFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterRootFlag(boolean writerRootFlag) {
|
||||||
|
this.writerRootFlag = writerRootFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWriterParent() {
|
||||||
|
return writerParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterParent(String writerParent) {
|
||||||
|
this.writerParent = writerParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getReaderChildren() {
|
||||||
|
return readerChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderChildren(List<String> readerChildren) {
|
||||||
|
this.readerChildren = readerChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getReaderRoots() {
|
||||||
|
return readerRoots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderRoots(List<String> readerRoots) {
|
||||||
|
this.readerRoots = readerRoots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getWriteInterval() {
|
||||||
|
return writeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriteInterval(Long writeInterval) {
|
||||||
|
this.writeInterval = writeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getReaderInterval() {
|
||||||
|
return readerInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderInterval(Long readerInterval) {
|
||||||
|
this.readerInterval = readerInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SharableVarConfiguration {
|
||||||
|
// ["/bdrepo1/var/0", "/bdrepo1/var/1", "/bdrepo1/var/2", "/bdrepo1/var/3"]
|
||||||
|
// 0(w) -> 2(w) -> 1(r) -> 3(r)
|
||||||
|
// |
|
||||||
|
// 1(w) -
|
||||||
|
|
||||||
|
// ["/bdrepo1/var/0", "/bdrepo1/var/1", "/bdrepo1/var/2", "/bdrepo1/var/3"]
|
||||||
|
String[] nodeIds;
|
||||||
|
long maxDelay;
|
||||||
|
int[] writerIndexes;
|
||||||
|
int[] readerIndexes;
|
||||||
|
|
||||||
|
// [2, 2, -1, -2] -2表示该节点为非writer节点,-1表示该结点为writer根结点
|
||||||
|
int[] writerParents;
|
||||||
|
// [-2, -1, -2, 1] -2表示该节点为非reader节点,-1表示该结点为reader根结点
|
||||||
|
int[] readerParents;
|
||||||
|
// [5, 5, 6, -1] -1为无需同步
|
||||||
|
long[] writerIntervals;
|
||||||
|
// [-1, 4, -1, -1]
|
||||||
|
long[] readerIntervals;
|
||||||
|
|
||||||
|
public String[] getNodeIds() {
|
||||||
|
return nodeIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeIds(String[] nodeIds) {
|
||||||
|
this.nodeIds = nodeIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMaxDelay() {
|
||||||
|
return maxDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxDelay(long maxDelay) {
|
||||||
|
this.maxDelay = maxDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getWriterIndexes() {
|
||||||
|
return writerIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterIndexes(int[] writerIndexes) {
|
||||||
|
this.writerIndexes = writerIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getReaderIndexes() {
|
||||||
|
return readerIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderIndexes(int[] readerIndexes) {
|
||||||
|
this.readerIndexes = readerIndexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getWriterParents() {
|
||||||
|
return writerParents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterParents(int[] writerParents) {
|
||||||
|
this.writerParents = writerParents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getReaderParents() {
|
||||||
|
return readerParents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderParents(int[] readerParents) {
|
||||||
|
this.readerParents = readerParents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getWriterIntervals() {
|
||||||
|
return writerIntervals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriterIntervals(long[] writerIntervals) {
|
||||||
|
this.writerIntervals = writerIntervals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getReaderIntervals() {
|
||||||
|
return readerIntervals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReaderIntervals(long[] readerIntervals) {
|
||||||
|
this.readerIntervals = readerIntervals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// ["/bdrepo1/var/0", "/bdrepo1/var/1", "/bdrepo1/var/2", "/bdrepo1/var/3"]
|
||||||
|
// 0(w) -> 2(w) -> 1(r) -> 3(r)
|
||||||
|
// |
|
||||||
|
// 1(w) -
|
||||||
|
|
||||||
|
|
||||||
|
SharableVarConfiguration sharableVarConfiguration = new SharableVarConfiguration();
|
||||||
|
sharableVarConfiguration.setNodeIds(new String[] {"/bdrepo1/var/0", "/bdrepo1/var/1",
|
||||||
|
"/bdrepo1/var/2", "/bdrepo1/var/3"});
|
||||||
|
sharableVarConfiguration.setWriterParents(new int[] {2, 2, -1, -2});
|
||||||
|
sharableVarConfiguration.setReaderParents(new int[] {-2, -1, -2, 1});
|
||||||
|
sharableVarConfiguration.setWriterIntervals(new long[] {5, 5, 6, -1});
|
||||||
|
sharableVarConfiguration.setReaderIntervals(new long[] {-1, 4, -1, -1});
|
||||||
|
|
||||||
|
|
||||||
|
SharableVarState sharableVarState0 =
|
||||||
|
new SharableVarState("/bdrepo1/var/0", sharableVarConfiguration);
|
||||||
|
SharableVarState sharableVarState1 =
|
||||||
|
new SharableVarState("/bdrepo1/var/1", sharableVarConfiguration);
|
||||||
|
SharableVarState sharableVarState2 =
|
||||||
|
new SharableVarState("/bdrepo1/var/2", sharableVarConfiguration);
|
||||||
|
SharableVarState sharableVarState3 =
|
||||||
|
new SharableVarState("/bdrepo1/var/3", sharableVarConfiguration);
|
||||||
|
System.out.println(sharableVarState0);
|
||||||
|
System.out.println(sharableVarState1);
|
||||||
|
System.out.println(sharableVarState2);
|
||||||
|
System.out.println(sharableVarState3);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/main/java/org/bdware/sc/crdt/planning/PlanningTest.java
Normal file
54
src/main/java/org/bdware/sc/crdt/planning/PlanningTest.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
public class PlanningTest {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
final int nodeIdsCount = 1000;
|
||||||
|
final int writerCount = 500;
|
||||||
|
final int readerCount = 500;
|
||||||
|
String[] nodeIds = new String[nodeIdsCount];
|
||||||
|
int[] writers = new int[writerCount];
|
||||||
|
int[] readers = new int[readerCount];
|
||||||
|
for (int i = 0; i < nodeIdsCount; ++i) {
|
||||||
|
nodeIds[i] = "node_" + i;
|
||||||
|
if (i < writerCount) {
|
||||||
|
writers[i] = i;
|
||||||
|
}
|
||||||
|
if (i >= nodeIdsCount - readerCount) {
|
||||||
|
readers[i - nodeIdsCount + readerCount] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long maxDelay = 300;
|
||||||
|
int bandwidthUpload = 30;
|
||||||
|
int bandwidthDownload = 30;
|
||||||
|
int datasize = 10;
|
||||||
|
double domainSize = 100 * datasize;
|
||||||
|
|
||||||
|
PlanningWith0Expansivity planning0 = new PlanningWith0Expansivity(nodeIds, writers, readers,
|
||||||
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
||||||
|
PlanningWithkExpansivity planningK = new PlanningWithkExpansivity(nodeIds, writers, readers,
|
||||||
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize, domainSize);
|
||||||
|
PlanningWith1Expansivity planning1 = new PlanningWith1Expansivity(nodeIds, writers, readers,
|
||||||
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
planning0.adjustAndCalc();
|
||||||
|
planning0.allocate();
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.out.println("took " + (end - start));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
planningK.adjustAndCalc();
|
||||||
|
planningK.allocate();
|
||||||
|
end = System.currentTimeMillis();
|
||||||
|
System.out.println("took " + (end - start));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
planning1.adjustAndCalc();
|
||||||
|
planning1.allocate();
|
||||||
|
end = System.currentTimeMillis();
|
||||||
|
System.out.println("took " + (end - start));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
public class PlanningWith0Expansivity extends SharableNetworkPlanning {
|
||||||
|
public PlanningWith0Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
||||||
|
this.nodeIds = nodeIds;
|
||||||
|
this.writers = writers;
|
||||||
|
this.readers = readers;
|
||||||
|
this.maxDelay = maxDelay;
|
||||||
|
this.bandwidthDownload = bandwidthDownload;
|
||||||
|
this.bandwidthUpload = bandwidthUpload;
|
||||||
|
this.dataSize = dataSize;
|
||||||
|
this.totalCountW = writers.length;
|
||||||
|
this.totalCountR = readers.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writerTreeConstraint() {
|
||||||
|
if (frequencySyncW > 0) {
|
||||||
|
double common = frequencySyncW * dataSize;
|
||||||
|
// 非叶子节点下载带宽
|
||||||
|
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writer2ReaderConstraint() {
|
||||||
|
double common = frequencySyncWR * dataSize;
|
||||||
|
// Writer根节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * rootCountR;
|
||||||
|
// Reader根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common * rootCountW;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readerTreeConstraint() {
|
||||||
|
if (frequencySyncR > 0) {
|
||||||
|
double common = frequencySyncR * dataSize;
|
||||||
|
// Reader非叶子节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
|
// Reader非根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calcOptimizedResult() {
|
||||||
|
double a = (treeHeightW - 1) * (totalCountW - rootCountW);
|
||||||
|
double b = rootCountR * rootCountW;
|
||||||
|
double c = (treeHeightR - 1) * (totalCountR - rootCountR);
|
||||||
|
|
||||||
|
double A = Math.sqrt(a);
|
||||||
|
double B = Math.sqrt(b);
|
||||||
|
double C = Math.sqrt(c);
|
||||||
|
|
||||||
|
wDelay = (long) (maxDelay * (A / (A + B + C)));
|
||||||
|
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
|
||||||
|
rDelay = (long) (maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
|
totalData =
|
||||||
|
(long) (dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
public class PlanningWith1Expansivity extends SharableNetworkPlanning {
|
||||||
|
public PlanningWith1Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
||||||
|
this.nodeIds = nodeIds;
|
||||||
|
this.writers = writers;
|
||||||
|
this.readers = readers;
|
||||||
|
this.maxDelay = maxDelay;
|
||||||
|
this.bandwidthDownload = bandwidthDownload;
|
||||||
|
this.bandwidthUpload = bandwidthUpload;
|
||||||
|
this.dataSize = dataSize;
|
||||||
|
this.totalCountW = writers.length;
|
||||||
|
this.totalCountR = readers.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writerTreeConstraint() {
|
||||||
|
if (frequencySyncW > 0) {
|
||||||
|
double common = frequencySyncW * (treeNodeCountW - 1) * dataSize;
|
||||||
|
// 非叶子节点下载带宽
|
||||||
|
boolean result1 = bandwidthDownload >= common;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common / treeDegreeW;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writer2ReaderConstraint() {
|
||||||
|
double common = frequencySyncWR * totalCountW * dataSize;
|
||||||
|
// Writer根节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * rootCountR / rootCountW;
|
||||||
|
// Reader根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readerTreeConstraint() {
|
||||||
|
if (frequencySyncR > 0) {
|
||||||
|
double common = frequencySyncR * totalCountW * dataSize;
|
||||||
|
// Reader非叶子节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
|
// Reader非根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calcOptimizedResult() {
|
||||||
|
double a = 0;
|
||||||
|
if (treeHeightW > 1) {
|
||||||
|
if (treeDegreeW > 1) {
|
||||||
|
a = (treeHeightW - 1)
|
||||||
|
* (treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1)
|
||||||
|
+ (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1))
|
||||||
|
/ (treeDegreeW - 1) / (treeDegreeW - 1))
|
||||||
|
* rootCountW;
|
||||||
|
} else {
|
||||||
|
// treeDegreeW = 1
|
||||||
|
a = (treeHeightW - 1) * (treeHeightW - 1) * treeHeightW / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double b = rootCountR * totalCountW;
|
||||||
|
double c = (totalCountR - rootCountR) * (treeHeightR - 1) * totalCountW;
|
||||||
|
|
||||||
|
double A = Math.sqrt(a);
|
||||||
|
double B = Math.sqrt(b);
|
||||||
|
double C = Math.sqrt(c);
|
||||||
|
|
||||||
|
wDelay = (long) Math.ceil(maxDelay * (A / (A + B + C)));
|
||||||
|
w2rDelay = (long) Math.ceil(maxDelay * (B / (A + B + C)));
|
||||||
|
rDelay = (long) Math.ceil(maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
|
|
||||||
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
|
totalData =
|
||||||
|
(long) (dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlanningWithkExpansivity extends SharableNetworkPlanning {
|
||||||
|
Map<Integer, Map<Integer, Double>> accumulationsCache;
|
||||||
|
private final double k;
|
||||||
|
private final double domainSize;
|
||||||
|
|
||||||
|
public PlanningWithkExpansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize, double domainSize) {
|
||||||
|
this.nodeIds = nodeIds;
|
||||||
|
this.writers = writers;
|
||||||
|
this.readers = readers;
|
||||||
|
this.maxDelay = maxDelay;
|
||||||
|
this.bandwidthDownload = bandwidthDownload;
|
||||||
|
this.bandwidthUpload = bandwidthUpload;
|
||||||
|
this.dataSize = dataSize;
|
||||||
|
this.totalCountW = writers.length;
|
||||||
|
this.totalCountR = readers.length;
|
||||||
|
this.domainSize = domainSize;
|
||||||
|
this.k = (domainSize - dataSize) / domainSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writerTreeConstraint() {
|
||||||
|
if (frequencySyncW > 0) {
|
||||||
|
if (treeDegreeW > 1) {
|
||||||
|
double common = frequencySyncW * domainSize * (1 - Math.pow(k,
|
||||||
|
(Math.pow(treeDegreeW, treeHeightW - 1) - 1) / (treeDegreeW - 1)));
|
||||||
|
// 非叶子节点下载带宽
|
||||||
|
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
} else if (treeDegreeW == 1) {
|
||||||
|
double common = frequencySyncW * domainSize * (1 - Math.pow(k, treeHeightW - 1));
|
||||||
|
boolean result1 = bandwidthDownload >= common;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writer2ReaderConstraint() {
|
||||||
|
double common = frequencySyncWR * domainSize * (1 - Math.pow(k, treeNodeCountW));
|
||||||
|
// Writer根节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * rootCountR;
|
||||||
|
// Reader根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common * rootCountW;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readerTreeConstraint() {
|
||||||
|
if (frequencySyncR > 0) {
|
||||||
|
double common = frequencySyncR * domainSize * (1 - Math.pow(k, totalCountW));
|
||||||
|
// Reader非叶子节点上行带宽
|
||||||
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
|
// Reader非根节点下载带宽
|
||||||
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double calcAccumulationWithK() {
|
||||||
|
if (accumulationsCache == null) {
|
||||||
|
accumulationsCache = new HashMap<>();
|
||||||
|
}
|
||||||
|
int H1 = (int) treeHeightW;
|
||||||
|
int D1 = (int) treeDegreeW;
|
||||||
|
if (accumulationsCache.get(H1) != null && accumulationsCache.get(H1).get(D1) != null) {
|
||||||
|
return accumulationsCache.get(H1).get(D1);
|
||||||
|
}
|
||||||
|
double result = 0;
|
||||||
|
for (int h = 1; h < H1; ++h) {
|
||||||
|
result += (Math.pow(D1, h) * (1 - Math.pow(k, (Math.pow(D1, H1 - h) - 1) / (D1 - 1))));
|
||||||
|
}
|
||||||
|
accumulationsCache.computeIfAbsent(H1, k -> new HashMap<>()).put(D1, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
double calcAccumulation() {
|
||||||
|
int H1 = (int) treeHeightW;
|
||||||
|
double result = 0;
|
||||||
|
for (int h = 1; h < H1; ++h) {
|
||||||
|
result += (1 - Math.pow(k, H1 - h));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calcOptimizedResult() {
|
||||||
|
double a = 0;
|
||||||
|
if (treeDegreeW > 1) {
|
||||||
|
a = treeHeightW > 1 ? (treeHeightW - 1) * calcAccumulationWithK() * rootCountW : 0;
|
||||||
|
} else if (treeDegreeW == 1) {
|
||||||
|
a = treeHeightW > 1 ? (treeHeightW - 1) * calcAccumulation() * rootCountW : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double b = rootCountR * rootCountW * (1 - Math.pow(k, treeNodeCountW));
|
||||||
|
double c = treeHeightR > 1
|
||||||
|
? (treeHeightR - 1) * (totalCountR - rootCountR) * (1 - Math.pow(k, totalCountW))
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
double A = Math.sqrt(a);
|
||||||
|
double B = Math.sqrt(b);
|
||||||
|
double C = Math.sqrt(c);
|
||||||
|
wDelay = (long) Math.ceil(maxDelay * (A / (A + B + C)));
|
||||||
|
w2rDelay = (long) Math.ceil(maxDelay * (B / (A + B + C)));
|
||||||
|
rDelay = (long) Math.ceil(maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
|
|
||||||
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
|
totalData = (long) (domainSize
|
||||||
|
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SharableNetworkPlanning {
|
||||||
|
protected String[] nodeIds;
|
||||||
|
protected int[] writers;
|
||||||
|
protected int[] readers;
|
||||||
|
protected long maxDelay;
|
||||||
|
|
||||||
|
protected int bandwidthDownload;
|
||||||
|
protected int bandwidthUpload;
|
||||||
|
protected int dataSize;
|
||||||
|
|
||||||
|
|
||||||
|
protected long wDelay;
|
||||||
|
protected long rDelay;
|
||||||
|
protected long w2rDelay;
|
||||||
|
|
||||||
|
|
||||||
|
protected double totalCountW;
|
||||||
|
protected double rootCountW;
|
||||||
|
protected double treeNodeCountW;
|
||||||
|
protected double treeDegreeW;
|
||||||
|
protected double treeHeightW;
|
||||||
|
protected double frequencySyncW;
|
||||||
|
|
||||||
|
|
||||||
|
protected double totalCountR;
|
||||||
|
protected double rootCountR;
|
||||||
|
protected double treeNodeCountR;
|
||||||
|
protected double treeDegreeR;
|
||||||
|
protected double treeHeightR;
|
||||||
|
protected double frequencySyncR;
|
||||||
|
|
||||||
|
protected double frequencySyncWR;
|
||||||
|
|
||||||
|
protected long totalData;
|
||||||
|
|
||||||
|
protected static double logNM(double n, double m) {
|
||||||
|
return Math.log(m) / Math.log(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void adjustWriterTree(int rootCountW, int treeDegreeW) {
|
||||||
|
this.rootCountW = rootCountW;
|
||||||
|
this.treeDegreeW = treeDegreeW;
|
||||||
|
this.treeNodeCountW = Math.ceil(totalCountW / rootCountW);
|
||||||
|
if (treeDegreeW > 1) {
|
||||||
|
this.treeHeightW =
|
||||||
|
Math.ceil(logNM(treeDegreeW, treeNodeCountW * (treeDegreeW - 1) + 1));
|
||||||
|
} else {
|
||||||
|
this.treeHeightW = treeNodeCountW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void adjustReaderTree(int rootCountR, int treeDegreeR) {
|
||||||
|
this.rootCountR = rootCountR;
|
||||||
|
this.treeDegreeR = treeDegreeR;
|
||||||
|
this.treeNodeCountR = Math.ceil(totalCountR / rootCountR);
|
||||||
|
if (treeDegreeR > 1) {
|
||||||
|
this.treeHeightR =
|
||||||
|
Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
|
||||||
|
} else {
|
||||||
|
this.treeHeightR = treeNodeCountR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void adjustAndCalc() {
|
||||||
|
long minTotalData = Long.MAX_VALUE;
|
||||||
|
String result = "";
|
||||||
|
for (int rootCountW = 1; rootCountW <= writers.length; ++rootCountW) {
|
||||||
|
int nodeCountPerTree = (int) Math.ceil(writers.length * 1.0 / rootCountW);
|
||||||
|
for (int treeDegreeW = 1; treeDegreeW <= nodeCountPerTree; ++treeDegreeW) {
|
||||||
|
adjustWriterTree(rootCountW, treeDegreeW);
|
||||||
|
for (int rootCountR = 1; rootCountR <= readers.length; ++rootCountR) {
|
||||||
|
int maxTreeDegreeR = (int) Math.ceil(readers.length * 1.0 / rootCountR);
|
||||||
|
for (int treeDegreeR = 1; treeDegreeR <= maxTreeDegreeR; ++treeDegreeR) {
|
||||||
|
adjustReaderTree(rootCountR, treeDegreeR);
|
||||||
|
calcOptimizedResult();
|
||||||
|
if (!readerTreeConstraint()) {
|
||||||
|
// System.out.println("reader");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!writerTreeConstraint()) {
|
||||||
|
// System.out.println("writer");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!writer2ReaderConstraint()) {
|
||||||
|
// System.out.println("writer2Reader");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (totalData > 0 && minTotalData > totalData) {
|
||||||
|
minTotalData = totalData;
|
||||||
|
result = toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(minTotalData);
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void calcOptimizedResult() {}
|
||||||
|
|
||||||
|
protected boolean writer2ReaderConstraint() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean writerTreeConstraint() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean readerTreeConstraint() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void allocate() {
|
||||||
|
Set<Integer> writerOnlySet = new LinkedHashSet<>();
|
||||||
|
for (int i : writers) {
|
||||||
|
writerOnlySet.add(i);
|
||||||
|
}
|
||||||
|
Set<Integer> readerOnlySet = new LinkedHashSet<>();
|
||||||
|
Set<Integer> rwSet = new LinkedHashSet<>();
|
||||||
|
for (int i : readers) {
|
||||||
|
if (writerOnlySet.contains(i)) {
|
||||||
|
rwSet.add(i);
|
||||||
|
writerOnlySet.remove(i);
|
||||||
|
} else {
|
||||||
|
readerOnlySet.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int[] writerParents = allocateTreeNode(writerOnlySet, rwSet, (int) rootCountW,
|
||||||
|
(int) treeDegreeW, wDelay, (int) treeHeightW);
|
||||||
|
int[] readerParents = allocateTreeNode(readerOnlySet, rwSet, (int) rootCountR,
|
||||||
|
(int) treeDegreeR, rDelay, (int) treeHeightR);
|
||||||
|
System.out.println(readerParents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] allocateTreeNode(Set<Integer> onlySet, Set<Integer> rwSet, int rootCount,
|
||||||
|
int degree, long delay, int height) {
|
||||||
|
int[] result = new int[nodeIds.length];
|
||||||
|
long[] writerInterval = new long[nodeIds.length];
|
||||||
|
Arrays.fill(result, -2);
|
||||||
|
|
||||||
|
Map<Integer, List<Integer>> children = new HashMap<>();
|
||||||
|
Deque<Integer> notFullNodesIdx = new LinkedList<>();
|
||||||
|
for (Integer idx : onlySet) {
|
||||||
|
if (children.size() < rootCount) {
|
||||||
|
children.put(idx, new ArrayList<>());
|
||||||
|
notFullNodesIdx.add(idx);
|
||||||
|
result[idx] = -1;
|
||||||
|
} else {
|
||||||
|
int parentIdx = notFullNodesIdx.peek();
|
||||||
|
children.computeIfAbsent(parentIdx, k -> new ArrayList<>()).add(idx);
|
||||||
|
notFullNodesIdx.addLast(idx);
|
||||||
|
if (children.get(parentIdx).size() >= degree) {
|
||||||
|
notFullNodesIdx.pop();
|
||||||
|
}
|
||||||
|
writerInterval[idx] = delay / (height - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读写节点放在尽量靠近叶子节点,以便带宽的平衡
|
||||||
|
for (Integer idx : rwSet) {
|
||||||
|
if (children.size() < rootCount) {
|
||||||
|
children.put(idx, new ArrayList<>());
|
||||||
|
notFullNodesIdx.add(idx);
|
||||||
|
result[idx] = -1;
|
||||||
|
} else {
|
||||||
|
int parentIdx = notFullNodesIdx.peek();
|
||||||
|
children.computeIfAbsent(parentIdx, k -> new ArrayList<>()).add(idx);
|
||||||
|
notFullNodesIdx.addLast(idx);
|
||||||
|
if (children.get(parentIdx).size() >= degree) {
|
||||||
|
notFullNodesIdx.pop();
|
||||||
|
}
|
||||||
|
writerInterval[idx] = delay / (height - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Integer parentId : children.keySet()) {
|
||||||
|
for (int childId : children.get(parentId)) {
|
||||||
|
result[childId] = parentId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String result = "[" + wDelay + "," + w2rDelay + "," + rDelay + "]\n"
|
||||||
|
+ "writer tree: degree " + treeDegreeW + ", count " + rootCountW + ",\n"
|
||||||
|
+ "reader tree: degree " + treeDegreeR + ", count " + rootCountR;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/java/org/bdware/sc/crdt/proxy/AWORSetProxy.java
Normal file
38
src/main/java/org/bdware/sc/crdt/proxy/AWORSetProxy.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.set.AWORSet;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class AWORSetProxy extends SharableVar<AWORSet<Object>> {
|
||||||
|
public AWORSetProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
AWORSet<Object> delta = writerVar.add(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
AWORSet<Object> delta = writerVar.remove(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AWORSet<Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new AWORSet<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/main/java/org/bdware/sc/crdt/proxy/DWFlagProxy.java
Normal file
36
src/main/java/org/bdware/sc/crdt/proxy/DWFlagProxy.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.flag.DWFlag;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
public class DWFlagProxy extends SharableVar<DWFlag> {
|
||||||
|
public DWFlagProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enable() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
DWFlag delta = writerVar.enable();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
DWFlag delta = writerVar.disable();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DWFlag createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new DWFlag(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/main/java/org/bdware/sc/crdt/proxy/EWFlagProxy.java
Normal file
36
src/main/java/org/bdware/sc/crdt/proxy/EWFlagProxy.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.flag.EWFlag;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
public class EWFlagProxy extends SharableVar<EWFlag> {
|
||||||
|
public EWFlagProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enable() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
EWFlag delta = writerVar.enable();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
EWFlag delta = writerVar.disable();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EWFlag createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new EWFlag(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/main/java/org/bdware/sc/crdt/proxy/GCounterProxy.java
Normal file
47
src/main/java/org/bdware/sc/crdt/proxy/GCounterProxy.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.counter.GCounter;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GCounterProxy extends SharableVar<GCounter> {
|
||||||
|
|
||||||
|
public GCounterProxy(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inc() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
GCounter delta = writerVar.inc();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inc(long var) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
GCounter delta = writerVar.inc(var);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Long> getM() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.getM();
|
||||||
|
}
|
||||||
|
return writerVar.getM();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GCounter createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new GCounter(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/main/java/org/bdware/sc/crdt/proxy/GSetProxy.java
Normal file
31
src/main/java/org/bdware/sc/crdt/proxy/GSetProxy.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.set.GSet;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class GSetProxy extends SharableVar<GSet<Object>> {
|
||||||
|
public GSetProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
GSet<Object> delta = writerVar.add(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GSet<Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new GSet<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/main/java/org/bdware/sc/crdt/proxy/LWWRegisterProxy.java
Normal file
30
src/main/java/org/bdware/sc/crdt/proxy/LWWRegisterProxy.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.register.LWWRegister;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
public class LWWRegisterProxy extends SharableVar<LWWRegister<Long, Object>> {
|
||||||
|
public LWWRegisterProxy(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
LWWRegister<Long, Object> delta = writerVar.write(System.currentTimeMillis(), val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LWWRegister<Long, Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new LWWRegister<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/main/java/org/bdware/sc/crdt/proxy/MVRegisterProxy.java
Normal file
36
src/main/java/org/bdware/sc/crdt/proxy/MVRegisterProxy.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.register.MVRegister;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
public class MVRegisterProxy extends SharableVar<MVRegister<Object>> {
|
||||||
|
|
||||||
|
public MVRegisterProxy(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
MVRegister<Object> delta = writerVar.write(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolve(Object val) {
|
||||||
|
MVRegister<Object> delta = writerVar.resolve();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MVRegister<Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new MVRegister<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/main/java/org/bdware/sc/crdt/proxy/PNCounterProxy.java
Normal file
51
src/main/java/org/bdware/sc/crdt/proxy/PNCounterProxy.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.counter.PNCounter;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
public class PNCounterProxy extends SharableVar<PNCounter> {
|
||||||
|
public PNCounterProxy(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inc() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
PNCounter delta = writerVar.inc();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inc(long val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
PNCounter delta = writerVar.inc(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dec() {
|
||||||
|
if (writerVar != null) {
|
||||||
|
PNCounter delta = writerVar.dec();
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dec(long val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
PNCounter delta = writerVar.dec(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PNCounter createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new PNCounter(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/org/bdware/sc/crdt/proxy/RWLWWSetProxy.java
Normal file
39
src/main/java/org/bdware/sc/crdt/proxy/RWLWWSetProxy.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.set.RWLWWSet;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class RWLWWSetProxy extends SharableVar<RWLWWSet<Long, Object>> {
|
||||||
|
public RWLWWSetProxy(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
RWLWWSet<Long, Object> delta = writerVar.add(System.currentTimeMillis(), val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
RWLWWSet<Long, Object> delta = writerVar.remove(System.currentTimeMillis(), val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RWLWWSet<Long, Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new RWLWWSet<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/java/org/bdware/sc/crdt/proxy/RWORSetProxy.java
Normal file
38
src/main/java/org/bdware/sc/crdt/proxy/RWORSetProxy.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.set.RWORSet;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class RWORSetProxy extends SharableVar<RWORSet<Object>> {
|
||||||
|
public RWORSetProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
RWORSet<Object> delta = writerVar.add(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
RWORSet<Object> delta = writerVar.remove(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RWORSet<Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new RWORSet<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
146
src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java
Normal file
146
src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import io.netty.util.HashedWheelTimer;
|
||||||
|
import io.netty.util.Timeout;
|
||||||
|
import io.netty.util.TimerTask;
|
||||||
|
import org.bdware.crdt.basic.JoinableCRDT;
|
||||||
|
import org.bdware.sc.crdt.SharableVarManager;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public abstract class SharableVar<T extends JoinableCRDT> {
|
||||||
|
// 用于writer节点的变量副本
|
||||||
|
public T writerVar;
|
||||||
|
// 用于reader节点的变量副本
|
||||||
|
public T readerVar;
|
||||||
|
|
||||||
|
public Queue<JoinableCRDT> writerVarDeltaQueue;
|
||||||
|
public Queue<JoinableCRDT> readerVarDeltaQueue;
|
||||||
|
|
||||||
|
public String varId;
|
||||||
|
public SharableVarState sharableVarState;
|
||||||
|
|
||||||
|
public HashedWheelTimer readerTimer;
|
||||||
|
public ReaderSyncTimerTask readerSyncTimerTask;
|
||||||
|
public HashedWheelTimer writerTimer;
|
||||||
|
public WriterSyncTimerTask writerSyncTimerTask;
|
||||||
|
|
||||||
|
public SharableVar(String varId, String cpId,
|
||||||
|
SharableVarState.SharableVarConfiguration resolveResult) {
|
||||||
|
this.varId = varId;
|
||||||
|
this.sharableVarState = new SharableVarState(cpId, resolveResult);
|
||||||
|
|
||||||
|
if (this.sharableVarState.isReaderFlag()) {
|
||||||
|
this.readerVar = createDeltaCrdt(cpId, varId);
|
||||||
|
this.readerVarDeltaQueue = new LinkedList<>();
|
||||||
|
if (this.sharableVarState.getReaderChildren() != null
|
||||||
|
&& this.sharableVarState.getReaderChildren().size() > 0
|
||||||
|
&& this.sharableVarState.getReaderInterval() != null
|
||||||
|
&& this.sharableVarState.getReaderInterval() > 0) {
|
||||||
|
this.readerTimer = new HashedWheelTimer(r -> {
|
||||||
|
Thread t = Executors.defaultThreadFactory().newThread(r);
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
}, 5, TimeUnit.MILLISECONDS, 2);
|
||||||
|
this.readerTimer.newTimeout(timeout -> {
|
||||||
|
readerSyncTimerTask = new ReaderSyncTimerTask();
|
||||||
|
readerTimer.newTimeout(readerSyncTimerTask,
|
||||||
|
sharableVarState.getReaderInterval(), TimeUnit.SECONDS);
|
||||||
|
}, this.sharableVarState.getReaderInterval(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.sharableVarState.isWriterFlag()) {
|
||||||
|
this.writerVar = createDeltaCrdt(cpId, varId);
|
||||||
|
this.writerVarDeltaQueue = new LinkedList<>();
|
||||||
|
if (this.sharableVarState.getWriteInterval() != null
|
||||||
|
&& this.sharableVarState.getWriteInterval() > 0) {
|
||||||
|
this.writerTimer = new HashedWheelTimer(r -> {
|
||||||
|
Thread t = Executors.defaultThreadFactory().newThread(r);
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
}, 5, TimeUnit.MILLISECONDS, 2);
|
||||||
|
this.writerTimer.newTimeout(timeout -> {
|
||||||
|
writerSyncTimerTask = new WriterSyncTimerTask();
|
||||||
|
writerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(),
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}, this.sharableVarState.getWriteInterval(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncReaderVar() {
|
||||||
|
if (readerVarDeltaQueue.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JoinableCRDT joinedDelta = createDeltaCrdt(null, varId);
|
||||||
|
synchronized (readerVarDeltaQueue) {
|
||||||
|
while (!readerVarDeltaQueue.isEmpty()) {
|
||||||
|
JoinableCRDT delta = readerVarDeltaQueue.poll();
|
||||||
|
joinedDelta.join(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String content = JsonUtil.toJson(joinedDelta);
|
||||||
|
SharableVarManager.instance.broadcastSyncMessage(varId,
|
||||||
|
sharableVarState.getReaderChildren(), content, "r2r");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncWriterVar() {
|
||||||
|
if (writerVarDeltaQueue.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JoinableCRDT joinedDelta = createDeltaCrdt(null, varId);
|
||||||
|
synchronized (writerVarDeltaQueue) {
|
||||||
|
while (!writerVarDeltaQueue.isEmpty()) {
|
||||||
|
JoinableCRDT delta = writerVarDeltaQueue.poll();
|
||||||
|
joinedDelta.join(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String content = JsonUtil.toJson(joinedDelta);
|
||||||
|
if (sharableVarState.getWriterParent() != null) {
|
||||||
|
// 父节点是Writer
|
||||||
|
SharableVarManager.instance.broadcastSyncMessage(varId,
|
||||||
|
Collections.singletonList(sharableVarState.getWriterParent()), content, "w2w");
|
||||||
|
} else if (sharableVarState.getReaderRoots() != null) {
|
||||||
|
// 自己是writer根结点 向reader根结点们广播
|
||||||
|
SharableVarManager.instance.broadcastSyncMessage(varId,
|
||||||
|
sharableVarState.getReaderRoots(), content, "w2r");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected T createDeltaCrdt(String nodeId, String varId);
|
||||||
|
|
||||||
|
class ReaderSyncTimerTask implements TimerTask {
|
||||||
|
@Override
|
||||||
|
public void run(Timeout timeout) throws Exception {
|
||||||
|
try {
|
||||||
|
syncReaderVar();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
readerTimer.newTimeout(readerSyncTimerTask, sharableVarState.getReaderInterval(),
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WriterSyncTimerTask implements TimerTask {
|
||||||
|
@Override
|
||||||
|
public void run(Timeout timeout) throws Exception {
|
||||||
|
try {
|
||||||
|
syncWriterVar();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
writerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(),
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/java/org/bdware/sc/crdt/proxy/TPSetProxy.java
Normal file
38
src/main/java/org/bdware/sc/crdt/proxy/TPSetProxy.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package org.bdware.sc.crdt.proxy;
|
||||||
|
|
||||||
|
import org.bdware.crdt.set.TPSet;
|
||||||
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class TPSetProxy extends SharableVar<TPSet<Object>> {
|
||||||
|
public TPSetProxy(String varId, String cpId, SharableVarState.SharableVarConfiguration conf) {
|
||||||
|
super(varId, cpId, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
TPSet<Object> delta = writerVar.add(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Object val) {
|
||||||
|
if (writerVar != null) {
|
||||||
|
TPSet<Object> delta = writerVar.remove(val);
|
||||||
|
writerVarDeltaQueue.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> read() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.read();
|
||||||
|
}
|
||||||
|
return writerVar.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TPSet<Object> createDeltaCrdt(String nodeId, String varId) {
|
||||||
|
return new TPSet<>(nodeId, varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,23 +23,26 @@ public class ConfidentialContractUtil {
|
|||||||
|
|
||||||
public static final String CONFIDENTIAL_TEMPLATE_PATH = System.getenv("GRAPHENE_DIR")
|
public static final String CONFIDENTIAL_TEMPLATE_PATH = System.getenv("GRAPHENE_DIR")
|
||||||
+ File.separator + "Examples" + File.separator + "nodejs-secret";
|
+ File.separator + "Examples" + File.separator + "nodejs-secret";
|
||||||
public static final String CONFIDENTIAL_SCRIPT_PATH = System.getenv("GRAPHENE_DIR")
|
public static final String CONFIDENTIAL_SCRIPT_PATH =
|
||||||
+ File.separator + "App";
|
System.getenv("GRAPHENE_DIR") + File.separator + "App";
|
||||||
public static final String[] COMMAND = {"bash", "executeContract.sh"};
|
public static final String[] COMMAND = {"bash", "executeContract.sh"};
|
||||||
private static final Type MapType = TypeToken.getParameterized(HashMap.class, String.class, String.class).getType();
|
private static final Type MapType =
|
||||||
|
TypeToken.getParameterized(HashMap.class, String.class, String.class).getType();
|
||||||
|
|
||||||
public static String executeConfidentialContract(ContractRequest input) throws IOException, InterruptedException {
|
public static String executeConfidentialContract(ContractRequest input)
|
||||||
|
throws IOException, InterruptedException {
|
||||||
File runDir = new File(CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID());
|
File runDir = new File(CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID());
|
||||||
ProcessBuilder pb = new ProcessBuilder(COMMAND);
|
ProcessBuilder pb = new ProcessBuilder(COMMAND);
|
||||||
pb.directory(runDir);
|
pb.directory(runDir);
|
||||||
Process p = pb.start();
|
Process p = pb.start();
|
||||||
p.waitFor();
|
p.waitFor();
|
||||||
File resultFile = new File(CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID() +
|
File resultFile = new File(CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID()
|
||||||
File.separator + "result.json");
|
+ File.separator + "result.json");
|
||||||
return FileUtils.readFileToString(resultFile, StandardCharsets.UTF_8);
|
return FileUtils.readFileToString(resultFile, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateConfidentialContract(ContractNode cn, ScriptObjectMirror globalVars, Global global) {
|
public static void generateConfidentialContract(ContractNode cn, ScriptObjectMirror globalVars,
|
||||||
|
Global global) {
|
||||||
List<FunctionNode> functionNodes = cn.getFunctions();
|
List<FunctionNode> functionNodes = cn.getFunctions();
|
||||||
for (FunctionNode fn : functionNodes) {
|
for (FunctionNode fn : functionNodes) {
|
||||||
// assuming only one confidential function for now
|
// assuming only one confidential function for now
|
||||||
@@ -54,18 +57,46 @@ public class ConfidentialContractUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// load necessary Node.js libraries
|
// load necessary Node.js libraries
|
||||||
jsStr.append("var fs = require('fs');\n" + "var crypto = require('crypto');\n" + "var sm2 = require('sm-crypto').sm2;\n");
|
jsStr.append("var fs = require('fs');\n" + "var crypto = require('crypto');\n"
|
||||||
|
+ "var sm2 = require('sm-crypto').sm2;\n");
|
||||||
// load Global variables and arguments from files
|
// load Global variables and arguments from files
|
||||||
jsStr.append("let rawGlobal = fs.readFileSync('global.json').toString();\n" + "let Global = JSON.parse(rawGlobal);\n");
|
jsStr.append("let rawGlobal = fs.readFileSync('global.json').toString();\n"
|
||||||
jsStr.append("let rawArg = fs.readFileSync('arg.json').toString();\n" + "let jsonArg = JSON.parse(rawArg);\n" + "let requester = jsonArg.requester;\n" + "let arg = jsonArg.arg;\n");
|
+ "let Global = JSON.parse(rawGlobal);\n");
|
||||||
|
jsStr.append("let rawArg = fs.readFileSync('arg.json').toString();\n"
|
||||||
|
+ "let jsonArg = JSON.parse(rawArg);\n"
|
||||||
|
+ "let requester = jsonArg.requester;\n" + "let arg = jsonArg.arg;\n");
|
||||||
jsStr.append("let srcStr = fs.readFileSync('contract.js').toString();\n");
|
jsStr.append("let srcStr = fs.readFileSync('contract.js').toString();\n");
|
||||||
// verify signatures and decrypt all confidential variables Important!!!!!
|
// verify signatures and decrypt all confidential variables Important!!!!!
|
||||||
jsStr.append("for (var k in Global) {\n" + " if (Global.hasOwnProperty(k)) {\n" + " if (k.startsWith('conf_')) {\n" + " let sig = Global[k].signature;\n" + " let pubKey = Global[k].owner;\n" + " let verifyResult = sm2.doVerifySignature(srcStr, sig, pubKey);\n" + " if (verifyResult) {\n" + " let newKey = k.substring(5);\n" + " let decKey = Buffer.from(process.env['KEY_'+pubKey.substring(0,10).toUpperCase()], 'hex');\n" + " let decIv = Buffer.from(Global[k].iv, 'hex');\n" + " let cipherText = Buffer.from(Global[k].cipherText, 'hex');\n" + " let decipher = crypto.createDecipheriv('aes-256-cbc', decKey, decIv);\n" + " let decrypted = decipher.update(cipherText);\n" + " decrypted = Buffer.concat([decrypted, decipher.final()]);\n" + " let plaintext = decrypted.toString();\n" + " Global[newKey] = plaintext;\n" + " }\n" + " }\n" + " }\n" + "}\n");
|
jsStr.append("for (var k in Global) {\n" + " if (Global.hasOwnProperty(k)) {\n"
|
||||||
|
+ " if (k.startsWith('conf_')) {\n"
|
||||||
|
+ " let sig = Global[k].signature;\n"
|
||||||
|
+ " let pubKey = Global[k].owner;\n"
|
||||||
|
+ " let verifyResult = sm2.doVerifySignature(srcStr, sig, pubKey);\n"
|
||||||
|
+ " if (verifyResult) {\n" + " let newKey = k.substring(5);\n"
|
||||||
|
+ " let decKey = Buffer.from(process.env['KEY_'+pubKey.substring(0,10).toUpperCase()], 'hex');\n"
|
||||||
|
+ " let decIv = Buffer.from(Global[k].iv, 'hex');\n"
|
||||||
|
+ " let cipherText = Buffer.from(Global[k].cipherText, 'hex');\n"
|
||||||
|
+ " let decipher = crypto.createDecipheriv('aes-256-cbc', decKey, decIv);\n"
|
||||||
|
+ " let decrypted = decipher.update(cipherText);\n"
|
||||||
|
+ " decrypted = Buffer.concat([decrypted, decipher.final()]);\n"
|
||||||
|
+ " let plaintext = decrypted.toString();\n"
|
||||||
|
+ " Global[newKey] = plaintext;\n" + " }\n" + " }\n"
|
||||||
|
+ " }\n" + "}\n");
|
||||||
// call function
|
// call function
|
||||||
jsStr.append("var ret = ").append(fn.functionName).append("(arg, requester, null);\n");
|
jsStr.append("var ret = ").append(fn.functionName)
|
||||||
// TODO: encrypt all confidential variables so state can be updated in confidential function @shujunyi
|
.append("(arg, requester, null);\n");
|
||||||
|
// TODO: encrypt all confidential variables so state can be updated in confidential
|
||||||
|
// function @shujunyi
|
||||||
// encrypt return value and write to a file
|
// encrypt return value and write to a file
|
||||||
jsStr.append("var retStr = JSON.stringify(ret);\n" + "var key = Buffer.from(process.env['KEY_'+requester.substring(0,10).toUpperCase()], 'hex');\n" + "var iv = crypto.randomBytes(16);\n" + "let cipher = crypto.createCipheriv('aes-256-cbc', key, iv); \n" + "let encRet = cipher.update(retStr);\n" + "encRet = Buffer.concat([encRet, cipher.final()]);\n" + "let result = {iv: iv.toString('hex'), encryptedData: encRet.toString('hex')};\n" + "let resultStr = JSON.stringify(result);\n" + "fs.writeFileSync('result.json', resultStr);\n");
|
jsStr.append("var retStr = JSON.stringify(ret);\n"
|
||||||
|
+ "var key = Buffer.from(process.env['KEY_'+requester.substring(0,10).toUpperCase()], 'hex');\n"
|
||||||
|
+ "var iv = crypto.randomBytes(16);\n"
|
||||||
|
+ "let cipher = crypto.createCipheriv('aes-256-cbc', key, iv); \n"
|
||||||
|
+ "let encRet = cipher.update(retStr);\n"
|
||||||
|
+ "encRet = Buffer.concat([encRet, cipher.final()]);\n"
|
||||||
|
+ "let result = {iv: iv.toString('hex'), encryptedData: encRet.toString('hex')};\n"
|
||||||
|
+ "let resultStr = JSON.stringify(result);\n"
|
||||||
|
+ "fs.writeFileSync('result.json', resultStr);\n");
|
||||||
// put script into Global so owner can send it and collect signatures
|
// put script into Global so owner can send it and collect signatures
|
||||||
Object som = ScriptObjectMirror.wrap(jsStr.toString(), global);
|
Object som = ScriptObjectMirror.wrap(jsStr.toString(), global);
|
||||||
globalVars.put("src_" + fn.functionName, som);
|
globalVars.put("src_" + fn.functionName, som);
|
||||||
@@ -85,11 +116,8 @@ public class ConfidentialContractUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dumpScriptAndStates(
|
public static void dumpScriptAndStates(Invocable engine, FunctionNode functionNode,
|
||||||
Invocable engine,
|
ContractRequest input, ScriptObjectMirror globalVars)
|
||||||
FunctionNode functionNode,
|
|
||||||
ContractRequest input,
|
|
||||||
ScriptObjectMirror globalVars)
|
|
||||||
throws IOException, ScriptException, NoSuchMethodException {
|
throws IOException, ScriptException, NoSuchMethodException {
|
||||||
Map<String, Object> globalMap = (Map<String, Object>) convertIntoJavaObject(globalVars);
|
Map<String, Object> globalMap = (Map<String, Object>) convertIntoJavaObject(globalVars);
|
||||||
String dest = CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID();
|
String dest = CONFIDENTIAL_SCRIPT_PATH + File.separator + input.getRequestID();
|
||||||
@@ -136,156 +164,116 @@ public class ConfidentialContractUtil {
|
|||||||
return dependentFunctions;
|
return dependentFunctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateGrapheneManifestStr(Invocable engine, ContractRequest input) throws ScriptException, NoSuchMethodException {
|
private static String generateGrapheneManifestStr(Invocable engine, ContractRequest input)
|
||||||
String manifestStr = "# Nodejs manifest file example\n" +
|
throws ScriptException, NoSuchMethodException {
|
||||||
"#\n" +
|
String manifestStr = "# Nodejs manifest file example\n" + "#\n"
|
||||||
"# This manifest was prepared and tested on Ubuntu 18.04.\n" +
|
+ "# This manifest was prepared and tested on Ubuntu 18.04.\n" + "\n"
|
||||||
"\n" +
|
+ "loader.argv0_override = \"nodejs\"\n" + "\n"
|
||||||
"loader.argv0_override = \"nodejs\"\n" +
|
+ "# LibOS layer library of Graphene. There is currently only one implementation,\n"
|
||||||
"\n" +
|
+ "# so it is always set to libsysdb.so.\n"
|
||||||
"# LibOS layer library of Graphene. There is currently only one implementation,\n" +
|
+ "loader.preload = \"file:$(GRAPHENEDIR)/Runtime/libsysdb.so\"\n" + "\n"
|
||||||
"# so it is always set to libsysdb.so.\n" +
|
+ "# Show/hide debug log of Graphene ('inline' or 'none' respectively).\n"
|
||||||
"loader.preload = \"file:$(GRAPHENEDIR)/Runtime/libsysdb.so\"\n" +
|
+ "loader.debug_type = \"$(GRAPHENEDEBUG)\"\n" + "\n"
|
||||||
"\n" +
|
+ "# Read application arguments directly from the command line. Don't use this on production!\n"
|
||||||
"# Show/hide debug log of Graphene ('inline' or 'none' respectively).\n" +
|
+ "loader.insecure__use_cmdline_argv = 1\n" + "\n"
|
||||||
"loader.debug_type = \"$(GRAPHENEDEBUG)\"\n" +
|
+ "# Specify paths to search for libraries. The usual LD_LIBRARY_PATH syntax\n"
|
||||||
"\n" +
|
+ "# applies. Paths must be in-Graphene visible paths, not host-OS paths (i.e.,\n"
|
||||||
"# Read application arguments directly from the command line. Don't use this on production!\n" +
|
+ "# paths must be taken from fs.mount.xxx.path, not fs.mount.xxx.uri).\n"
|
||||||
"loader.insecure__use_cmdline_argv = 1\n" +
|
+ "loader.env.LD_LIBRARY_PATH = \"/lib:/usr/lib:$(ARCH_LIBDIR):/usr/$(ARCH_LIBDIR):./\"\n"
|
||||||
"\n" +
|
+ "\n"
|
||||||
"# Specify paths to search for libraries. The usual LD_LIBRARY_PATH syntax\n" +
|
+ "# Mount host-OS directory to required libraries (in 'uri') into in-Graphene\n"
|
||||||
"# applies. Paths must be in-Graphene visible paths, not host-OS paths (i.e.,\n" +
|
+ "# visible directory /lib (in 'path').\n" + "fs.mount.lib.type = \"chroot\"\n"
|
||||||
"# paths must be taken from fs.mount.xxx.path, not fs.mount.xxx.uri).\n" +
|
+ "fs.mount.lib.path = \"/lib\"\n"
|
||||||
"loader.env.LD_LIBRARY_PATH = \"/lib:/usr/lib:$(ARCH_LIBDIR):/usr/$(ARCH_LIBDIR):./\"\n" +
|
+ "fs.mount.lib.uri = \"file:$(GRAPHENEDIR)/Runtime\"\n" + "\n"
|
||||||
"\n" +
|
+ "fs.mount.lib2.type = \"chroot\"\n" + "fs.mount.lib2.path = \"$(ARCH_LIBDIR)\"\n"
|
||||||
"# Mount host-OS directory to required libraries (in 'uri') into in-Graphene\n" +
|
+ "fs.mount.lib2.uri = \"file:$(ARCH_LIBDIR)\"\n" + "\n"
|
||||||
"# visible directory /lib (in 'path').\n" +
|
+ "#fs.mount.lib3.type = \"chroot\"\n"
|
||||||
"fs.mount.lib.type = \"chroot\"\n" +
|
+ "#fs.mount.lib3.path = \"/usr/$(ARCH_LIBDIR)\"\n"
|
||||||
"fs.mount.lib.path = \"/lib\"\n" +
|
+ "#fs.mount.lib3.uri = \"file:/usr/$(ARCH_LIBDIR)\"\n" + "\n"
|
||||||
"fs.mount.lib.uri = \"file:$(GRAPHENEDIR)/Runtime\"\n" +
|
+ "fs.mount.usr.type = \"chroot\"\n" + "fs.mount.usr.path = \"/usr\"\n"
|
||||||
"\n" +
|
+ "fs.mount.usr.uri = \"file:/usr\"\n" + "\n"
|
||||||
"fs.mount.lib2.type = \"chroot\"\n" +
|
+ "# Host-level directory to NSS files required by Glibc + NSS libs\n"
|
||||||
"fs.mount.lib2.path = \"$(ARCH_LIBDIR)\"\n" +
|
+ "fs.mount.etc.type = \"chroot\"\n" + "fs.mount.etc.path = \"/etc\"\n"
|
||||||
"fs.mount.lib2.uri = \"file:$(ARCH_LIBDIR)\"\n" +
|
+ "fs.mount.etc.uri = \"file:/etc\"\n" + "\n"
|
||||||
"\n" +
|
+ "# Workload needs to create temporary files\n"
|
||||||
"#fs.mount.lib3.type = \"chroot\"\n" +
|
+ "fs.mount.tmp.type = \"chroot\"\n" + "fs.mount.tmp.path = \"/tmp\"\n"
|
||||||
"#fs.mount.lib3.path = \"/usr/$(ARCH_LIBDIR)\"\n" +
|
+ "fs.mount.tmp.uri = \"file:/tmp\"\n" + "\n"
|
||||||
"#fs.mount.lib3.uri = \"file:/usr/$(ARCH_LIBDIR)\"\n" +
|
+ "# Set enclave size to 2GB; NodeJS expects around 1.7GB of heap on startup,\n"
|
||||||
"\n" +
|
+ "# see e.g. https://github.com/nodejs/node/issues/13018.\n"
|
||||||
"fs.mount.usr.type = \"chroot\"\n" +
|
+ "# Recall that SGX v1 requires to specify enclave size at enclave creation time.\n"
|
||||||
"fs.mount.usr.path = \"/usr\"\n" +
|
+ "sgx.enclave_size = \"2G\"\n" + "\n"
|
||||||
"fs.mount.usr.uri = \"file:/usr\"\n" +
|
+ "# Set maximum number of in-enclave threads (somewhat arbitrarily) to 8. Recall\n"
|
||||||
"\n" +
|
+ "# that SGX v1 requires to specify the maximum number of simultaneous threads at\n"
|
||||||
"# Host-level directory to NSS files required by Glibc + NSS libs\n" +
|
+ "# enclave creation time.\n" + "sgx.thread_num = 16\n" + "\n"
|
||||||
"fs.mount.etc.type = \"chroot\"\n" +
|
+ "# Specify all libraries used by Node.js and its dependencies (including all libs\n"
|
||||||
"fs.mount.etc.path = \"/etc\"\n" +
|
+ "# which can be loaded at runtime via dlopen).\n"
|
||||||
"fs.mount.etc.uri = \"file:/etc\"\n" +
|
+ "sgx.trusted_files.ld = \"file:$(GRAPHENEDIR)/Runtime/ld-linux-x86-64.so.2\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libc = \"file:$(GRAPHENEDIR)/Runtime/libc.so.6\"\n"
|
||||||
"# Workload needs to create temporary files\n" +
|
+ "sgx.trusted_files.libm = \"file:$(GRAPHENEDIR)/Runtime/libm.so.6\"\n"
|
||||||
"fs.mount.tmp.type = \"chroot\"\n" +
|
+ "sgx.trusted_files.libdl = \"file:$(GRAPHENEDIR)/Runtime/libdl.so.2\"\n"
|
||||||
"fs.mount.tmp.path = \"/tmp\"\n" +
|
+ "sgx.trusted_files.librt = \"file:$(GRAPHENEDIR)/Runtime/librt.so.1\"\n"
|
||||||
"fs.mount.tmp.uri = \"file:/tmp\"\n" +
|
+ "sgx.trusted_files.libutil = \"file:$(GRAPHENEDIR)/Runtime/libutil.so.1\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libpthread = \"file:$(GRAPHENEDIR)/Runtime/libpthread.so.0\"\n"
|
||||||
"# Set enclave size to 2GB; NodeJS expects around 1.7GB of heap on startup,\n" +
|
+ "sgx.trusted_files.libnssdns = \"file:$(GRAPHENEDIR)/Runtime/libnss_dns.so.2\"\n"
|
||||||
"# see e.g. https://github.com/nodejs/node/issues/13018.\n" +
|
+ "sgx.trusted_files.libresolv = \"file:$(GRAPHENEDIR)/Runtime/libresolv.so.2\"\n"
|
||||||
"# Recall that SGX v1 requires to specify enclave size at enclave creation time.\n" +
|
+ "\n" + "sgx.trusted_files.libstdc = \"file:/usr/$(ARCH_LIBDIR)/libstdc++.so.6\"\n"
|
||||||
"sgx.enclave_size = \"2G\"\n" +
|
+ "sgx.trusted_files.libgccs = \"file:$(ARCH_LIBDIR)/libgcc_s.so.1\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libaptpkg = \"file:/usr/$(ARCH_LIBDIR)/libapt-pkg.so.5.0\"\n"
|
||||||
"# Set maximum number of in-enclave threads (somewhat arbitrarily) to 8. Recall\n" +
|
+ "sgx.trusted_files.liblz4 = \"file:/usr/$(ARCH_LIBDIR)/liblz4.so.1\"\n"
|
||||||
"# that SGX v1 requires to specify the maximum number of simultaneous threads at\n" +
|
+ "sgx.trusted_files.libsystemd = \"file:$(ARCH_LIBDIR)/libsystemd.so.0\"\n"
|
||||||
"# enclave creation time.\n" +
|
+ "sgx.trusted_files.libselinux = \"file:$(ARCH_LIBDIR)/libselinux.so.1\"\n"
|
||||||
"sgx.thread_num = 16\n" +
|
+ "sgx.trusted_files.libgcrypt = \"file:$(ARCH_LIBDIR)/libgcrypt.so.20\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libpcre = \"file:$(ARCH_LIBDIR)/libpcre.so.3\"\n"
|
||||||
"# Specify all libraries used by Node.js and its dependencies (including all libs\n" +
|
+ "sgx.trusted_files.libgpgerror = \"file:$(ARCH_LIBDIR)/libgpg-error.so.0\"\n"
|
||||||
"# which can be loaded at runtime via dlopen).\n" +
|
+ "sgx.trusted_files.libexpat = \"file:$(ARCH_LIBDIR)/libexpat.so.1\"\n"
|
||||||
"sgx.trusted_files.ld = \"file:$(GRAPHENEDIR)/Runtime/ld-linux-x86-64.so.2\"\n" +
|
+ "sgx.trusted_files.libz = \"file:$(ARCH_LIBDIR)/libz.so.1\"\n"
|
||||||
"sgx.trusted_files.libc = \"file:$(GRAPHENEDIR)/Runtime/libc.so.6\"\n" +
|
+ "sgx.trusted_files.libz2 = \"file:$(ARCH_LIBDIR)/libbz2.so.1.0\"\n"
|
||||||
"sgx.trusted_files.libm = \"file:$(GRAPHENEDIR)/Runtime/libm.so.6\"\n" +
|
+ "sgx.trusted_files.liblzma = \"file:$(ARCH_LIBDIR)/liblzma.so.5\"\n"
|
||||||
"sgx.trusted_files.libdl = \"file:$(GRAPHENEDIR)/Runtime/libdl.so.2\"\n" +
|
+ "sgx.trusted_files.libmpdec = \"file:/usr/$(ARCH_LIBDIR)/libmpdec.so.2\"\n" + "\n"
|
||||||
"sgx.trusted_files.librt = \"file:$(GRAPHENEDIR)/Runtime/librt.so.1\"\n" +
|
+ "# Name Service Switch (NSS) libraries (Glibc dependencies)\n"
|
||||||
"sgx.trusted_files.libutil = \"file:$(GRAPHENEDIR)/Runtime/libutil.so.1\"\n" +
|
+ "sgx.trusted_files.libnssfiles = \"file:$(ARCH_LIBDIR)/libnss_files.so.2\"\n"
|
||||||
"sgx.trusted_files.libpthread = \"file:$(GRAPHENEDIR)/Runtime/libpthread.so.0\"\n" +
|
+ "sgx.trusted_files.libnsscompat = \"file:$(ARCH_LIBDIR)/libnss_compat.so.2\"\n"
|
||||||
"sgx.trusted_files.libnssdns = \"file:$(GRAPHENEDIR)/Runtime/libnss_dns.so.2\"\n" +
|
+ "sgx.trusted_files.libnssnis = \"file:$(ARCH_LIBDIR)/libnss_nis.so.2\"\n"
|
||||||
"sgx.trusted_files.libresolv = \"file:$(GRAPHENEDIR)/Runtime/libresolv.so.2\"\n" +
|
+ "sgx.trusted_files.libnsl = \"file:$(ARCH_LIBDIR)/libnsl.so.1\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libnssmyhostname = \"file:$(ARCH_LIBDIR)/libnss_myhostname.so.2\"\n"
|
||||||
"sgx.trusted_files.libstdc = \"file:/usr/$(ARCH_LIBDIR)/libstdc++.so.6\"\n" +
|
+ "sgx.trusted_files.libnssmdns = \"file:$(ARCH_LIBDIR)/libnss_mdns4_minimal.so.2\"\n"
|
||||||
"sgx.trusted_files.libgccs = \"file:$(ARCH_LIBDIR)/libgcc_s.so.1\"\n" +
|
+ "\n" + "# Scratch space\n" + "sgx.allowed_files.tmp = \"file:/tmp\"\n" + "\n"
|
||||||
"sgx.trusted_files.libaptpkg = \"file:/usr/$(ARCH_LIBDIR)/libapt-pkg.so.5.0\"\n" +
|
+ "# APT config files\n"
|
||||||
"sgx.trusted_files.liblz4 = \"file:/usr/$(ARCH_LIBDIR)/liblz4.so.1\"\n" +
|
+ "sgx.allowed_files.aptconfd = \"file:/etc/apt/apt.conf.d\"\n"
|
||||||
"sgx.trusted_files.libsystemd = \"file:$(ARCH_LIBDIR)/libsystemd.so.0\"\n" +
|
+ "sgx.allowed_files.aptconf = \"file:/etc/apt/apt.conf\"\n"
|
||||||
"sgx.trusted_files.libselinux = \"file:$(ARCH_LIBDIR)/libselinux.so.1\"\n" +
|
+ "sgx.allowed_files.apport = \"file:/etc/default/apport\"\n" + "\n"
|
||||||
"sgx.trusted_files.libgcrypt = \"file:$(ARCH_LIBDIR)/libgcrypt.so.20\"\n" +
|
+ "# Name Service Switch (NSS) files (Glibc reads these files)\n"
|
||||||
"sgx.trusted_files.libpcre = \"file:$(ARCH_LIBDIR)/libpcre.so.3\"\n" +
|
+ "sgx.allowed_files.nsswitch = \"file:/etc/nsswitch.conf\"\n"
|
||||||
"sgx.trusted_files.libgpgerror = \"file:$(ARCH_LIBDIR)/libgpg-error.so.0\"\n" +
|
+ "sgx.allowed_files.group = \"file:/etc/group\"\n"
|
||||||
"sgx.trusted_files.libexpat = \"file:$(ARCH_LIBDIR)/libexpat.so.1\"\n" +
|
+ "sgx.allowed_files.passwd = \"file:/etc/passwd\"\n" + "\n"
|
||||||
"sgx.trusted_files.libz = \"file:$(ARCH_LIBDIR)/libz.so.1\"\n" +
|
+ "# DNS hostname resolution files (Glibc reads these files)\n"
|
||||||
"sgx.trusted_files.libz2 = \"file:$(ARCH_LIBDIR)/libbz2.so.1.0\"\n" +
|
+ "sgx.allowed_files.hostconf = \"file:/etc/host.conf\"\n"
|
||||||
"sgx.trusted_files.liblzma = \"file:$(ARCH_LIBDIR)/liblzma.so.5\"\n" +
|
+ "sgx.allowed_files.hosts = \"file:/etc/hosts\"\n"
|
||||||
"sgx.trusted_files.libmpdec = \"file:/usr/$(ARCH_LIBDIR)/libmpdec.so.2\"\n" +
|
+ "sgx.allowed_files.gaiconf = \"file:/etc/gai.conf\"\n"
|
||||||
"\n" +
|
+ "sgx.allowed_files.resolv = \"file:/etc/resolv.conf\"\n" + "\n"
|
||||||
"# Name Service Switch (NSS) libraries (Glibc dependencies)\n" +
|
+ "sgx.allowed_files.openssl = \"file:/etc/ssl/openssl.cnf\"\n" + "\n"
|
||||||
"sgx.trusted_files.libnssfiles = \"file:$(ARCH_LIBDIR)/libnss_files.so.2\"\n" +
|
+ "# System's file system table\n"
|
||||||
"sgx.trusted_files.libnsscompat = \"file:$(ARCH_LIBDIR)/libnss_compat.so.2\"\n" +
|
+ "sgx.allowed_files.fstab = \"file:/etc/fstab\"\n" + "\n"
|
||||||
"sgx.trusted_files.libnssnis = \"file:$(ARCH_LIBDIR)/libnss_nis.so.2\"\n" +
|
+ "$(NODEJS_TRUSTED_LIBS)\n" + "\n" + "# JavaScript (trusted)\n"
|
||||||
"sgx.trusted_files.libnsl = \"file:$(ARCH_LIBDIR)/libnsl.so.1\"\n" +
|
+ "sgx.allowed_files.smlib = \"file:node_modules\"\n"
|
||||||
"sgx.trusted_files.libnssmyhostname = \"file:$(ARCH_LIBDIR)/libnss_myhostname.so.2\"\n" +
|
+ "sgx.trusted_files.npminfo = \"file:package.json\"\n"
|
||||||
"sgx.trusted_files.libnssmdns = \"file:$(ARCH_LIBDIR)/libnss_mdns4_minimal.so.2\"\n" +
|
+ "sgx.trusted_files.contract = \"file:contract.js\"\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.globaljson = \"file:global.json\"\n"
|
||||||
"# Scratch space\n" +
|
+ "sgx.trusted_files.argjson = \"file:arg.json\"\n" + "\n"
|
||||||
"sgx.allowed_files.tmp = \"file:/tmp\"\n" +
|
+ "sys.insecure__allow_eventfd = 1\n" + "\n" + "sgx.remote_attestation = 1\n" + "\n"
|
||||||
"\n" +
|
+ "loader.env.LD_PRELOAD = \"libsecret_prov_attest.so\"\n"
|
||||||
"# APT config files\n" +
|
+ "loader.env.SECRET_PROVISION_CONSTRUCTOR = \"1\"\n"
|
||||||
"sgx.allowed_files.aptconfd = \"file:/etc/apt/apt.conf.d\"\n" +
|
+ "loader.env.SECRET_PROVISION_SET_PF_KEY = \"1\"\n"
|
||||||
"sgx.allowed_files.aptconf = \"file:/etc/apt/apt.conf\"\n" +
|
+ "loader.env.SECRET_PROVISION_CA_CHAIN_PATH = \"certs/test-ca-sha256.crt\"\n"
|
||||||
"sgx.allowed_files.apport = \"file:/etc/default/apport\"\n" +
|
+ "loader.env.SECRET_PROVISION_SERVERS = \"localhost:4433\"\n" + "\n"
|
||||||
"\n" +
|
+ "sgx.trusted_files.libsecretprovattest = \"file:libsecret_prov_attest.so\"\n"
|
||||||
"# Name Service Switch (NSS) files (Glibc reads these files)\n" +
|
+ "sgx.trusted_files.cachain = \"file:certs/test-ca-sha256.crt\"\n" + "\n"
|
||||||
"sgx.allowed_files.nsswitch = \"file:/etc/nsswitch.conf\"\n" +
|
+ "# Specify your SPID and linkable/unlinkable attestation policy\n"
|
||||||
"sgx.allowed_files.group = \"file:/etc/group\"\n" +
|
+ "sgx.ra_client_spid = \"DF3A8BA098E93F66CC64E8A215E98333\"\n"
|
||||||
"sgx.allowed_files.passwd = \"file:/etc/passwd\"\n" +
|
+ "sgx.ra_client_linkable = 0\n";
|
||||||
"\n" +
|
|
||||||
"# DNS hostname resolution files (Glibc reads these files)\n" +
|
|
||||||
"sgx.allowed_files.hostconf = \"file:/etc/host.conf\"\n" +
|
|
||||||
"sgx.allowed_files.hosts = \"file:/etc/hosts\"\n" +
|
|
||||||
"sgx.allowed_files.gaiconf = \"file:/etc/gai.conf\"\n" +
|
|
||||||
"sgx.allowed_files.resolv = \"file:/etc/resolv.conf\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"sgx.allowed_files.openssl = \"file:/etc/ssl/openssl.cnf\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"# System's file system table\n" +
|
|
||||||
"sgx.allowed_files.fstab = \"file:/etc/fstab\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"$(NODEJS_TRUSTED_LIBS)\n" +
|
|
||||||
"\n" +
|
|
||||||
"# JavaScript (trusted)\n" +
|
|
||||||
"sgx.allowed_files.smlib = \"file:node_modules\"\n" +
|
|
||||||
"sgx.trusted_files.npminfo = \"file:package.json\"\n" +
|
|
||||||
"sgx.trusted_files.contract = \"file:contract.js\"\n" +
|
|
||||||
"sgx.trusted_files.globaljson = \"file:global.json\"\n" +
|
|
||||||
"sgx.trusted_files.argjson = \"file:arg.json\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"sys.insecure__allow_eventfd = 1\n" +
|
|
||||||
"\n" +
|
|
||||||
"sgx.remote_attestation = 1\n" +
|
|
||||||
"\n" +
|
|
||||||
"loader.env.LD_PRELOAD = \"libsecret_prov_attest.so\"\n" +
|
|
||||||
"loader.env.SECRET_PROVISION_CONSTRUCTOR = \"1\"\n" +
|
|
||||||
"loader.env.SECRET_PROVISION_SET_PF_KEY = \"1\"\n" +
|
|
||||||
"loader.env.SECRET_PROVISION_CA_CHAIN_PATH = \"certs/test-ca-sha256.crt\"\n" +
|
|
||||||
"loader.env.SECRET_PROVISION_SERVERS = \"localhost:4433\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"sgx.trusted_files.libsecretprovattest = \"file:libsecret_prov_attest.so\"\n" +
|
|
||||||
"sgx.trusted_files.cachain = \"file:certs/test-ca-sha256.crt\"\n" +
|
|
||||||
"\n" +
|
|
||||||
"# Specify your SPID and linkable/unlinkable attestation policy\n" +
|
|
||||||
"sgx.ra_client_spid = \"DF3A8BA098E93F66CC64E8A215E98333\"\n" +
|
|
||||||
"sgx.ra_client_linkable = 0\n";
|
|
||||||
// add secret servers
|
// add secret servers
|
||||||
manifestStr += "loader.env.SECRET_PROVISION_CC_SERVERS = ";
|
manifestStr += "loader.env.SECRET_PROVISION_CC_SERVERS = ";
|
||||||
Object resultStr = engine.invokeFunction(
|
Object resultStr = engine.invokeFunction("getAllSecret", "", input.getRequester(),
|
||||||
"getAllSecret",
|
|
||||||
"",
|
|
||||||
input.getRequester(),
|
|
||||||
input.getRequesterDOI());
|
input.getRequesterDOI());
|
||||||
Map<String, String> resultMap = JsonUtil.fromJson(resultStr.toString(), MapType);
|
Map<String, String> resultMap = JsonUtil.fromJson(resultStr.toString(), MapType);
|
||||||
Map<String, String> serverMap = JsonUtil.fromJson(resultMap.get("result"), MapType);
|
Map<String, String> serverMap = JsonUtil.fromJson(resultMap.get("result"), MapType);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.bdware.sc.engine;
|
package org.bdware.sc.engine;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -52,18 +51,18 @@ public class DesktopEngine extends JSEngine {
|
|||||||
private static final String ScriptFileName = "contract_main.yjs";
|
private static final String ScriptFileName = "contract_main.yjs";
|
||||||
private static final Logger LOGGER = LogManager.getLogger(DesktopEngine.class);
|
private static final Logger LOGGER = LogManager.getLogger(DesktopEngine.class);
|
||||||
public static boolean _with_init_script = true;
|
public static boolean _with_init_script = true;
|
||||||
// static String script = "";
|
// static String script = "";
|
||||||
public NashornScriptEngine engine;
|
public NashornScriptEngine engine;
|
||||||
public SyncMechUtil syncUtil;
|
public SyncMechUtil syncUtil;
|
||||||
public boolean recovering; // 如果正在通过trace、trans恢复,设置为true,此时即使是StableMode也不记录
|
public boolean recovering; // 如果正在通过trace、trans恢复,设置为true,此时即使是StableMode也不记录
|
||||||
Resources resources;
|
Resources resources;
|
||||||
// Class<?> clz;
|
// Class<?> clz;
|
||||||
// byte[] stub;
|
// byte[] stub;
|
||||||
YJSClassLoader classLoader;
|
YJSClassLoader classLoader;
|
||||||
private ContractNode cn;
|
private ContractNode cn;
|
||||||
private Global global;
|
private Global global;
|
||||||
// private Object obj;
|
// private Object obj;
|
||||||
// private SimpleScriptContext simpleContext;
|
// private SimpleScriptContext simpleContext;
|
||||||
// private String traceDir;
|
// private String traceDir;
|
||||||
private ContractProcess.Logger tracePS = null;
|
private ContractProcess.Logger tracePS = null;
|
||||||
private Contract contract;
|
private Contract contract;
|
||||||
@@ -137,37 +136,28 @@ public class DesktopEngine extends JSEngine {
|
|||||||
syncUtil = new SyncMechUtil(this);
|
syncUtil = new SyncMechUtil(this);
|
||||||
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
|
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
|
||||||
ccl = (ccl == null) ? NashornScriptEngineFactory.class.getClassLoader() : ccl;
|
ccl = (ccl == null) ? NashornScriptEngineFactory.class.getClassLoader() : ccl;
|
||||||
String[] args = new String[]{"--loader-per-compile=false", "-strict=false"};
|
String[] args = new String[] {"--loader-per-compile=false", "-strict=false"};
|
||||||
classLoader = new YJSClassLoader(ccl, new YJSFilter());
|
classLoader = new YJSClassLoader(ccl, new YJSFilter());
|
||||||
engine =
|
engine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(args, // "--print-ast",
|
||||||
(NashornScriptEngine)
|
// "true",
|
||||||
new NashornScriptEngineFactory()
|
// "-d=/Users/huaqiancai/Downloads/dumpedClz",
|
||||||
.getScriptEngine(
|
// "--trace-callsites=enterexit"
|
||||||
args, // "--print-ast",
|
// "--log=methodhandles:all",
|
||||||
// "true",
|
// fields:all,
|
||||||
// "-d=/Users/huaqiancai/Downloads/dumpedClz",
|
// "--print-parse", "true" "--print-code",
|
||||||
// "--trace-callsites=enterexit"
|
// fields:finest
|
||||||
// "--log=methodhandles:all",
|
classLoader);
|
||||||
// fields:all,
|
|
||||||
// "--print-parse", "true" "--print-code",
|
|
||||||
// fields:finest
|
|
||||||
classLoader);
|
|
||||||
|
|
||||||
Context.TRACEIF = false;
|
Context.TRACEIF = false;
|
||||||
// engine = (NashornScriptEngine) new
|
// engine = (NashornScriptEngine) new
|
||||||
// NashornScriptEngineFactory().getScriptEngine(new YJSFilter());
|
// NashornScriptEngineFactory().getScriptEngine(new YJSFilter());
|
||||||
if (_with_init_script) {
|
if (_with_init_script) {
|
||||||
InputStream in =
|
InputStream in = DesktopEngine.class.getClassLoader()
|
||||||
DesktopEngine.class
|
.getResourceAsStream("org/bdware/sc/engine/yancloud_desktop.js");
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("org/bdware/sc/engine/yancloud_desktop.js");
|
|
||||||
assert in != null;
|
assert in != null;
|
||||||
InputStreamReader streamReader = new InputStreamReader(in);
|
InputStreamReader streamReader = new InputStreamReader(in);
|
||||||
engine.getContext()
|
engine.getContext().setAttribute(ScriptEngine.FILENAME,
|
||||||
.setAttribute(
|
"org/bdware/sc/engine/yancloud_desktop.js", ScriptContext.ENGINE_SCOPE);
|
||||||
ScriptEngine.FILENAME,
|
|
||||||
"org/bdware/sc/engine/yancloud_desktop.js",
|
|
||||||
ScriptContext.ENGINE_SCOPE);
|
|
||||||
engine.eval(streamReader);
|
engine.eval(streamReader);
|
||||||
}
|
}
|
||||||
global = engine.getNashornGlobal();
|
global = engine.getNashornGlobal();
|
||||||
@@ -194,12 +184,9 @@ public class DesktopEngine extends JSEngine {
|
|||||||
for (String str : permissionStub) {
|
for (String str : permissionStub) {
|
||||||
yancloud_desktop.append(UtilRegistry.getInitStr(str, false));
|
yancloud_desktop.append(UtilRegistry.getInitStr(str, false));
|
||||||
}
|
}
|
||||||
// LOGGER.debug("[initScript] " + yancloud_desktop);
|
// LOGGER.debug("[initScript] " + yancloud_desktop);
|
||||||
engine.getContext()
|
engine.getContext().setAttribute(ScriptEngine.FILENAME, yancloud_desktop.toString(),
|
||||||
.setAttribute(
|
ScriptContext.ENGINE_SCOPE);
|
||||||
ScriptEngine.FILENAME,
|
|
||||||
yancloud_desktop.toString(),
|
|
||||||
ScriptContext.ENGINE_SCOPE);
|
|
||||||
engine.eval(yancloud_desktop.toString());
|
engine.eval(yancloud_desktop.toString());
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -211,14 +198,14 @@ public class DesktopEngine extends JSEngine {
|
|||||||
ScriptLoader loader = engine.getNashornContext().getScriptLoader();
|
ScriptLoader loader = engine.getNashornContext().getScriptLoader();
|
||||||
Map<String, byte[]> clzCache = loader.getClzCache();
|
Map<String, byte[]> clzCache = loader.getClzCache();
|
||||||
Map<String, byte[]> ret = new HashMap<>(clzCache);
|
Map<String, byte[]> ret = new HashMap<>(clzCache);
|
||||||
// for (String str : clzCache.keySet()) {
|
// for (String str : clzCache.keySet()) {
|
||||||
// System.out.println("===ScriptClzName:" + str);
|
// System.out.println("===ScriptClzName:" + str);
|
||||||
// }
|
// }
|
||||||
StructureLoader sLoader = (StructureLoader) (engine.getNashornContext().getStructLoader());
|
StructureLoader sLoader = (StructureLoader) (engine.getNashornContext().getStructLoader());
|
||||||
clzCache = sLoader.getClzCache();
|
clzCache = sLoader.getClzCache();
|
||||||
// for (String str : clzCache.keySet()) {
|
// for (String str : clzCache.keySet()) {
|
||||||
// System.out.println("===StructureClzName:" + str);
|
// System.out.println("===StructureClzName:" + str);
|
||||||
// }
|
// }
|
||||||
ret.putAll(clzCache);
|
ret.putAll(clzCache);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -252,25 +239,26 @@ public class DesktopEngine extends JSEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContractResult loadContract(
|
public ContractResult loadContract(Contract contract, ContractNode contractNode,
|
||||||
Contract contract, ContractNode contractNode, boolean isInsnLimit) {
|
boolean isInsnLimit) {
|
||||||
cn = contractNode;
|
cn = contractNode;
|
||||||
engine.getContext()
|
engine.getContext().setAttribute(ScriptEngine.FILENAME, ScriptFileName,
|
||||||
.setAttribute(ScriptEngine.FILENAME, ScriptFileName, ScriptContext.ENGINE_SCOPE);
|
ScriptContext.ENGINE_SCOPE);
|
||||||
try {
|
try {
|
||||||
setPermission(cn.getPermission());
|
setPermission(cn.getPermission());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
for (SharableNode sharable : contractNode.getSharables()) {
|
||||||
|
for (String variableStatement : sharable.getVariableStatements()) {
|
||||||
|
compileSharable(sharable, variableStatement);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (FunctionNode fun : contractNode.getFunctions())
|
for (FunctionNode fun : contractNode.getFunctions())
|
||||||
try {
|
try {
|
||||||
String str = fun.plainText();
|
String str = fun.plainText();
|
||||||
engine.getContext()
|
engine.getContext().setAttribute(ScriptEngine.FILENAME, fun.getFileName(),
|
||||||
.setAttribute(
|
ScriptContext.ENGINE_SCOPE);
|
||||||
ScriptEngine.FILENAME,
|
|
||||||
fun.getFileName(),
|
|
||||||
ScriptContext.ENGINE_SCOPE);
|
|
||||||
compileFunction(fun, str, isInsnLimit);
|
compileFunction(fun, str, isInsnLimit);
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
return wrapperException(e, fun);
|
return wrapperException(e, fun);
|
||||||
@@ -280,7 +268,8 @@ public class DesktopEngine extends JSEngine {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new ContractResult(Status.Error, new JsonPrimitive(bo.toString()));
|
return new ContractResult(Status.Error, new JsonPrimitive(bo.toString()));
|
||||||
}
|
}
|
||||||
LOGGER.debug(JsonUtil.toJson(contractNode.events) + "\n\t" + JsonUtil.toJson(contractNode.logs));
|
LOGGER.debug(
|
||||||
|
JsonUtil.toJson(contractNode.events) + "\n\t" + JsonUtil.toJson(contractNode.logs));
|
||||||
for (String topic : contractNode.events.keySet()) {
|
for (String topic : contractNode.events.keySet()) {
|
||||||
compileEventFunction(topic, topic, contractNode.events.get(topic));
|
compileEventFunction(topic, topic, contractNode.events.get(topic));
|
||||||
}
|
}
|
||||||
@@ -307,26 +296,33 @@ public class DesktopEngine extends JSEngine {
|
|||||||
return cResult;
|
return cResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void compileSharable(SharableNode sharable, String variableStatement) {
|
||||||
|
try {
|
||||||
|
engine.getContext().setAttribute(ScriptEngine.FILENAME, sharable.getFileName(),
|
||||||
|
ScriptContext.ENGINE_SCOPE);
|
||||||
|
engine.eval("var " + variableStatement);
|
||||||
|
LOGGER.info("load sharable: " + variableStatement);
|
||||||
|
} catch (ScriptException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void compileEventFunction(String name, String topic, REventSemantics semantics) {
|
private void compileEventFunction(String name, String topic, REventSemantics semantics) {
|
||||||
try {
|
try {
|
||||||
String str;
|
String str;
|
||||||
if (REventSemantics.AT_LEAST_ONCE.equals(semantics)) {
|
if (REventSemantics.AT_LEAST_ONCE.equals(semantics)) {
|
||||||
str =
|
str = String.format("function %s(arg) { YancloudUtil.pubEvent(\"%s\", arg); }",
|
||||||
String.format(
|
name, topic);
|
||||||
"function %s(arg) { YancloudUtil.pubEvent(\"%s\", arg); }",
|
|
||||||
name, topic);
|
|
||||||
} else {
|
} else {
|
||||||
str =
|
str = String.format(
|
||||||
String.format(
|
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
||||||
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
name, topic, semantics.name());
|
||||||
name, topic, semantics.name());
|
|
||||||
}
|
}
|
||||||
compileFunction(null, str, false);
|
compileFunction(null, str, false);
|
||||||
LOGGER.debug("compile function " + name + " success!");
|
LOGGER.debug("compile function " + name + " success!");
|
||||||
str =
|
str = String.format(
|
||||||
String.format(
|
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
||||||
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
name, topic);
|
||||||
name, topic);
|
|
||||||
compileFunction(null, str, false);
|
compileFunction(null, str, false);
|
||||||
LOGGER.debug("compile function " + name + "s success!");
|
LOGGER.debug("compile function " + name + "s success!");
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
@@ -334,79 +330,80 @@ public class DesktopEngine extends JSEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Load a contract into contract engine
|
// * Load a contract into contract engine
|
||||||
// *
|
// *
|
||||||
// * @param contractNode a contract node generated by YJS compiler
|
// * @param contractNode a contract node generated by YJS compiler
|
||||||
// * @return whether contract is loaded successfully
|
// * @return whether contract is loaded successfully
|
||||||
// */
|
// */
|
||||||
// @Override
|
// @Override
|
||||||
// public ContractResult loadContract(Contract contract, ContractNode contractNode) {
|
// public ContractResult loadContract(Contract contract, ContractNode contractNode) {
|
||||||
// cn = contractNode;
|
// cn = contractNode;
|
||||||
// engine.getContext()
|
// engine.getContext()
|
||||||
// .setAttribute(ScriptEngine.FILENAME, ScriptFileName,
|
// .setAttribute(ScriptEngine.FILENAME, ScriptFileName,
|
||||||
// ScriptContext.ENGINE_SCOPE);
|
// ScriptContext.ENGINE_SCOPE);
|
||||||
// try {
|
// try {
|
||||||
// setPermission(cn.getPermission());
|
// setPermission(cn.getPermission());
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// for (FunctionNode fun : cn.getFunctions()) {
|
// for (FunctionNode fun : cn.getFunctions()) {
|
||||||
// try {
|
// try {
|
||||||
// String str = fun.plainText();
|
// String str = fun.plainText();
|
||||||
// engine.getContext()
|
// engine.getContext()
|
||||||
// .setAttribute(
|
// .setAttribute(
|
||||||
// ScriptEngine.FILENAME,
|
// ScriptEngine.FILENAME,
|
||||||
// fun.getFileName(),
|
// fun.getFileName(),
|
||||||
// ScriptContext.ENGINE_SCOPE);
|
// ScriptContext.ENGINE_SCOPE);
|
||||||
// Object scriptFunction = engine.eval(str);
|
// Object scriptFunction = engine.eval(str);
|
||||||
// ScriptObjectMirror sf = (ScriptObjectMirror) scriptFunction;
|
// ScriptObjectMirror sf = (ScriptObjectMirror) scriptFunction;
|
||||||
// compileFunction(sf, fun.getLogTypes().contains(LogType.Branch));
|
// compileFunction(sf, fun.getLogTypes().contains(LogType.Branch));
|
||||||
// } catch (ScriptException e) {
|
// } catch (ScriptException e) {
|
||||||
// return wrapperException(e, fun);
|
// return wrapperException(e, fun);
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
// e.printStackTrace(new PrintStream(bo));
|
// e.printStackTrace(new PrintStream(bo));
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// return new ContractResult(Status.Error, new JsonPrimitive(bo.toString()));
|
// return new ContractResult(Status.Error, new JsonPrimitive(bo.toString()));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// for (String event : cn.events) {
|
// for (String event : cn.events) {
|
||||||
// String str =
|
// String str =
|
||||||
// "function "
|
// "function "
|
||||||
// + event
|
// + event
|
||||||
// + "(arg){ return YancloudUtil.pubEvent(\""
|
// + "(arg){ return YancloudUtil.pubEvent(\""
|
||||||
// + event
|
// + event
|
||||||
// + "\",arg);}";
|
// + "\",arg);}";
|
||||||
//
|
//
|
||||||
// try {
|
// try {
|
||||||
// Object scriptFunction = engine.eval(str);
|
// Object scriptFunction = engine.eval(str);
|
||||||
// ScriptObjectMirror sf = (ScriptObjectMirror) scriptFunction;
|
// ScriptObjectMirror sf = (ScriptObjectMirror) scriptFunction;
|
||||||
// compileFunction(sf, false);
|
// compileFunction(sf, false);
|
||||||
// } catch (ScriptException e) {
|
// } catch (ScriptException e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// for (ClassNode classNode : cn.getClzs()) {
|
// for (ClassNode classNode : cn.getClzs()) {
|
||||||
// try {
|
// try {
|
||||||
// System.out.println(classNode.plainText());
|
// System.out.println(classNode.plainText());
|
||||||
// // engine.eval(cn.plainText());
|
// // engine.eval(cn.plainText());
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// // return wrapperException(e, cn.getFileName(), cn.getLine(),
|
// // return wrapperException(e, cn.getFileName(), cn.getLine(),
|
||||||
// // cn.getPos());
|
// // cn.getPos());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // dump confidential functions and corresponding dependent functions to a String in
|
// // dump confidential functions and corresponding dependent functions to a String in
|
||||||
// Global
|
// Global
|
||||||
// // variable.
|
// // variable.
|
||||||
// // The String will be passed to collect signature.
|
// // The String will be passed to collect signature.
|
||||||
//
|
//
|
||||||
// return new ContractResult(Status.Success, new JsonPrimitive(""));
|
// return new ContractResult(Status.Success, new JsonPrimitive(""));
|
||||||
// }
|
// }
|
||||||
private void compileFunction(FunctionNode functionNode, ScriptObjectMirror sf, boolean instrumentBranch) {
|
private void compileFunction(FunctionNode functionNode, ScriptObjectMirror sf,
|
||||||
|
boolean instrumentBranch) {
|
||||||
Global oldGlobal = Context.getGlobal();
|
Global oldGlobal = Context.getGlobal();
|
||||||
boolean globalChanged = (oldGlobal != global);
|
boolean globalChanged = (oldGlobal != global);
|
||||||
try {
|
try {
|
||||||
@@ -423,7 +420,8 @@ public class DesktopEngine extends JSEngine {
|
|||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
ScriptFunctionData scriptFunctioNData = (ScriptFunctionData) f.get(scriptFunction);
|
ScriptFunctionData scriptFunctioNData = (ScriptFunctionData) f.get(scriptFunction);
|
||||||
Object scope = scriptFunction.getScope();
|
Object scope = scriptFunction.getScope();
|
||||||
Method getGeneric = ScriptFunctionData.class.getDeclaredMethod("getGenericInvoker", ScriptObject.class);
|
Method getGeneric = ScriptFunctionData.class.getDeclaredMethod("getGenericInvoker",
|
||||||
|
ScriptObject.class);
|
||||||
getGeneric.setAccessible(true);
|
getGeneric.setAccessible(true);
|
||||||
MethodHandle methodHandle = (MethodHandle) getGeneric.invoke(scriptFunctioNData, scope);
|
MethodHandle methodHandle = (MethodHandle) getGeneric.invoke(scriptFunctioNData, scope);
|
||||||
if (methodHandle.getClass() != Class.forName("java.lang.invoke.DirectMethodHandle")) {
|
if (methodHandle.getClass() != Class.forName("java.lang.invoke.DirectMethodHandle")) {
|
||||||
@@ -441,17 +439,19 @@ public class DesktopEngine extends JSEngine {
|
|||||||
Class clazz2 = (Class) clazz.get(memberName);
|
Class clazz2 = (Class) clazz.get(memberName);
|
||||||
if (functionNode != null)
|
if (functionNode != null)
|
||||||
functionNode.compiledClazz = clazz2;
|
functionNode.compiledClazz = clazz2;
|
||||||
//functionNode==null --> event functions
|
// functionNode==null --> event functions
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (globalChanged) Context.setGlobal(oldGlobal);
|
if (globalChanged)
|
||||||
|
Context.setGlobal(oldGlobal);
|
||||||
Context.TRACEIF = false;
|
Context.TRACEIF = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compileFunction(FunctionNode functionNode, String snippet, boolean instrumentBranch) throws ScriptException {
|
public void compileFunction(FunctionNode functionNode, String snippet, boolean instrumentBranch)
|
||||||
|
throws ScriptException {
|
||||||
compileFunction(functionNode, (ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
compileFunction(functionNode, (ScriptObjectMirror) engine.eval(snippet), instrumentBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,8 +481,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
JavaScriptEntry.msgList = new ArrayList<>();
|
JavaScriptEntry.msgList = new ArrayList<>();
|
||||||
FunctionNode fun = cn.getFunction(input.getAction());
|
FunctionNode fun = cn.getFunction(input.getAction());
|
||||||
if (fun == null) {
|
if (fun == null) {
|
||||||
return new ContractResult(
|
return new ContractResult(Status.Exception,
|
||||||
Status.Exception,
|
|
||||||
new JsonPrimitive("Action " + input.getAction() + " is not exists"));
|
new JsonPrimitive("Action " + input.getAction() + " is not exists"));
|
||||||
}
|
}
|
||||||
ProgramPointCounter ppc = null;
|
ProgramPointCounter ppc = null;
|
||||||
@@ -499,23 +498,14 @@ public class DesktopEngine extends JSEngine {
|
|||||||
HashMap<String, Long> ppCountMap = evaluatesAnalysis(input.getAction(), functions);
|
HashMap<String, Long> ppCountMap = evaluatesAnalysis(input.getAction(), functions);
|
||||||
Long extraGas = getExtraGas(fun.getCost().getExtraGas(), input);
|
Long extraGas = getExtraGas(fun.getCost().getExtraGas(), input);
|
||||||
bo = new ByteArrayOutputStream();
|
bo = new ByteArrayOutputStream();
|
||||||
ppc =
|
ppc = new ProgramPointCounter(bo, previous.getCp(), Long.MAX_VALUE, functionIndex,
|
||||||
new ProgramPointCounter(
|
input.getGasLimit(), extraGas, input.getAction(), ppCountMap);
|
||||||
bo,
|
|
||||||
previous.getCp(),
|
|
||||||
Long.MAX_VALUE,
|
|
||||||
functionIndex,
|
|
||||||
input.getGasLimit(),
|
|
||||||
extraGas,
|
|
||||||
input.getAction(),
|
|
||||||
ppCountMap);
|
|
||||||
this.redirectTracePS(ppc);
|
this.redirectTracePS(ppc);
|
||||||
}
|
}
|
||||||
if (fun.isExport() ||
|
if (fun.isExport() ||
|
||||||
// if the function has been registered as event handler
|
// if the function has been registered as event handler
|
||||||
(fun.isHandler() &&
|
(fun.isHandler() && null != input.getRequester()
|
||||||
null != input.getRequester() &&
|
&& input.getRequester().startsWith("event"))) {
|
||||||
input.getRequester().startsWith("event"))) {
|
|
||||||
Object ret;
|
Object ret;
|
||||||
if (fun.isView()) {
|
if (fun.isView()) {
|
||||||
ret = executeWithoutLock(fun, input, null);
|
ret = executeWithoutLock(fun, input, null);
|
||||||
@@ -525,8 +515,10 @@ public class DesktopEngine extends JSEngine {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//System.out.println("[DesktopEngine MaskConfig]"+ContractProcess.instance.getProjectConfig().getMaskConfig().config.toString());
|
// System.out.println("[DesktopEngine
|
||||||
ContractResult contractRes = new ContractResult(Status.Success, JSONTool.convertMirrorToJson(ret));
|
// MaskConfig]"+ContractProcess.instance.getProjectConfig().getMaskConfig().config.toString());
|
||||||
|
ContractResult contractRes =
|
||||||
|
new ContractResult(Status.Success, JSONTool.convertMirrorToJson(ret));
|
||||||
if (ppc != null) {
|
if (ppc != null) {
|
||||||
contractRes.extraGas = ppc.extraGas;
|
contractRes.extraGas = ppc.extraGas;
|
||||||
contractRes.executionGas = ppc.cost;
|
contractRes.executionGas = ppc.cost;
|
||||||
@@ -553,10 +545,10 @@ public class DesktopEngine extends JSEngine {
|
|||||||
if (syncUtil.startFlag && !recovering) {
|
if (syncUtil.startFlag && !recovering) {
|
||||||
switch (syncUtil.currType) {
|
switch (syncUtil.currType) {
|
||||||
case Trace:
|
case Trace:
|
||||||
// syncUtil.traceRecordUtil.eachFinish();
|
// syncUtil.traceRecordUtil.eachFinish();
|
||||||
break;
|
break;
|
||||||
case Trans:
|
case Trans:
|
||||||
// syncUtil.transRecordUtil.eachFinish();
|
// syncUtil.transRecordUtil.eachFinish();
|
||||||
break;
|
break;
|
||||||
case Memory:
|
case Memory:
|
||||||
default:
|
default:
|
||||||
@@ -568,16 +560,13 @@ public class DesktopEngine extends JSEngine {
|
|||||||
} else {
|
} else {
|
||||||
// return new ContractResult(Status.Exception, "Action " + input.getAction() + "
|
// return new ContractResult(Status.Exception, "Action " + input.getAction() + "
|
||||||
// is not exported!");
|
// is not exported!");
|
||||||
return new ContractResult(
|
return new ContractResult(Status.Exception,
|
||||||
Status.Exception,
|
|
||||||
new JsonPrimitive("Action " + input.getAction() + " is not exported!"));
|
new JsonPrimitive("Action " + input.getAction() + " is not exported!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ScriptReturnException e) {
|
} catch (ScriptReturnException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new ContractResult(
|
return new ContractResult(Status.Exception, e.message);
|
||||||
Status.Exception,
|
|
||||||
e.message);
|
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
Throwable cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -588,26 +577,25 @@ public class DesktopEngine extends JSEngine {
|
|||||||
e.printStackTrace(ps);
|
e.printStackTrace(ps);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (e.getCause() != null && e.getCause() instanceof ScriptException) {
|
if (e.getCause() != null && e.getCause() instanceof ScriptException) {
|
||||||
return new ContractResult(
|
return new ContractResult(Status.Exception, new JsonPrimitive(
|
||||||
Status.Exception,
|
extractException(bo1.toString(), extract(cn, e.getCause()))));
|
||||||
new JsonPrimitive(
|
|
||||||
extractException(bo1.toString(), extract(cn, e.getCause()))));
|
|
||||||
} else {
|
} else {
|
||||||
return new ContractResult(
|
return new ContractResult(Status.Exception,
|
||||||
Status.Exception,
|
|
||||||
new JsonPrimitive(extractException(bo1.toString(), extract(cn, e))));
|
new JsonPrimitive(extractException(bo1.toString(), extract(cn, e))));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.redirectTracePS(previous);
|
this.redirectTracePS(previous);
|
||||||
if (globalChanged) Context.setGlobal(oldGlobal);
|
if (globalChanged)
|
||||||
|
Context.setGlobal(oldGlobal);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object executeWithoutLock(FunctionNode fun, ContractRequest input, Object injectedArg) throws ScriptException, NoSuchMethodException {
|
public Object executeWithoutLock(FunctionNode fun, ContractRequest input, Object injectedArg)
|
||||||
// long start = System.currentTimeMillis();
|
throws ScriptException, NoSuchMethodException {
|
||||||
|
// long start = System.currentTimeMillis();
|
||||||
ArgPacks argPacks = new ArgPacks(input, input.getArg(), null);
|
ArgPacks argPacks = new ArgPacks(input, input.getArg(), null);
|
||||||
if(injectedArg != null) {
|
if (injectedArg != null) {
|
||||||
argPacks.arg = injectedArg;
|
argPacks.arg = injectedArg;
|
||||||
}
|
}
|
||||||
for (AnnotationHook handler : fun.beforeExecutionAnnotations()) {
|
for (AnnotationHook handler : fun.beforeExecutionAnnotations()) {
|
||||||
@@ -616,19 +604,15 @@ public class DesktopEngine extends JSEngine {
|
|||||||
|
|
||||||
// actually invoke!
|
// actually invoke!
|
||||||
if (argPacks.ret == null) {
|
if (argPacks.ret == null) {
|
||||||
argPacks.ret =
|
argPacks.ret = engine.invokeFunction(input.getAction(),
|
||||||
engine.invokeFunction(
|
(fun.isHandler() ? JsonUtil.fromJson(input.getArg(), Event.class)
|
||||||
input.getAction(),
|
: JSONTool.convertJsonElementToMirror(argPacks.arg)),
|
||||||
(fun.isHandler()
|
input.getRequester(), input.getRequesterDOI());
|
||||||
? JsonUtil.fromJson(input.getArg(), Event.class)
|
|
||||||
: JSONTool.convertJsonElementToMirror(argPacks.arg)),
|
|
||||||
input.getRequester(),
|
|
||||||
input.getRequesterDOI());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (AnnotationHook handler : fun.afterExecutionAnnotations()) {
|
for (AnnotationHook handler : fun.afterExecutionAnnotations()) {
|
||||||
//Mask在after裏面
|
// Mask在after裏面
|
||||||
//System.out.println("afterHook"+contract.Mask);
|
// System.out.println("afterHook"+contract.Mask);
|
||||||
argPacks = handler.handle(this, argPacks);
|
argPacks = handler.handle(this, argPacks);
|
||||||
}
|
}
|
||||||
return argPacks.ret;
|
return argPacks.ret;
|
||||||
@@ -661,13 +645,12 @@ public class DesktopEngine extends JSEngine {
|
|||||||
for (String function : functions) {
|
for (String function : functions) {
|
||||||
MethodNode mn = methods.get(function);
|
MethodNode mn = methods.get(function);
|
||||||
if (mn != null) {
|
if (mn != null) {
|
||||||
CFGraph cfg =
|
CFGraph cfg = new CFGraph(mn) {
|
||||||
new CFGraph(mn) {
|
@Override
|
||||||
@Override
|
public BasicBlock getBasicBlock(int id) {
|
||||||
public BasicBlock getBasicBlock(int id) {
|
return new BasicBlock(id);
|
||||||
return new BasicBlock(id);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
// cfg.printSelf();
|
// cfg.printSelf();
|
||||||
CFGmap.put(function, cfg);
|
CFGmap.put(function, cfg);
|
||||||
PPCount countFee = new PPCount(cfg, flag);
|
PPCount countFee = new PPCount(cfg, flag);
|
||||||
@@ -686,15 +669,15 @@ public class DesktopEngine extends JSEngine {
|
|||||||
flag++;
|
flag++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* for (Map.Entry<String, Long> map : PPCount.functionSumGas.entrySet()) {
|
/*
|
||||||
if (map.getKey().contains(getFunction) && map.getKey().contains("true")) {
|
* for (Map.Entry<String, Long> map : PPCount.functionSumGas.entrySet()) { if
|
||||||
System.out.println("[合约方法pub中条件循环为true时:]" + map.getValue());
|
* (map.getKey().contains(getFunction) && map.getKey().contains("true")) {
|
||||||
} else if (map.getKey().contains(getFunction) && map.getKey().contains("false")) {
|
* System.out.println("[合约方法pub中条件循环为true时:]" + map.getValue()); } else if
|
||||||
System.out.println("[合约方法pub中条件循环为false时:]" + map.getValue());
|
* (map.getKey().contains(getFunction) && map.getKey().contains("false")) {
|
||||||
} else if (map.getKey().contains(getFunction)) {
|
* System.out.println("[合约方法pub中条件循环为false时:]" + map.getValue()); } else if
|
||||||
System.out.println("[合约方法pub中其他语句消耗:]" + map.getValue());
|
* (map.getKey().contains(getFunction)) { System.out.println("[合约方法pub中其他语句消耗:]" +
|
||||||
}
|
* map.getValue()); } }
|
||||||
}*/
|
*/
|
||||||
return ppCountMap;
|
return ppCountMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,12 +687,8 @@ public class DesktopEngine extends JSEngine {
|
|||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
Invocable cal = engine;
|
Invocable cal = engine;
|
||||||
Object ret =
|
Object ret = cal.invokeFunction(costFunction, input.getArg(), input.getRequester(),
|
||||||
cal.invokeFunction(
|
input.getRequesterDOI());
|
||||||
costFunction,
|
|
||||||
input.getArg(),
|
|
||||||
input.getRequester(),
|
|
||||||
input.getRequesterDOI());
|
|
||||||
if (ret != null && StringUtils.isNumeric(ret.toString())) {
|
if (ret != null && StringUtils.isNumeric(ret.toString())) {
|
||||||
return Long.parseLong(ret.toString());
|
return Long.parseLong(ret.toString());
|
||||||
} else {
|
} else {
|
||||||
@@ -765,15 +744,16 @@ public class DesktopEngine extends JSEngine {
|
|||||||
if (actLine != -1) {
|
if (actLine != -1) {
|
||||||
actLine += line - 1;
|
actLine += line - 1;
|
||||||
}
|
}
|
||||||
message =
|
message = message.replaceAll("at line number " + e.getLineNumber(),
|
||||||
message.replaceAll(
|
"at line number " + (actLine));
|
||||||
"at line number " + e.getLineNumber(), "at line number " + (actLine));
|
|
||||||
if (fun.getFileName() != null)
|
if (fun.getFileName() != null)
|
||||||
message = message.replace("in contract_main.yjs", "in " + fun.getFileName());
|
message = message.replace("in contract_main.yjs", "in " + fun.getFileName());
|
||||||
content.append(message);
|
content.append(message);
|
||||||
content.append("(");
|
content.append("(");
|
||||||
if (fun.functionName != null) content.append(fun.functionName);
|
if (fun.functionName != null)
|
||||||
else content.append("contract_main.yjs");
|
content.append(fun.functionName);
|
||||||
|
else
|
||||||
|
content.append("contract_main.yjs");
|
||||||
content.append(":");
|
content.append(":");
|
||||||
|
|
||||||
content.append(actLine);
|
content.append(actLine);
|
||||||
@@ -792,17 +772,15 @@ public class DesktopEngine extends JSEngine {
|
|||||||
String methodName = element.getMethodName();
|
String methodName = element.getMethodName();
|
||||||
String fileName = element.getFileName();
|
String fileName = element.getFileName();
|
||||||
|
|
||||||
if (fileName.endsWith(".java")) continue;
|
if (fileName.endsWith(".java"))
|
||||||
|
continue;
|
||||||
if (c.isBundle()) {
|
if (c.isBundle()) {
|
||||||
fileName = fixFile(c, methodName);
|
fileName = fixFile(c, methodName);
|
||||||
}
|
}
|
||||||
if (fileName.equals("--")) continue;
|
if (fileName.equals("--"))
|
||||||
ret.add(
|
continue;
|
||||||
String.format(
|
ret.add(String.format("at %s(%s:%d)", methodName, fileName,
|
||||||
"at %s(%s:%d)",
|
(fixLine(c, methodName) + element.getLineNumber())));
|
||||||
methodName,
|
|
||||||
fileName,
|
|
||||||
(fixLine(c, methodName) + element.getLineNumber())));
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -918,13 +896,13 @@ public class DesktopEngine extends JSEngine {
|
|||||||
}
|
}
|
||||||
if (entry.getName().endsWith(".so") || entry.getName().endsWith(".so.1")) {
|
if (entry.getName().endsWith(".so") || entry.getName().endsWith(".so.1")) {
|
||||||
System.out.println("unzip library:" + entry.getName().replaceAll(".*/", ""));
|
System.out.println("unzip library:" + entry.getName().replaceAll(".*/", ""));
|
||||||
loader.unzipLibrary(
|
loader.unzipLibrary(zf.getInputStream(entry),
|
||||||
zf.getInputStream(entry), entry.getName().replaceAll(".*/", ""));
|
entry.getName().replaceAll(".*/", ""));
|
||||||
}
|
}
|
||||||
if (HardwareInfo.type == OSType.mac && entry.getName().endsWith(".dylib")) {
|
if (HardwareInfo.type == OSType.mac && entry.getName().endsWith(".dylib")) {
|
||||||
System.out.println("unzip library:" + entry.getName().replaceAll(".*/", ""));
|
System.out.println("unzip library:" + entry.getName().replaceAll(".*/", ""));
|
||||||
loader.unzipLibrary(
|
loader.unzipLibrary(zf.getInputStream(entry),
|
||||||
zf.getInputStream(entry), entry.getName().replaceAll(".*/", ""));
|
entry.getName().replaceAll(".*/", ""));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.bdware.sc.engine;
|
package org.bdware.sc.engine;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
|
||||||
import org.bdware.sc.util.JsonUtil;
|
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
import wrp.jdk.nashorn.internal.objects.NativeArray;
|
import wrp.jdk.nashorn.internal.objects.NativeArray;
|
||||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||||
@@ -44,7 +42,7 @@ public class JSONTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object convertJsonElementToMirror(Object input) {
|
public static Object convertJsonElementToMirror(Object input) {
|
||||||
if(input instanceof JsonElement) {
|
if (input instanceof JsonElement) {
|
||||||
return convertJsonElementToMirror((JsonElement) input);
|
return convertJsonElementToMirror((JsonElement) input);
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input;
|
||||||
@@ -52,11 +50,14 @@ public class JSONTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JsonElement convertMirrorToJsonInternal(Object obj, Set<Object> recorded) {
|
private static JsonElement convertMirrorToJsonInternal(Object obj, Set<Object> recorded) {
|
||||||
if (recorded.contains(obj)) return JsonNull.INSTANCE;
|
if (recorded.contains(obj))
|
||||||
if (obj == null) return JsonNull.INSTANCE;
|
return JsonNull.INSTANCE;
|
||||||
|
if (obj == null)
|
||||||
|
return JsonNull.INSTANCE;
|
||||||
if (obj.getClass() == wrp.jdk.nashorn.internal.runtime.Undefined.class)
|
if (obj.getClass() == wrp.jdk.nashorn.internal.runtime.Undefined.class)
|
||||||
return JsonNull.INSTANCE;
|
return JsonNull.INSTANCE;
|
||||||
if (obj instanceof JsonElement) return (JsonElement) obj;
|
if (obj instanceof JsonElement)
|
||||||
|
return (JsonElement) obj;
|
||||||
if (obj.getClass().isArray()) {
|
if (obj.getClass().isArray()) {
|
||||||
Object[] arr = (Object[]) obj;
|
Object[] arr = (Object[]) obj;
|
||||||
recorded.add(obj);
|
recorded.add(obj);
|
||||||
@@ -149,9 +150,7 @@ public class JSONTool {
|
|||||||
return jsonObject;
|
return jsonObject;
|
||||||
} else if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
} else if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
||||||
return JsonNull.INSTANCE;
|
return JsonNull.INSTANCE;
|
||||||
} else if (obj.getClass() == DoipMessage.class) {
|
} else if (obj instanceof Number) {
|
||||||
return JsonUtil.fromJson(JsonUtil.toJson(obj), JsonObject.class);
|
|
||||||
}else if (obj instanceof Number) {
|
|
||||||
return new JsonPrimitive((Number) obj);
|
return new JsonPrimitive((Number) obj);
|
||||||
} else if (obj instanceof String) {
|
} else if (obj instanceof String) {
|
||||||
return new JsonPrimitive((String) obj);
|
return new JsonPrimitive((String) obj);
|
||||||
|
|||||||
@@ -128,17 +128,18 @@ public class SyncMechUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* memory的操作
|
* memory的操作 无需startFlag就可以使用memory的操作
|
||||||
* 无需startFlag就可以使用memory的操作
|
|
||||||
*/
|
*/
|
||||||
public synchronized String dumpMemory(String path) {
|
public synchronized String dumpMemory(String path) {
|
||||||
if (memoryDumpUtil == null) memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
if (memoryDumpUtil == null)
|
||||||
|
memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
||||||
return memoryDumpUtil.dumpMemory(path, true);
|
return memoryDumpUtil.dumpMemory(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String dumpMemory(String path, boolean stateful) {
|
public synchronized String dumpMemory(String path, boolean stateful) {
|
||||||
LOGGER.info("dumpMemroy : stateful=" + stateful);
|
LOGGER.info("dumpMemroy : stateful=" + stateful);
|
||||||
if (memoryDumpUtil == null) memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
if (memoryDumpUtil == null)
|
||||||
|
memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
||||||
return memoryDumpUtil.dumpMemory(path, stateful);
|
return memoryDumpUtil.dumpMemory(path, stateful);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@ public class SyncMechUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 同步机制操作
|
* 同步机制操作
|
||||||
*/
|
*/
|
||||||
// 设置ContractRecord持久化的文件
|
// 设置ContractRecord持久化的文件
|
||||||
public void setCRFile(String fileName) {
|
public void setCRFile(String fileName) {
|
||||||
@@ -210,7 +211,8 @@ public class SyncMechUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void changeCurrType(SyncType t) {
|
public void changeCurrType(SyncType t) {
|
||||||
if (t == currType) return;
|
if (t == currType)
|
||||||
|
return;
|
||||||
|
|
||||||
// finASyncRecord();
|
// finASyncRecord();
|
||||||
currType = t;
|
currType = t;
|
||||||
@@ -226,7 +228,8 @@ public class SyncMechUtil {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Memory:
|
case Memory:
|
||||||
if (memoryDumpUtil == null) memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
if (memoryDumpUtil == null)
|
||||||
|
memoryDumpUtil = new MemoryDumpUtil(engine.engine);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -256,7 +259,8 @@ public class SyncMechUtil {
|
|||||||
* Trans操作
|
* Trans操作
|
||||||
*/
|
*/
|
||||||
public synchronized String redo(String path) {
|
public synchronized String redo(String path) {
|
||||||
if (transRecoverUtil == null) transRecoverUtil = new TransRecoverUtil(engine);
|
if (transRecoverUtil == null)
|
||||||
|
transRecoverUtil = new TransRecoverUtil(engine);
|
||||||
|
|
||||||
// 先清空,否则会重复执行一些trans
|
// 先清空,否则会重复执行一些trans
|
||||||
if (transRecoverUtil.transRecords != null && !transRecoverUtil.transRecords.isEmpty())
|
if (transRecoverUtil.transRecords != null && !transRecoverUtil.transRecords.isEmpty())
|
||||||
@@ -264,10 +268,11 @@ public class SyncMechUtil {
|
|||||||
|
|
||||||
// 某一次检查点之后没有transRecords
|
// 某一次检查点之后没有transRecords
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.exists()) return "success";
|
if (!file.exists())
|
||||||
|
return "success";
|
||||||
|
|
||||||
transRecoverUtil.setTraceRecords(path);
|
transRecoverUtil.setTraceRecords(path);
|
||||||
transRecoverUtil.recoverFromTransRecord();
|
transRecoverUtil.recoverFromTransRecord();
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import javax.script.ScriptEngine;
|
|||||||
|
|
||||||
public class TestClassFilter {
|
public class TestClassFilter {
|
||||||
public TestClassFilter() {
|
public TestClassFilter() {
|
||||||
final String script = "print(java.lang.System.getProperty(\"java.home\"));" +
|
final String script = "print(java.lang.System.getProperty(\"java.home\"));"
|
||||||
"print(\"Create file variable\");" +
|
+ "print(\"Create file variable\");" + "var File = Java.type(\"java.io.File\");";
|
||||||
"var File = Java.type(\"java.io.File\");";
|
|
||||||
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
||||||
ScriptEngine engine = factory.getScriptEngine(new YJSFilter());
|
ScriptEngine engine = factory.getScriptEngine(new YJSFilter());
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class YJSClassLoader extends URLClassLoader {
|
|||||||
List<String> toLoad = new ArrayList<>();
|
List<String> toLoad = new ArrayList<>();
|
||||||
|
|
||||||
public YJSClassLoader(ClassLoader parent, ClassFilter cf) {
|
public YJSClassLoader(ClassLoader parent, ClassFilter cf) {
|
||||||
super(new URL[]{}, parent);
|
super(new URL[] {}, parent);
|
||||||
classFilter = cf;
|
classFilter = cf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class YJSClassLoader extends URLClassLoader {
|
|||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
byte[] buff = new byte[1024];
|
byte[] buff = new byte[1024];
|
||||||
|
|
||||||
for (int len = 0; (len = in.read(buff)) > 0; ) {
|
for (int len = 0; (len = in.read(buff)) > 0;) {
|
||||||
bo.write(buff, 0, len);
|
bo.write(buff, 0, len);
|
||||||
}
|
}
|
||||||
return bo.toByteArray();
|
return bo.toByteArray();
|
||||||
@@ -63,7 +63,8 @@ public class YJSClassLoader extends URLClassLoader {
|
|||||||
public String unzipLibrary(InputStream inputStream, String name) {
|
public String unzipLibrary(InputStream inputStream, String name) {
|
||||||
try {
|
try {
|
||||||
if (libDir == null) {
|
if (libDir == null) {
|
||||||
libDir = new File(System.getProperty("java.io.tmpdir"), "yjscontract_" + System.currentTimeMillis());
|
libDir = new File(System.getProperty("java.io.tmpdir"),
|
||||||
|
"yjscontract_" + System.currentTimeMillis());
|
||||||
libDir.mkdirs();
|
libDir.mkdirs();
|
||||||
}
|
}
|
||||||
File f = new File(libDir, name);
|
File f = new File(libDir, name);
|
||||||
@@ -71,7 +72,7 @@ public class YJSClassLoader extends URLClassLoader {
|
|||||||
toLoad.add(f.getAbsolutePath());
|
toLoad.add(f.getAbsolutePath());
|
||||||
FileOutputStream fout = new FileOutputStream(f);
|
FileOutputStream fout = new FileOutputStream(f);
|
||||||
byte[] buff = new byte[1024 * 100];
|
byte[] buff = new byte[1024 * 100];
|
||||||
for (int k = 0; (k = inputStream.read(buff)) > 0; ) {
|
for (int k = 0; (k = inputStream.read(buff)) > 0;) {
|
||||||
fout.write(buff, 0, k);
|
fout.write(buff, 0, k);
|
||||||
}
|
}
|
||||||
fout.close();
|
fout.close();
|
||||||
@@ -84,7 +85,7 @@ public class YJSClassLoader extends URLClassLoader {
|
|||||||
|
|
||||||
private void addDirToPath(String s) {
|
private void addDirToPath(String s) {
|
||||||
try {
|
try {
|
||||||
// System.out.println("[YJSClassloader] addtopath:" + s);
|
// System.out.println("[YJSClassloader] addtopath:" + s);
|
||||||
Field field = ClassLoader.class.getDeclaredField("sys_paths");
|
Field field = ClassLoader.class.getDeclaredField("sys_paths");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
String[] path = (String[]) field.get(null);
|
String[] path = (String[]) field.get(null);
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package org.bdware.sc.engine;
|
|||||||
import wrp.jdk.nashorn.api.scripting.ClassFilter;
|
import wrp.jdk.nashorn.api.scripting.ClassFilter;
|
||||||
|
|
||||||
public class YJSFilter implements ClassFilter {
|
public class YJSFilter implements ClassFilter {
|
||||||
@Override
|
@Override
|
||||||
public boolean exposeToScripts(String arg0) {
|
public boolean exposeToScripts(String arg0) {
|
||||||
return true;
|
return true;
|
||||||
//return arg0.compareTo("java.io.File") != 0;
|
// return arg0.compareTo("java.io.File") != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ArgPacks;
|
import org.bdware.sc.node.ArgPacks;
|
||||||
@@ -42,22 +43,22 @@ public class AccessHandler implements AnnotationHook {
|
|||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
if (requireSign) {
|
if (requireSign) {
|
||||||
if (!argPacks.request.verifySignature()) {
|
if (!verifyRequest(argPacks)) {
|
||||||
throw new ScriptReturnException(JsonParser.parseString("{\"code\":400,\"msg\":\"permission denied\"}"));
|
throw new ScriptReturnException(
|
||||||
|
JsonParser.parseString("{\"code\":400,\"msg\":\"permission denied\"}"));
|
||||||
}
|
}
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
if (!argPacks.request.verifySignature()) {
|
if (!verifyRequest(argPacks)) {
|
||||||
LOGGER.info("verify failed! clear requester," + argPacks.request.getContentStr() +
|
LOGGER.info("verify failed! clear requester," + argPacks.request.getContentStr()
|
||||||
" -> " + argPacks.request.getPublicKey() + "sign:" + argPacks.request.getSignature());
|
+ " -> " + argPacks.request.getPublicKey() + "sign:"
|
||||||
//TODO
|
+ argPacks.request.getSignature());
|
||||||
//FIXME here!
|
argPacks.request.setRequester(null);
|
||||||
// argPacks.request.setRequester(null);
|
|
||||||
} else
|
} else
|
||||||
LOGGER.info("verify success!" + argPacks.request.getRequester());
|
LOGGER.info("verify success!" + argPacks.request.getRequester());
|
||||||
if (acFunction == null) return argPacks;
|
if (acFunction == null)
|
||||||
|
return argPacks;
|
||||||
DesktopEngine de = (DesktopEngine) desktopEngine;
|
DesktopEngine de = (DesktopEngine) desktopEngine;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ContractRequest input = argPacks.request;
|
ContractRequest input = argPacks.request;
|
||||||
JO jo = new JO(PropertyMap.newMap());
|
JO jo = new JO(PropertyMap.newMap());
|
||||||
@@ -76,4 +77,11 @@ public class AccessHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean verifyRequest(ArgPacks argPacks) {
|
||||||
|
if (argPacks.arg != null && argPacks.arg instanceof DoipMessagePacker) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return argPacks.request.verifySignature();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,15 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
public ArgSchemaHandler(AnnotationNode annoNode) {
|
public ArgSchemaHandler(AnnotationNode annoNode) {
|
||||||
a = annoNode;
|
a = annoNode;
|
||||||
String arg = a.getArgs().get(0);
|
String arg = a.getArgs().get(0);
|
||||||
// if (arg.startsWith("/")){
|
// if (arg.startsWith("/")){
|
||||||
// ;//ContractProcess.instance.engine.getResources().loadAsString(arg);
|
// ;//ContractProcess.instance.engine.getResources().loadAsString(arg);
|
||||||
// }else {
|
// }else {
|
||||||
// ;
|
// ;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArgSchemaHandler fromAnnotationNode(FunctionNode funNode, AnnotationNode annoNode) {
|
public static ArgSchemaHandler fromAnnotationNode(FunctionNode funNode,
|
||||||
|
AnnotationNode annoNode) {
|
||||||
return new ArgSchemaHandler(annoNode);
|
return new ArgSchemaHandler(annoNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
try {
|
try {
|
||||||
JsonElement obj = JsonParser.parseString(input.getArg().getAsString());
|
JsonElement obj = JsonParser.parseString(input.getArg().getAsString());
|
||||||
visitor = new ArgSchemaVisitor(obj);
|
visitor = new ArgSchemaVisitor(obj);
|
||||||
//IMPORTANT automatically convert arg type here
|
// IMPORTANT automatically convert arg type here
|
||||||
input.setArg(obj);
|
input.setArg(obj);
|
||||||
argPacks.arg = obj;
|
argPacks.arg = obj;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -65,6 +66,7 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
jo.addProperty("msg", visitor.getException());
|
jo.addProperty("msg", visitor.getException());
|
||||||
jo.addProperty("code", visitor.errorCode);
|
jo.addProperty("code", visitor.errorCode);
|
||||||
|
jo.add("argSchema", JsonParser.parseString(a.getArgs().get(0)));
|
||||||
throw new ScriptReturnException(jo);
|
throw new ScriptReturnException(jo);
|
||||||
}
|
}
|
||||||
return argPacks;
|
return argPacks;
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
package org.bdware.sc.engine.hook;
|
package org.bdware.sc.engine.hook;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import org.bdware.mockjava.JsonVisitor;
|
import org.bdware.mockjava.JsonVisitor;
|
||||||
|
|
||||||
public class ArgSchemaVisitor extends JsonVisitor {
|
public class ArgSchemaVisitor extends JsonVisitor {
|
||||||
JsonElement root;
|
JsonElement root;
|
||||||
public boolean status = true;
|
public boolean status = true;
|
||||||
public int errorCode = 0;
|
public int errorCode = 0;
|
||||||
//{"msg":"xxx","code":1000}
|
// {"msg":"xxx","code":1000}
|
||||||
//
|
//
|
||||||
// JsonElement message = new JsonPrimitive("");
|
// JsonElement message = new JsonPrimitive("");
|
||||||
public String message = "";
|
public String message = "";
|
||||||
|
|
||||||
public ArgSchemaVisitor(JsonElement ret) {
|
public ArgSchemaVisitor(JsonElement ret) {
|
||||||
@@ -21,13 +18,13 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonVisitor visitObject(JsonObject schema) {
|
public JsonVisitor visitObject(JsonObject schema) {
|
||||||
//message = new JsonObject();
|
// message = new JsonObject();
|
||||||
if (root.isJsonObject()) {
|
if (root.isJsonObject()) {
|
||||||
JsonObject jo = root.getAsJsonObject();
|
JsonObject jo = root.getAsJsonObject();
|
||||||
for (String key : schema.keySet()) {
|
for (String key : schema.keySet()) {
|
||||||
if (key.startsWith("!")) {
|
if (key.startsWith("!")) {
|
||||||
//TODO
|
// TODO
|
||||||
//if(必選)
|
// if(必選)
|
||||||
if (jo.has(key.substring(1))) {
|
if (jo.has(key.substring(1))) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key.substring(1)));
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key.substring(1)));
|
||||||
visitor.visit(schema.get(key));
|
visitor.visit(schema.get(key));
|
||||||
@@ -37,12 +34,12 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
}
|
}
|
||||||
status &= visitor.status;
|
status &= visitor.status;
|
||||||
} else {
|
} else {
|
||||||
message += "[Missing argument] " + key.substring(1) + " should be supplied ";
|
message += "[Missing key] " + key.substring(1) + " should be supplied ";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1002;
|
errorCode = 1002;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jo.has(key)) {
|
if (jo.has(key) && jo.get(key) != null && jo.get(key) != JsonNull.INSTANCE) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key));
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key));
|
||||||
visitor.visit(schema.get(key));
|
visitor.visit(schema.get(key));
|
||||||
if (!visitor.status) {
|
if (!visitor.status) {
|
||||||
@@ -87,12 +84,13 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
String type = primitive.getAsString();
|
String type = primitive.getAsString();
|
||||||
try {
|
try {
|
||||||
String result = "";
|
String result = "";
|
||||||
//md5不需要参数
|
// md5不需要参数
|
||||||
if (type.equals("string")) {
|
if (type.equals("string")) {
|
||||||
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isString()) {
|
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isString()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be string";
|
message = "[Type error] The value ("
|
||||||
|
+ root.getAsJsonPrimitive().getAsString() + ") should be string";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
return this;
|
return this;
|
||||||
@@ -101,7 +99,8 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isNumber()) {
|
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isNumber()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be number";
|
message = "[Type error] The value ("
|
||||||
|
+ root.getAsJsonPrimitive().getAsString() + ") should be number";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
return this;
|
return this;
|
||||||
@@ -110,7 +109,8 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isBoolean()) {
|
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isBoolean()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be boolean";
|
message = "[Type error] The value ("
|
||||||
|
+ root.getAsJsonPrimitive().getAsString() + ") should be boolean";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
return this;
|
return this;
|
||||||
@@ -119,7 +119,8 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (root.isJsonArray()) {
|
if (root.isJsonArray()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be array";
|
message = "[Type error] The value ("
|
||||||
|
+ root.getAsJsonPrimitive().getAsString() + ") should be array";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
return this;
|
return this;
|
||||||
@@ -128,7 +129,8 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (root.isJsonObject()) {
|
if (root.isJsonObject()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be object";
|
message = "[Type error] The value ("
|
||||||
|
+ root.getAsJsonPrimitive().getAsString() + ") should be object";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ public class ConfidentialHandler implements AnnotationHook {
|
|||||||
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
||||||
ConfidentialContractUtil.copyTemplateToDestination(input);
|
ConfidentialContractUtil.copyTemplateToDestination(input);
|
||||||
ScriptObjectMirror globalVars = (ScriptObjectMirror) desktopEngine.get("Global");
|
ScriptObjectMirror globalVars = (ScriptObjectMirror) desktopEngine.get("Global");
|
||||||
ConfidentialContractUtil.dumpScriptAndStates(
|
ConfidentialContractUtil.dumpScriptAndStates(desktopEngine.engine, fun, input,
|
||||||
desktopEngine.engine, fun, input, globalVars);
|
globalVars);
|
||||||
// run in SGX instead of Nashorn if function has @Confidential annotation
|
// run in SGX instead of Nashorn if function has @Confidential annotation
|
||||||
argPacks.ret = ConfidentialContractUtil.executeConfidentialContract(input);
|
argPacks.ret = ConfidentialContractUtil.executeConfidentialContract(input);
|
||||||
return argPacks;
|
return argPacks;
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package org.bdware.sc.engine.hook;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.bdware.doip.codec.doipMessage.*;
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
import org.bdware.doip.codec.operations.BasicOperations;
|
import org.bdware.doip.codec.operations.BasicOperations;
|
||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
|
||||||
import org.bdware.sc.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.conn.ByteUtil;
|
||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
import org.bdware.sc.node.ArgPacks;
|
import org.bdware.sc.node.ArgPacks;
|
||||||
@@ -16,76 +17,47 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DOOPAfterExecHandler implements AnnotationHook {
|
public class DOOPAfterExecHandler implements AnnotationHook {
|
||||||
public static Map<String, BasicOperations> funcNameToDoipOperations;
|
private JsonElement jsonResponseRules;
|
||||||
public static DOOPAfterExecHandler instance;
|
|
||||||
public DOOPAfterExecHandler() {
|
|
||||||
funcNameToDoipOperations = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DOOPAfterExecHandler createDOOPHandler() {
|
public DOOPAfterExecHandler(BasicOperations operations) {
|
||||||
if(instance == null) {
|
jsonResponseRules = getRulesForJsonResponse(operations);
|
||||||
instance = new DOOPAfterExecHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putFuncNameAndDoipOperationsMapping(FunctionNode fn) {
|
|
||||||
String basicOperationsString = fn.getDoipOperationInfo().operationType;
|
|
||||||
BasicOperations operation = BasicOperations.Unknown;
|
|
||||||
for(BasicOperations basicOperation : BasicOperations.values()) {
|
|
||||||
if(basicOperation.toString().equals(basicOperationsString)) {
|
|
||||||
operation = basicOperation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
funcNameToDoipOperations.put(fn.getFunctionName(), operation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
BasicOperations curOp = funcNameToDoipOperations.get(argPacks.request.getAction());
|
|
||||||
Object originDoipMsgPacker = argPacks.arg;
|
Object originDoipMsgPacker = argPacks.arg;
|
||||||
DoipMessage originDoipMsg = null;
|
DoipMessage originDoipMsg = null;
|
||||||
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
||||||
DoipMessagePacker doipMessagePacker = (DoipMessagePacker) originDoipMsgPacker;
|
DoipMessagePacker doipMessagePacker = (DoipMessagePacker) originDoipMsgPacker;
|
||||||
originDoipMsg = doipMessagePacker.rawDoipMsg;
|
originDoipMsg = doipMessagePacker.rawDoipMsg;
|
||||||
|
|
||||||
// if http, directly return
|
// if http, directly return
|
||||||
if (doipMessagePacker.source.equals("http")) {
|
if (doipMessagePacker.source.equals("http")) {
|
||||||
|
if (argPacks.ret != null && argPacks.ret instanceof DoipMessage) {
|
||||||
|
argPacks.ret = JsonUtil.parseObject(
|
||||||
|
JsonDoipMessage.fromDoipMessage((DoipMessage) argPacks.ret));
|
||||||
|
}
|
||||||
return argPacks;
|
return argPacks;
|
||||||
} else {
|
} else {
|
||||||
// pack
|
// pack
|
||||||
JsonObject jsonObjectRes = JSONTool.convertMirrorToJson(argPacks.ret).getAsJsonObject();
|
if (!(argPacks.ret instanceof DoipMessage)) {
|
||||||
|
JsonObject jsonObjectRes = ((JsonElement) argPacks.ret).getAsJsonObject();
|
||||||
// validate json response
|
if (!jsonObjectRes.has("bodyBase64Encoded")
|
||||||
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
|
|| jsonObjectRes.get("bodyBase64Encoded").getAsBoolean() == true) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes);
|
if (jsonObjectRes.has("body")) {
|
||||||
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
String body = jsonObjectRes.get("body").getAsString();
|
||||||
|
jsonObjectRes.addProperty("body",
|
||||||
JsonObject header = jsonObjectRes.get("header") != null ? jsonObjectRes.get("header").getAsJsonObject() : null;
|
ByteUtil.encodeBASE64(body.getBytes(StandardCharsets.UTF_8)));
|
||||||
String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null;
|
}
|
||||||
|
|
||||||
// 和HTTP一样,所有需要的字段自己封装,校验规则也比较简单,这里只做简单的包装返回即可!!!
|
|
||||||
if(header != null) {
|
|
||||||
originDoipMsg.header = JsonUtil.fromJson(header, MessageHeader.class);
|
|
||||||
// response字段根据白皮书上的规定,处于header下,人为包装到parameters的response中
|
|
||||||
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null;
|
|
||||||
if(headerRespCode != null) {
|
|
||||||
if (originDoipMsg.header.parameters == null) originDoipMsg.header.parameters = new HeaderParameter(null, null);
|
|
||||||
originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode);
|
|
||||||
}
|
}
|
||||||
|
// validate json response
|
||||||
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes);
|
||||||
|
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
||||||
|
JsonDoipMessage returnedMessage =
|
||||||
|
JsonUtil.fromJson(jsonObjectRes, JsonDoipMessage.class);
|
||||||
|
argPacks.ret = returnedMessage.toResponseDoipMessage(originDoipMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(body != null) {
|
|
||||||
originDoipMsg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
argPacks.ret = originDoipMsg;
|
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -94,7 +66,6 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static JsonElement getRulesForJsonResponse(BasicOperations basicOperations) {
|
public static JsonElement getRulesForJsonResponse(BasicOperations basicOperations) {
|
||||||
switch (basicOperations) {
|
switch (basicOperations) {
|
||||||
case Hello:
|
case Hello:
|
||||||
@@ -103,9 +74,9 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
case Update:
|
case Update:
|
||||||
case Search:
|
case Search:
|
||||||
case ListOps:
|
case ListOps:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!response\":\"string\"}, \"!body\":\"string\"}");
|
|
||||||
case Delete:
|
case Delete:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!response\":\"string\"}, \"body\":\"string\"}");
|
return JsonParser.parseString(
|
||||||
|
"{\"header\":{\"response\":\"string\",\"attributes\":{}},\"body\":\"string\"}");
|
||||||
case Extension:
|
case Extension:
|
||||||
case Unknown:
|
case Unknown:
|
||||||
default:
|
default:
|
||||||
@@ -114,38 +85,39 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// old convert jsonResponse from argPack's ret to Doip response in doip chain logic
|
// old convert jsonResponse from argPack's ret to Doip response in doip chain logic
|
||||||
public static DoipMessage convertJsonResponseToDoipMessage(FunctionNode fn, JsonElement jsonResponse, DoipMessage msg) {
|
public DoipMessage convertJsonResponseToDoipMessage(FunctionNode fn, JsonElement jsonResponse,
|
||||||
BasicOperations curOp = funcNameToDoipOperations.get(fn.getFunctionName());
|
DoipMessage msg) {
|
||||||
JsonObject jsonParams = jsonResponse.getAsJsonObject();
|
JsonObject jsonParams = jsonResponse.getAsJsonObject();
|
||||||
|
|
||||||
// validate json response
|
// validate json response
|
||||||
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
|
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonResponse);
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonResponse);
|
||||||
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
||||||
|
|
||||||
JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null;
|
JsonObject header =
|
||||||
|
jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject()
|
||||||
|
: null;
|
||||||
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null;
|
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null;
|
||||||
|
|
||||||
if(header != null) {
|
if (header != null) {
|
||||||
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null;
|
String headerRespCode =
|
||||||
if(headerRespCode != null) {
|
header.get("response") != null ? header.get("response").getAsString() : null;
|
||||||
|
if (headerRespCode != null) {
|
||||||
for (DoipResponseCode responseCode : DoipResponseCode.values()) {
|
for (DoipResponseCode responseCode : DoipResponseCode.values()) {
|
||||||
if(responseCode.toString().equals(headerRespCode)) {
|
if (responseCode.toString().equals(headerRespCode)) {
|
||||||
msg.header.parameters.response = responseCode;
|
msg.header.parameters.response = responseCode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (body != null) {
|
||||||
if(body != null) {
|
|
||||||
msg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
|
msg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void validateJsonElementRulesByArgSchemaVisitor(JsonElement jsonElement, ArgSchemaVisitor visitor) {
|
public static void validateJsonElementRulesByArgSchemaVisitor(JsonElement jsonElement,
|
||||||
|
ArgSchemaVisitor visitor) {
|
||||||
visitor.visit(jsonElement);
|
visitor.visit(jsonElement);
|
||||||
if (!visitor.getStatus()) {
|
if (!visitor.getStatus()) {
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package org.bdware.sc.engine.hook;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
import org.bdware.doip.codec.doipMessage.MessageCredential;
|
||||||
import org.bdware.doip.codec.operations.BasicOperations;
|
import org.bdware.doip.codec.operations.BasicOperations;
|
||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
@@ -12,84 +13,72 @@ import org.bdware.sc.boundry.ScriptReturnException;
|
|||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
import org.bdware.sc.node.ArgPacks;
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DOOPBeforeExecHandler implements AnnotationHook {
|
public class DOOPBeforeExecHandler implements AnnotationHook {
|
||||||
public static Map<String, BasicOperations> funcNameToDoipOperations;
|
|
||||||
public static DOOPBeforeExecHandler instance;
|
|
||||||
public DOOPBeforeExecHandler() {
|
|
||||||
funcNameToDoipOperations = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DOOPBeforeExecHandler createDOOPHandler() {
|
private final BasicOperations httpOperation;
|
||||||
if(instance == null) {
|
private JsonElement httpArgsRules;
|
||||||
instance = new DOOPBeforeExecHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
public DOOPBeforeExecHandler(BasicOperations operations) {
|
||||||
}
|
httpOperation = operations;
|
||||||
|
httpArgsRules = getRulesForHTTPRequest(operations);
|
||||||
public void putFuncNameAndDoipOperationsMapping(FunctionNode fn) {
|
|
||||||
String basicOperationsString = fn.getDoipOperationInfo().operationType;
|
|
||||||
BasicOperations operation = BasicOperations.Unknown;
|
|
||||||
for(BasicOperations basicOperation : BasicOperations.values()) {
|
|
||||||
if(basicOperation.toString().equals(basicOperationsString)) {
|
|
||||||
operation = basicOperation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
funcNameToDoipOperations.put(fn.getFunctionName(), operation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
Object arg = argPacks.arg;
|
Object arg = argPacks.arg;
|
||||||
DoipMessagePacker doipMsgPackerArg = new DoipMessagePacker();
|
DoipMessagePacker doipMsgPackerArg = new DoipMessagePacker();
|
||||||
|
if (arg instanceof DoipMessagePacker) {
|
||||||
if (arg instanceof DoipMessagePacker){
|
doipMsgPackerArg = (DoipMessagePacker) arg;
|
||||||
doipMsgPackerArg = (DoipMessagePacker)arg;
|
|
||||||
} else {
|
} else {
|
||||||
// validate http request's params
|
// validate http request's params
|
||||||
ContractRequest httpReq = argPacks.request;
|
ContractRequest httpReq = argPacks.request;
|
||||||
validateHTTPRequestArgs(httpReq);
|
validateHTTPRequestArgs(httpReq);
|
||||||
|
|
||||||
// set doipMsgPackerArg struct's params
|
// set doipMsgPackerArg struct's params
|
||||||
doipMsgPackerArg.setSource("http");
|
doipMsgPackerArg.setSource("http");
|
||||||
doipMsgPackerArg.rawDoipMsg = convertHttpRequestToDoipMessage(httpReq);
|
doipMsgPackerArg.rawDoipMsg = convertHttpRequestToDoipMessage(httpReq);
|
||||||
|
|
||||||
|
if (httpReq.verifySignature()) {
|
||||||
|
doipMsgPackerArg.rawDoipMsg.credential =
|
||||||
|
new MessageCredential(httpReq.getRequester(), new byte[0]);
|
||||||
|
} else {
|
||||||
|
doipMsgPackerArg.rawDoipMsg.credential = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
argPacks.arg = doipMsgPackerArg;
|
argPacks.arg = doipMsgPackerArg;
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void validateHTTPRequestArgs(ContractRequest httpReq) {
|
public void validateHTTPRequestArgs(ContractRequest httpReq) {
|
||||||
JsonElement originArgs = httpReq.getArg();
|
JsonElement originArgs = httpReq.getArg();
|
||||||
JsonElement httpArgs = JsonParser.parseString(originArgs.getAsString());
|
JsonElement httpArgs = null;
|
||||||
BasicOperations curOp = funcNameToDoipOperations.get(httpReq.getAction());
|
if (originArgs.isJsonObject())
|
||||||
|
httpArgs = originArgs;
|
||||||
|
else
|
||||||
|
httpArgs = JsonParser.parseString(originArgs.getAsString());
|
||||||
// get args rules and validate http args
|
// get args rules and validate http args
|
||||||
JsonElement httpArgsRules = getRulesForHTTPRequest(curOp);
|
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs);
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs);
|
||||||
validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor);
|
validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonElement getRulesForHTTPRequest(BasicOperations basicOperation) {
|
public static JsonElement getRulesForHTTPRequest(BasicOperations basicOperation) {
|
||||||
switch(basicOperation) {
|
switch (basicOperation) {
|
||||||
case Hello:
|
case Hello:
|
||||||
case Delete:
|
case Delete:
|
||||||
case ListOps:
|
case ListOps:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!identifier\":\"string\"}}");
|
return JsonParser.parseString("{\"!header\":{\"!identifier\":\"string\"}}");
|
||||||
case Create:
|
case Create:
|
||||||
case Update:
|
case Update:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!identifier\":\"string\"}, \"!body\":\"string\"}");
|
return JsonParser.parseString(
|
||||||
|
"{\"!header\":{\"!identifier\":\"string\"}, \"!body\":\"string\"}");
|
||||||
case Search:
|
case Search:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!identifier\":\"string\", \"!attributes\":{\"!query\":\"string\", \"!pageNum\":\"int\", \"!pageSize\":\"int\", \"!type\":\"string\"}}}");
|
return JsonParser.parseString(
|
||||||
|
"{\"!header\":{\"!identifier\":\"string\", \"!attributes\":{\"!query\":\"string\", \"!pageNum\":\"int\", \"!pageSize\":\"int\", \"!type\":\"string\"}}}");
|
||||||
case Retrieve:
|
case Retrieve:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!identifier\":\"string\", \"attributes\":{\"element\":\"string\", \"includeElementData\":\"boolean\"}}}");
|
return JsonParser.parseString(
|
||||||
|
"{\"!header\":{\"!identifier\":\"string\", \"attributes\":{\"element\":\"string\", \"includeElementData\":\"boolean\"}}}");
|
||||||
case Extension:
|
case Extension:
|
||||||
case Unknown:
|
case Unknown:
|
||||||
default:
|
default:
|
||||||
@@ -97,77 +86,18 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) {
|
public DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) {
|
||||||
BasicOperations httpOperation = funcNameToDoipOperations.get(httpReq.getAction());
|
JsonElement arg = httpReq.getArg();
|
||||||
JsonObject jsonParams = JsonParser.parseString(httpReq.getArg().getAsString()).getAsJsonObject();
|
if (!arg.isJsonObject()) {
|
||||||
// taking Extension into consideration
|
arg = JsonParser.parseString(arg.getAsString());
|
||||||
JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null;
|
|
||||||
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null;
|
|
||||||
DoipMessage doipMessage = null;
|
|
||||||
switch(httpOperation) {
|
|
||||||
case Hello:
|
|
||||||
case Delete:
|
|
||||||
case ListOps:
|
|
||||||
doipMessage = new DoipMessageFactory.DoipMessageBuilder().createRequest(header.get("identifier").getAsString(), httpOperation.getName()).create();
|
|
||||||
break;
|
|
||||||
case Create:
|
|
||||||
case Update:
|
|
||||||
doipMessage = new DoipMessageFactory.DoipMessageBuilder()
|
|
||||||
.createRequest(header.get("identifier").getAsString(), httpOperation.getName())
|
|
||||||
.setBody(body.getBytes(StandardCharsets.UTF_8))
|
|
||||||
.create();
|
|
||||||
break;
|
|
||||||
case Search:
|
|
||||||
DoipMessageFactory.DoipMessageBuilder searchBuilder = new DoipMessageFactory.DoipMessageBuilder()
|
|
||||||
.createRequest(header.get("identifier").getAsString(), httpOperation.getName());
|
|
||||||
JsonElement query = header.get("query");
|
|
||||||
if(query != null) searchBuilder.addAttributes("query", query.getAsString());
|
|
||||||
JsonElement pageNum = header.get("pageNum");
|
|
||||||
if(pageNum != null) searchBuilder.addAttributes("pageNum", pageNum.getAsInt());
|
|
||||||
JsonElement pageSize = header.get("pageSize");
|
|
||||||
if(pageSize != null) searchBuilder.addAttributes("pageSize", pageSize.getAsInt());
|
|
||||||
JsonElement type = header.get("type");
|
|
||||||
if(type != null) searchBuilder.addAttributes("type", type.getAsString());
|
|
||||||
|
|
||||||
doipMessage = searchBuilder.create();
|
|
||||||
break;
|
|
||||||
case Retrieve:
|
|
||||||
doipMessage = new DoipMessageFactory.DoipMessageBuilder().createRequest(header.get("identifier").getAsString(), httpOperation.getName()).create();
|
|
||||||
JsonElement element = header.get("element");
|
|
||||||
JsonElement includeElementData = header.get("includeElementData");
|
|
||||||
if(element != null) doipMessage.header.parameters.addAttribute("element", element.getAsString());
|
|
||||||
if(includeElementData != null && includeElementData.getAsBoolean()) doipMessage.header.parameters.addAttribute("includeElementData", "true");
|
|
||||||
break;
|
|
||||||
case Extension:
|
|
||||||
DoipMessageFactory.DoipMessageBuilder extensionBuilder = new DoipMessageFactory.DoipMessageBuilder();
|
|
||||||
if(header != null) {
|
|
||||||
if(header.get("identifier") != null) {
|
|
||||||
extensionBuilder = extensionBuilder
|
|
||||||
.createRequest(header.get("identifier").getAsString(), httpOperation.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Map.Entry<String, JsonElement>> entries = header.entrySet();
|
|
||||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
|
||||||
extensionBuilder.addAttributes(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(body != null) {
|
|
||||||
extensionBuilder.setBody(body.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
doipMessage = extensionBuilder.create();
|
|
||||||
break;
|
|
||||||
case Unknown:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
JsonDoipMessage doipMessage = JsonUtil.fromJson(arg, JsonDoipMessage.class);
|
||||||
return doipMessage;
|
return doipMessage.toRequestDoipMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void validateJsonElementRulesByArgSchemaVisitor(JsonElement jsonElement, ArgSchemaVisitor visitor) {
|
public static void validateJsonElementRulesByArgSchemaVisitor(JsonElement jsonElement,
|
||||||
|
ArgSchemaVisitor visitor) {
|
||||||
visitor.visit(jsonElement);
|
visitor.visit(jsonElement);
|
||||||
if (!visitor.getStatus()) {
|
if (!visitor.getStatus()) {
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class HomoVisitor extends JsonVisitor {
|
|||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,25 +27,25 @@ public class HomomorphicDecryptHandler implements AnnotationHook {
|
|||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
// GetHomArgs args =
|
// GetHomArgs args =
|
||||||
// new GetHomArgs(
|
// new GetHomArgs(
|
||||||
// input.getRequester(), this.fun.getSecretID().replaceAll("\"", ""));
|
// input.getRequester(), this.fun.getSecretID().replaceAll("\"", ""));
|
||||||
// String arg = JsonUtil.toJson(args);
|
// String arg = JsonUtil.toJson(args);
|
||||||
JsonElement homoDecryptConf = this.fun.getHomoDecryptConf();
|
JsonElement homoDecryptConf = this.fun.getHomoDecryptConf();
|
||||||
if (null != homoDecryptConf && !homoDecryptConf.isJsonNull()) {
|
if (null != homoDecryptConf && !homoDecryptConf.isJsonNull()) {
|
||||||
String res = (String)
|
String res = (String) JavaScriptEntry.executeContract("keyManager_1", "getPrivKey",
|
||||||
JavaScriptEntry.executeContract(
|
this.fun.getSecretID().replaceAll("\"", ""));
|
||||||
"keyManager_1",
|
|
||||||
"getPrivKey",
|
|
||||||
this.fun.getSecretID().replaceAll("\"", ""));
|
|
||||||
LOGGER.info("HomomorphicDecryptHandler--------------------------------1: " + res);
|
LOGGER.info("HomomorphicDecryptHandler--------------------------------1: " + res);
|
||||||
ContractResult results = JsonUtil.fromJson(res, ContractResult.class);
|
ContractResult results = JsonUtil.fromJson(res, ContractResult.class);
|
||||||
String privKeyStr = results.result.getAsString();
|
String privKeyStr = results.result.getAsString();
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------2: " + privKeyStr);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------2: "
|
||||||
|
+ privKeyStr);
|
||||||
RSAPrivateKey privkey = (RSAPrivateKey) PaillierKeyPair.pemToPrivateKey(privKeyStr);
|
RSAPrivateKey privkey = (RSAPrivateKey) PaillierKeyPair.pemToPrivateKey(privKeyStr);
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------3: " + privkey);
|
LOGGER.info(
|
||||||
|
"HomomorphicEncryptHandler--------------------------------3: " + privkey);
|
||||||
HomoVisitor.privateKey = privkey;
|
HomoVisitor.privateKey = privkey;
|
||||||
argPacks.ret = getDecryptResult(homoDecryptConf, JsonUtil.parseObject(argPacks.ret));
|
argPacks.ret =
|
||||||
|
getDecryptResult(homoDecryptConf, JsonUtil.parseObject(argPacks.ret));
|
||||||
if (null != argPacks.ret) {
|
if (null != argPacks.ret) {
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,36 +29,36 @@ public class HomomorphicEncryptHandler implements AnnotationHook {
|
|||||||
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
ContractRequest input = argPacks.request;
|
ContractRequest input = argPacks.request;
|
||||||
LOGGER.info(
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------1: "
|
||||||
"HomomorphicEncryptHandler--------------------------------1: "
|
+ input.getRequester());
|
||||||
+ input.getRequester());
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------2: "
|
||||||
LOGGER.info(
|
+ this.fun.getSecretID());
|
||||||
"HomomorphicEncryptHandler--------------------------------2: "
|
|
||||||
+ this.fun.getSecretID());
|
|
||||||
JsonElement response = (JsonElement) argPacks.ret;
|
JsonElement response = (JsonElement) argPacks.ret;
|
||||||
JsonElement homoEncryptConf = this.fun.getHomoEncryptConf();
|
JsonElement homoEncryptConf = this.fun.getHomoEncryptConf();
|
||||||
if (homoEncryptConf != null && !homoEncryptConf.isJsonNull()) {
|
if (homoEncryptConf != null && !homoEncryptConf.isJsonNull()) {
|
||||||
String res =
|
String res = (String) JavaScriptEntry.executeContract("keyManager_1", "getPubKey",
|
||||||
(String) JavaScriptEntry.executeContract(
|
this.fun.getSecretID().replaceAll("\"", ""));
|
||||||
"keyManager_1",
|
// String res =
|
||||||
"getPubKey",
|
// JavaScriptEntry.executeContract(
|
||||||
this.fun.getSecretID().replaceAll("\"", ""));
|
// this.fun.getKeyManagerID(),
|
||||||
// String res =
|
// "getPubKey",
|
||||||
// JavaScriptEntry.executeContract(
|
// this.fun.getSecretID().replaceAll("\"", ""));
|
||||||
// this.fun.getKeyManagerID(),
|
|
||||||
// "getPubKey",
|
|
||||||
// this.fun.getSecretID().replaceAll("\"", ""));
|
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------4: " + res);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------4: " + res);
|
||||||
ContractResult results = JsonUtil.fromJson(res, ContractResult.class);
|
ContractResult results = JsonUtil.fromJson(res, ContractResult.class);
|
||||||
String pubKeyStr = results.result.getAsString();
|
String pubKeyStr = results.result.getAsString();
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------5: " + pubKeyStr);
|
LOGGER.info(
|
||||||
|
"HomomorphicEncryptHandler--------------------------------5: " + pubKeyStr);
|
||||||
HomoVisitor.publicKey = (RSAPublicKey) PaillierKeyPair.pemToPublicKey(pubKeyStr);
|
HomoVisitor.publicKey = (RSAPublicKey) PaillierKeyPair.pemToPublicKey(pubKeyStr);
|
||||||
// if (homoEncryptConf.getAsJsonPrimitive().isString())
|
// if (homoEncryptConf.getAsJsonPrimitive().isString())
|
||||||
// homoEncryptConf = JsonParser.parseString(homoEncryptConf.getAsString());
|
// homoEncryptConf = JsonParser.parseString(homoEncryptConf.getAsString());
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------6: " + homoEncryptConf);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------6: "
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------7: " + argPacks.ret);
|
+ homoEncryptConf);
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------8: " + argPacks.ret.toString());
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------7: "
|
||||||
// LOGGER.info("HomomorphicEncryptHandler--------------------------------9: " + JsonUtil.toJson(ret));
|
+ argPacks.ret);
|
||||||
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------8: "
|
||||||
|
+ argPacks.ret.toString());
|
||||||
|
// LOGGER.info("HomomorphicEncryptHandler--------------------------------9: " +
|
||||||
|
// JsonUtil.toJson(ret));
|
||||||
argPacks.ret = getEncryptResult(homoEncryptConf, response);
|
argPacks.ret = getEncryptResult(homoEncryptConf, response);
|
||||||
if (argPacks.ret != null) {
|
if (argPacks.ret != null) {
|
||||||
return argPacks;
|
return argPacks;
|
||||||
@@ -73,9 +73,9 @@ public class HomomorphicEncryptHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object getEncryptResult(JsonElement homoEncryptConf, JsonElement data) {
|
private Object getEncryptResult(JsonElement homoEncryptConf, JsonElement data) {
|
||||||
// if (null == homoEncryptConf || homoEncryptConf.getAsString().isEmpty()) {
|
// if (null == homoEncryptConf || homoEncryptConf.getAsString().isEmpty()) {
|
||||||
// return data;
|
// return data;
|
||||||
// }
|
// }
|
||||||
if (null == homoEncryptConf) {
|
if (null == homoEncryptConf) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ public class MaskHandler implements AnnotationHook {
|
|||||||
if (null != maskConf) {
|
if (null != maskConf) {
|
||||||
LOGGER.debug("execute maskConf: " + maskConf);
|
LOGGER.debug("execute maskConf: " + maskConf);
|
||||||
String s1 = ret.toString();
|
String s1 = ret.toString();
|
||||||
//budeijin
|
// budeijin
|
||||||
//"{\"count\":1}"
|
// "{\"count\":1}"
|
||||||
//{"count":1}
|
// {"count":1}
|
||||||
//System.out.println(s1);
|
// System.out.println(s1);
|
||||||
s1 = s1.replace("\\", "");
|
s1 = s1.replace("\\", "");
|
||||||
s1 = s1.substring(1, s1.length() - 1);
|
s1 = s1.substring(1, s1.length() - 1);
|
||||||
//System.out.println(s1);
|
// System.out.println(s1);
|
||||||
//System.out.println(JsonParser.parseString(s1));
|
// System.out.println(JsonParser.parseString(s1));
|
||||||
MaskVisitor visitor = new MaskVisitor(JsonParser.parseString(s1));
|
MaskVisitor visitor = new MaskVisitor(JsonParser.parseString(s1));
|
||||||
visitor.visit(maskConf);
|
visitor.visit(maskConf);
|
||||||
ret = visitor.get();
|
ret = visitor.get();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class MaskVisitor extends JsonVisitor {
|
|||||||
JsonObject jo = root.getAsJsonObject();
|
JsonObject jo = root.getAsJsonObject();
|
||||||
for (String key : mask.keySet()) {
|
for (String key : mask.keySet()) {
|
||||||
if (jo.has(key)) {
|
if (jo.has(key)) {
|
||||||
//TODO
|
// TODO
|
||||||
MaskVisitor visitor = new MaskVisitor(jo.get(key));
|
MaskVisitor visitor = new MaskVisitor(jo.get(key));
|
||||||
visitor.visit(mask.get(key));
|
visitor.visit(mask.get(key));
|
||||||
jo.add(key, visitor.get());
|
jo.add(key, visitor.get());
|
||||||
@@ -58,7 +58,7 @@ public class MaskVisitor extends JsonVisitor {
|
|||||||
String method = primitive.getAsString();
|
String method = primitive.getAsString();
|
||||||
try {
|
try {
|
||||||
String result = "";
|
String result = "";
|
||||||
//md5不需要参数
|
// md5不需要参数
|
||||||
if (method.equals("md5")) {
|
if (method.equals("md5")) {
|
||||||
MD5EncryptionImpl masker = new MD5EncryptionImpl();
|
MD5EncryptionImpl masker = new MD5EncryptionImpl();
|
||||||
result = masker.execute(root.getAsString());
|
result = masker.execute(root.getAsString());
|
||||||
@@ -69,7 +69,7 @@ public class MaskVisitor extends JsonVisitor {
|
|||||||
FormatPreservingEncryptionImpl masker = new FormatPreservingEncryptionImpl();
|
FormatPreservingEncryptionImpl masker = new FormatPreservingEncryptionImpl();
|
||||||
result = masker.execute(root.getAsString());
|
result = masker.execute(root.getAsString());
|
||||||
}
|
}
|
||||||
//edp需要精度的参数
|
// edp需要精度的参数
|
||||||
else if (method.equals("edp")) {
|
else if (method.equals("edp")) {
|
||||||
EpsilonDifferentialPrivacyImpl masker = new EpsilonDifferentialPrivacyImpl();
|
EpsilonDifferentialPrivacyImpl masker = new EpsilonDifferentialPrivacyImpl();
|
||||||
double epsilon = 1;
|
double epsilon = 1;
|
||||||
@@ -87,11 +87,11 @@ public class MaskVisitor extends JsonVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//String result = masker.execute(primitive.toString());
|
// String result = masker.execute(primitive.toString());
|
||||||
//System.out.println(result);
|
// System.out.println(result);
|
||||||
|
|
||||||
//root = new JsonPrimitive(root.getAsString().substring(0, 2));
|
// root = new JsonPrimitive(root.getAsString().substring(0, 2));
|
||||||
//https://github.com/guohf/DataX-Masking
|
// https://github.com/guohf/DataX-Masking
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ public class MockTemplateHandler implements AnnotationHook {
|
|||||||
MockUtil Mock = new MockUtil();
|
MockUtil Mock = new MockUtil();
|
||||||
argPacks.ret = Mock.mock(template).toString();
|
argPacks.ret = Mock.mock(template).toString();
|
||||||
return argPacks;
|
return argPacks;
|
||||||
} else return argPacks; //When mock config is null defined just ignore.
|
} else
|
||||||
|
return argPacks; // When mock config is null defined just ignore.
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.bdware.sc.engine.hook;
|
package org.bdware.sc.engine.hook;
|
||||||
|
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
@@ -8,6 +9,8 @@ import org.bdware.sc.node.ArgPacks;
|
|||||||
public class ObjToJsonHandler implements AnnotationHook {
|
public class ObjToJsonHandler implements AnnotationHook {
|
||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
|
if (argPacks.ret instanceof DoipMessage)
|
||||||
|
return argPacks;
|
||||||
argPacks.ret = JSONTool.convertMirrorToJson(argPacks.ret);
|
argPacks.ret = JSONTool.convertMirrorToJson(argPacks.ret);
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ import org.commonmark.parser.Parser;
|
|||||||
|
|
||||||
public class ReadMeHandler implements AnnotationHook {
|
public class ReadMeHandler implements AnnotationHook {
|
||||||
String getReadMeData(DesktopEngine desktopEngine, ContractRequest c) {
|
String getReadMeData(DesktopEngine desktopEngine, ContractRequest c) {
|
||||||
String fileReadme =
|
String fileReadme = desktopEngine.getResources().loadAsString("/assets/README.md"); // is
|
||||||
desktopEngine
|
// "/README.md"
|
||||||
.getResources()
|
// not"./README.md"!!!!
|
||||||
.loadAsString("/assets/README.md"); // is "/README.md" not"./README.md"!!!!
|
|
||||||
// System.out.println("fileReadme:" + fileReadme);
|
// System.out.println("fileReadme:" + fileReadme);
|
||||||
if (null == fileReadme) {
|
if (null == fileReadme) {
|
||||||
return "项目目录下无预览文档";
|
return "项目目录下无预览文档";
|
||||||
@@ -30,18 +29,11 @@ public class ReadMeHandler implements AnnotationHook {
|
|||||||
while (visitor != null) {
|
while (visitor != null) {
|
||||||
if (visitor instanceof Heading) {
|
if (visitor instanceof Heading) {
|
||||||
if (((Heading) visitor).getLevel() == 2) {
|
if (((Heading) visitor).getLevel() == 2) {
|
||||||
if (((Text) (visitor.getFirstChild()))
|
if (((Text) (visitor.getFirstChild())).getLiteral()
|
||||||
.getLiteral()
|
|
||||||
.equals(targetFunction)) {
|
.equals(targetFunction)) {
|
||||||
FencedCodeBlock blockResult =
|
FencedCodeBlock blockResult =
|
||||||
(FencedCodeBlock)
|
(FencedCodeBlock) (visitor.getNext().getNext().getNext()
|
||||||
(visitor.getNext()
|
.getNext().getNext().getNext().getNext());
|
||||||
.getNext()
|
|
||||||
.getNext()
|
|
||||||
.getNext()
|
|
||||||
.getNext()
|
|
||||||
.getNext()
|
|
||||||
.getNext());
|
|
||||||
result = blockResult.getLiteral();
|
result = blockResult.getLiteral();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package org.bdware.sc.engine.hook;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.sc.JSEngine;
|
||||||
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
|
@YJSAnnotation(name = "ResultSchema")
|
||||||
|
public class ResultSchemaHandler implements AnnotationHook {
|
||||||
|
private AnnotationNode a;
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(ResultSchemaHandler.class);
|
||||||
|
|
||||||
|
public ResultSchemaHandler(AnnotationNode annotationNode) {
|
||||||
|
a = annotationNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) throws ScriptReturnException {
|
||||||
|
Object ret = argPacks.ret;
|
||||||
|
if (ret != null) {
|
||||||
|
JsonElement je = null;
|
||||||
|
if (ret instanceof DoipMessage) {
|
||||||
|
JsonDoipMessage jo = JsonDoipMessage.fromDoipMessage((DoipMessage) ret);
|
||||||
|
je = JsonUtil.parseObjectAsJsonObject(jo);
|
||||||
|
} else if (ret instanceof JsonElement) {
|
||||||
|
je = (JsonElement) ret;
|
||||||
|
}
|
||||||
|
if (je == null) {
|
||||||
|
JsonObject jo = new JsonObject();
|
||||||
|
jo.addProperty("msg", "[Illegal Type] result should not be empty or null");
|
||||||
|
jo.addProperty("code", 1004);
|
||||||
|
throw new ScriptReturnException(jo);
|
||||||
|
}
|
||||||
|
ArgSchemaVisitor visitor;
|
||||||
|
if (je.isJsonObject())
|
||||||
|
visitor = new ArgSchemaVisitor(je.getAsJsonObject());
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
JsonElement obj = JsonParser.parseString(je.getAsString());
|
||||||
|
visitor = new ArgSchemaVisitor(obj);
|
||||||
|
// IMPORTANT automatically convert arg type here
|
||||||
|
argPacks.ret = obj;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
JsonObject jo = new JsonObject();
|
||||||
|
jo.addProperty("msg", "[Illegal Type] result should be JSON");
|
||||||
|
jo.add("errorResult", je);
|
||||||
|
jo.addProperty("code", 1004);
|
||||||
|
throw new ScriptReturnException(jo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (je.toString().isEmpty() && !a.getArgs().get(0).equals("")) {
|
||||||
|
JsonObject jo = new JsonObject();
|
||||||
|
jo.addProperty("msg", "[Empty result] result should not be empty");
|
||||||
|
jo.addProperty("code", 1003);
|
||||||
|
throw new ScriptReturnException(jo);
|
||||||
|
}
|
||||||
|
visitor.visit(JsonParser.parseString(a.getArgs().get(0)));
|
||||||
|
if (!visitor.getStatus()) {
|
||||||
|
JsonObject jo = new JsonObject();
|
||||||
|
jo.addProperty("msg", visitor.getException());
|
||||||
|
jo.addProperty("code", visitor.errorCode);
|
||||||
|
jo.add("errorResult", je);
|
||||||
|
jo.add("resultSchema", JsonParser.parseString(a.getArgs().get(0)));
|
||||||
|
throw new ScriptReturnException(jo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return argPacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResultSchemaHandler fromAnnotationNode(FunctionNode funNode,
|
||||||
|
AnnotationNode annoNode) {
|
||||||
|
return new ResultSchemaHandler(annoNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,7 @@ package org.bdware.sc.engine.setArgs;
|
|||||||
public class GetHomArgs {
|
public class GetHomArgs {
|
||||||
public String secretID;
|
public String secretID;
|
||||||
|
|
||||||
public GetHomArgs() {
|
public GetHomArgs() {}
|
||||||
}
|
|
||||||
|
|
||||||
public GetHomArgs(String secretID) {
|
public GetHomArgs(String secretID) {
|
||||||
this.secretID = secretID;
|
this.secretID = secretID;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.bdware.sc.entity;
|
package org.bdware.sc.entity;
|
||||||
|
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.sc.engine.JSONTool;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
public class DoipMessagePacker {
|
public class DoipMessagePacker {
|
||||||
// the DoipMessagePacker is raised by http/doip
|
// the DoipMessagePacker is raised by http/doip
|
||||||
@@ -22,4 +25,9 @@ public class DoipMessagePacker {
|
|||||||
public void setSource(String source) {
|
public void setSource(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object toJSObject() {
|
||||||
|
return JSONTool.convertJsonElementToMirror(
|
||||||
|
JsonUtil.parseObject(JsonDoipMessage.fromDoipMessage(rawDoipMsg)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ public class ContractHandler extends MsgHandler implements Runnable {
|
|||||||
|
|
||||||
@Description("set members")
|
@Description("set members")
|
||||||
public void setMembers(GetMessage msg, ResultCallback cb) {
|
public void setMembers(GetMessage msg, ResultCallback cb) {
|
||||||
cb.onResult(cs.setMembers(JsonUtil.fromJson(msg.arg, new TypeToken<List<String>>() {
|
cb.onResult(cs.setMembers(
|
||||||
}.getType())));
|
JsonUtil.fromJson(msg.arg, new TypeToken<List<String>>() {}.getType())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Description("get current contract name")
|
@Description("get current contract name")
|
||||||
|
|||||||
@@ -1,43 +1,38 @@
|
|||||||
package org.bdware.sc.handler;
|
package org.bdware.sc.handler;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
import org.bdware.doip.codec.doipMessage.HeaderParameter;
|
import org.bdware.doip.codec.doipMessage.HeaderParameter;
|
||||||
import org.bdware.doip.codec.operations.BasicOperations;
|
import org.bdware.doip.codec.operations.BasicOperations;
|
||||||
import org.bdware.doip.endpoint.server.DoipRequestHandler;
|
import org.bdware.doip.endpoint.server.DoipRequestHandler;
|
||||||
import org.bdware.doip.endpoint.server.NettyServerHandler;
|
import org.bdware.doip.endpoint.server.NettyServerHandler;
|
||||||
import org.bdware.doip.endpoint.server.RepositoryHandler;
|
|
||||||
import org.bdware.sc.ContractProcess;
|
import org.bdware.sc.ContractProcess;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
import org.bdware.sc.boundry.JavaScriptEntry;
|
import org.bdware.sc.boundry.JavaScriptEntry;
|
||||||
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
|
import org.bdware.sc.crdt.SharableVarManager;
|
||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler {
|
public class DOOPRequestHandler implements DoipRequestHandler {
|
||||||
public Map<String, FunctionNode> doipFunctionNodeMap;
|
|
||||||
static Logger logger = LogManager.getLogger(NettyServerHandler.class);
|
static Logger logger = LogManager.getLogger(NettyServerHandler.class);
|
||||||
static Gson gson;
|
public Map<String, FunctionNode> doipFunctionNodeMap;
|
||||||
|
|
||||||
public static DOOPRequestHandler instance;
|
|
||||||
|
|
||||||
public DOOPRequestHandler() {
|
public DOOPRequestHandler() {
|
||||||
doipFunctionNodeMap = new HashMap<>();
|
doipFunctionNodeMap = new HashMap<>();
|
||||||
gson = new Gson();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DOOPRequestHandler createHandler() {
|
|
||||||
if(instance == null) {
|
|
||||||
instance = new DOOPRequestHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDoipOperation(FunctionNode function) throws Exception {
|
public void addDoipOperation(FunctionNode function) throws Exception {
|
||||||
@@ -51,11 +46,16 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
|
|||||||
@Override
|
@Override
|
||||||
public DoipMessage onRequest(ChannelHandlerContext ctx, DoipMessage msg) {
|
public DoipMessage onRequest(ChannelHandlerContext ctx, DoipMessage msg) {
|
||||||
String str = msg.header.parameters.operation;
|
String str = msg.header.parameters.operation;
|
||||||
|
if (msg.header != null
|
||||||
|
&& msg.header.parameters.operation.equals(SharableVarManager.SHARABLEOP)) {
|
||||||
|
return SharableVarManager.instance.handleSyncMessage(msg);
|
||||||
|
}
|
||||||
logger.debug("[Call operation] name: " + str);
|
logger.debug("[Call operation] name: " + str);
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
FunctionNode fn;
|
FunctionNode fn;
|
||||||
fn = doipFunctionNodeMap.get(str);
|
fn = doipFunctionNodeMap.get(str);
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
if (fn == null)
|
||||||
|
fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
||||||
if (fn != null) {
|
if (fn != null) {
|
||||||
return buildRequestAndInvokeEngine(fn, msg);
|
return buildRequestAndInvokeEngine(fn, msg);
|
||||||
}
|
}
|
||||||
@@ -63,114 +63,55 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleHello(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.Hello.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation Hello is not provided");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleListOps(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.ListOps.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation ListOps is not provided");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleCreate(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.Create.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation Create is not provided");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleUpdate(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.Update.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation Update is not provided");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleDelete(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.Delete.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation Delete is not provided");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DoipMessage handleRetrieve(DoipMessage request) {
|
|
||||||
FunctionNode fn = doipFunctionNodeMap.get(BasicOperations.Retrieve.getName());
|
|
||||||
if (fn == null) fn = doipFunctionNodeMap.get(BasicOperations.Unknown.getName());
|
|
||||||
if (fn != null) {
|
|
||||||
return buildRequestAndInvokeEngine(fn, request);
|
|
||||||
} else {
|
|
||||||
logger.error("DoipOperation Retrieve is not provided");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DoipMessage buildRequestAndInvokeEngine(FunctionNode fn, DoipMessage msg) {
|
public DoipMessage buildRequestAndInvokeEngine(FunctionNode fn, DoipMessage msg) {
|
||||||
ContractRequest contractRequest = constructContractRequest(fn, msg);
|
ContractRequest contractRequest = constructContractRequest(fn, msg);
|
||||||
DoipMessagePacker arg = new DoipMessagePacker("doip", msg);
|
DoipMessagePacker arg = new DoipMessagePacker("doip", msg);
|
||||||
try {
|
try {
|
||||||
// 改变调用的函数 + 构造DoipMessagePacker
|
// 改变调用的函数 + 构造DoipMessagePacker
|
||||||
Object ret = ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg);
|
Object ret =
|
||||||
|
ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg);
|
||||||
DoipMessage finalDoipMsg = (DoipMessage) ret;
|
DoipMessage finalDoipMsg = (DoipMessage) ret;
|
||||||
finalDoipMsg.requestID = msg.requestID;
|
finalDoipMsg.requestID = msg.requestID;
|
||||||
if(finalDoipMsg.header.parameters == null) {
|
if (finalDoipMsg.header.parameters == null) {
|
||||||
finalDoipMsg.header.parameters = new HeaderParameter("", "");
|
finalDoipMsg.header.parameters = new HeaderParameter("", "");
|
||||||
}
|
}
|
||||||
if(finalDoipMsg.header.parameters.attributes == null) {
|
if (finalDoipMsg.header.parameters.attributes == null) {
|
||||||
finalDoipMsg.header.parameters.attributes = new JsonObject();
|
finalDoipMsg.header.parameters.attributes = new JsonObject();
|
||||||
}
|
}
|
||||||
finalDoipMsg.header.parameters.attributes.addProperty("nodeID", String.valueOf(JavaScriptEntry.shardingID));
|
finalDoipMsg.header.parameters.attributes.addProperty("nodeID",
|
||||||
|
String.valueOf(JavaScriptEntry.shardingID));
|
||||||
return finalDoipMsg;
|
return finalDoipMsg;
|
||||||
|
} catch (ScriptReturnException e) {
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder =
|
||||||
|
new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Declined, msg);
|
||||||
|
builder.setBody(e.message.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
logger.error("buildRequestAndInvokeEngine catch ScriptReturnException");
|
||||||
|
return builder.create();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
logger.error("buildRequestAndInvokeEngine has something wrong, executeWithoutLock err or validateJsonElementRulesByArgSchemaVisitor err");
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder =
|
||||||
|
new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Declined, msg);
|
||||||
|
builder.setBody(bo.toByteArray());
|
||||||
|
builder.addAttributes("nodeID", String.valueOf(JavaScriptEntry.shardingID));
|
||||||
|
logger.error(
|
||||||
|
"buildRequestAndInvokeEngine has something wrong, executeWithoutLock err or validateJsonElementRulesByArgSchemaVisitor err");
|
||||||
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) {
|
public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) {
|
||||||
ContractRequest cr = new ContractRequest();
|
ContractRequest cr = new ContractRequest();
|
||||||
cr.setContractID("");
|
cr.setContractID("");
|
||||||
if(request.credential == null) {
|
if (request.credential == null) {
|
||||||
cr.setRequester(null);
|
cr.setRequester(null);
|
||||||
} else {
|
} else {
|
||||||
cr.setRequester(request.credential.getSigner());
|
cr.setRequester(request.credential.getSigner());
|
||||||
}
|
}
|
||||||
cr.setAction(fn.functionName);
|
cr.setAction(fn.functionName);
|
||||||
|
cr.setArg(JsonUtil.parseObjectAsJsonObject(JsonDoipMessage.fromDoipMessage(request)));
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ public class JSEDump implements Serializable {
|
|||||||
long ranSeed;
|
long ranSeed;
|
||||||
int numsOfCopies;
|
int numsOfCopies;
|
||||||
|
|
||||||
public JSEDump(long id,long ra,int nums){
|
public JSEDump(long id, long ra, int nums) {
|
||||||
invokeID = id;
|
invokeID = id;
|
||||||
ranSeed = ra;
|
ranSeed = ra;
|
||||||
numsOfCopies = nums;
|
numsOfCopies = nums;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printContent(){
|
public void printContent() {
|
||||||
System.out.println("invokeID=" + invokeID);
|
System.out.println("invokeID=" + invokeID);
|
||||||
System.out.println("ranSeed=" + ranSeed);
|
System.out.println("ranSeed=" + ranSeed);
|
||||||
System.out.println("numsOfCopies=" + numsOfCopies);
|
System.out.println("numsOfCopies=" + numsOfCopies);
|
||||||
|
|||||||
@@ -4,37 +4,38 @@ import jdk.internal.dynalink.beans.StaticClass;
|
|||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
|
||||||
public enum MOType {
|
public enum MOType {
|
||||||
String(true), Int(true), Double(true), Boolean(true),JSObject(false), JSArray(false), JavaObject(false), Method(false),
|
String(true), Int(true), Double(true), Boolean(true), JSObject(false), JSArray(
|
||||||
Undefined(true), JSFunction(false),JSStatic(false);
|
false), JavaObject(
|
||||||
|
false), Method(false), Undefined(true), JSFunction(false), JSStatic(false);
|
||||||
|
|
||||||
private boolean isPrimitive;
|
private boolean isPrimitive;
|
||||||
|
|
||||||
MOType(boolean isPrimitive) {
|
MOType(boolean isPrimitive) {
|
||||||
this.isPrimitive = (isPrimitive);
|
this.isPrimitive = (isPrimitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MOType getType(Object obj) {
|
public static MOType getType(Object obj) {
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return Undefined;
|
return Undefined;
|
||||||
if (obj instanceof Integer) {
|
if (obj instanceof Integer) {
|
||||||
return Int;
|
return Int;
|
||||||
} else if (obj instanceof Double) {
|
} else if (obj instanceof Double) {
|
||||||
return Double;
|
return Double;
|
||||||
} else if (obj instanceof String) {
|
} else if (obj instanceof String) {
|
||||||
return String;
|
return String;
|
||||||
} else if (obj instanceof ScriptObjectMirror) {
|
} else if (obj instanceof ScriptObjectMirror) {
|
||||||
// ------
|
// ------
|
||||||
return JSObject;
|
return JSObject;
|
||||||
}else if(obj instanceof StaticClass) {
|
} else if (obj instanceof StaticClass) {
|
||||||
return JSStatic;
|
return JSStatic;
|
||||||
}else if(obj instanceof Boolean){
|
} else if (obj instanceof Boolean) {
|
||||||
return Boolean;
|
return Boolean;
|
||||||
}
|
}
|
||||||
return JSObject;
|
return JSObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPrimitive() {
|
public boolean isPrimitive() {
|
||||||
return isPrimitive;
|
return isPrimitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package org.bdware.sc.memory;
|
package org.bdware.sc.memory;
|
||||||
|
|
||||||
public class MemoryArrayObject extends MemoryJSObject{
|
public class MemoryArrayObject extends MemoryJSObject {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5805776423219733634L;
|
private static final long serialVersionUID = -5805776423219733634L;
|
||||||
|
|
||||||
public MemoryArrayObject(long id) {
|
public MemoryArrayObject(long id) {
|
||||||
super(id);
|
super(id);
|
||||||
type = MOType.JSArray;
|
type = MOType.JSArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
public class MemoryDump implements Serializable {
|
public class MemoryDump implements Serializable {
|
||||||
transient long id;
|
transient long id;
|
||||||
transient Map<Object, Long> allocated; //js对象,id
|
transient Map<Object, Long> allocated; // js对象,id
|
||||||
|
|
||||||
Map<Long, MemoryObject> objects; //id,memory对象
|
Map<Long, MemoryObject> objects; // id,memory对象
|
||||||
JSEDump jseDump;
|
JSEDump jseDump;
|
||||||
|
|
||||||
transient Map<Long, Object> recreate;
|
transient Map<Long, Object> recreate;
|
||||||
@@ -99,12 +99,11 @@ public class MemoryDump implements Serializable {
|
|||||||
id++;
|
id++;
|
||||||
currID = id;
|
currID = id;
|
||||||
if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
||||||
/*
|
/*
|
||||||
String obj2 = "jdk.internal.dynalink.beans.StaticClass.class";
|
* String obj2 = "jdk.internal.dynalink.beans.StaticClass.class"; if
|
||||||
if (allocated.containsKey(obj2))
|
* (allocated.containsKey(obj2)) return allocated.get(obj2); allocated.put(obj2,
|
||||||
return allocated.get(obj2);
|
* currID);
|
||||||
allocated.put(obj2, currID);
|
*/
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
if (allocated.containsKey(obj))
|
if (allocated.containsKey(obj))
|
||||||
return allocated.get(obj);
|
return allocated.get(obj);
|
||||||
@@ -137,12 +136,12 @@ public class MemoryDump implements Serializable {
|
|||||||
} else if (obj.getClass() == wrp.jdk.nashorn.internal.runtime.Undefined.class) {
|
} else if (obj.getClass() == wrp.jdk.nashorn.internal.runtime.Undefined.class) {
|
||||||
|
|
||||||
} else if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
} else if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) {
|
||||||
//regard as String
|
// regard as String
|
||||||
|
|
||||||
// MemoryObject mo = new MemoryObject(currID);
|
// MemoryObject mo = new MemoryObject(currID);
|
||||||
// mo.type = MOType.String;
|
// mo.type = MOType.String;
|
||||||
// mo.data = "jdk.internal.dynalink.beans.StaticClass";
|
// mo.data = "jdk.internal.dynalink.beans.StaticClass";
|
||||||
// objects.put(currID, mo);
|
// objects.put(currID, mo);
|
||||||
} else {
|
} else {
|
||||||
MOType type = MOType.getType(obj);
|
MOType type = MOType.getType(obj);
|
||||||
if (type.isPrimitive()) {
|
if (type.isPrimitive()) {
|
||||||
@@ -151,7 +150,8 @@ public class MemoryDump implements Serializable {
|
|||||||
mo.data = obj;
|
mo.data = obj;
|
||||||
objects.put(currID, mo);
|
objects.put(currID, mo);
|
||||||
} else
|
} else
|
||||||
System.out.println("[MemoryDump] Allocat MetType:" + obj.getClass() + " now id=" + currID);
|
System.out.println(
|
||||||
|
"[MemoryDump] Allocat MetType:" + obj.getClass() + " now id=" + currID);
|
||||||
|
|
||||||
}
|
}
|
||||||
return currID;
|
return currID;
|
||||||
@@ -203,15 +203,18 @@ public class MemoryDump implements Serializable {
|
|||||||
}
|
}
|
||||||
switch (mo.type) {
|
switch (mo.type) {
|
||||||
case JSArray:
|
case JSArray:
|
||||||
obj = ScriptObjectMirror.wrap(Global.allocate(new int[0]), JavaScriptEntry.getEngineGlobal());
|
obj = ScriptObjectMirror.wrap(Global.allocate(new int[0]),
|
||||||
|
JavaScriptEntry.getEngineGlobal());
|
||||||
break;
|
break;
|
||||||
case JSObject:
|
case JSObject:
|
||||||
obj = ScriptObjectMirror.wrap(new JO(PropertyMap.newMap()), JavaScriptEntry.getEngineGlobal());
|
obj = ScriptObjectMirror.wrap(new JO(PropertyMap.newMap()),
|
||||||
|
JavaScriptEntry.getEngineGlobal());
|
||||||
break;
|
break;
|
||||||
case JSFunction:
|
case JSFunction:
|
||||||
break;
|
break;
|
||||||
case String:
|
case String:
|
||||||
case Int:
|
case Int:
|
||||||
|
case Boolean:
|
||||||
obj = mo.data;
|
obj = mo.data;
|
||||||
break;
|
break;
|
||||||
case Double:
|
case Double:
|
||||||
@@ -225,4 +228,4 @@ public class MemoryDump implements Serializable {
|
|||||||
recreate.put(key, obj);
|
recreate.put(key, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
|
|
||||||
public class MemoryDumpUtil {
|
public class MemoryDumpUtil {
|
||||||
public static final String STATELESS_MEMORY = "statelessContractMemory";
|
public static final String STATELESS_MEMORY = "statelessContractMemory";
|
||||||
public static AtomicInteger checkPointCounter; //用于common模式下的检查点计数
|
public static AtomicInteger checkPointCounter; // 用于common模式下的检查点计数
|
||||||
NashornScriptEngine engine;
|
NashornScriptEngine engine;
|
||||||
String dumpContent;
|
String dumpContent;
|
||||||
MemoryDump memoryDump = null;
|
MemoryDump memoryDump = null;
|
||||||
@@ -30,11 +30,12 @@ public class MemoryDumpUtil {
|
|||||||
GZIPInputStream gzin = new GZIPInputStream(fileout);
|
GZIPInputStream gzin = new GZIPInputStream(fileout);
|
||||||
reader = new ObjectInputStream(gzin);
|
reader = new ObjectInputStream(gzin);
|
||||||
MemoryDump memoryDump = new MemoryDump();
|
MemoryDump memoryDump = new MemoryDump();
|
||||||
//memoryDump.objects = (Map<Long, MemoryObject>) reader.readObject();
|
// memoryDump.objects = (Map<Long, MemoryObject>) reader.readObject();
|
||||||
memoryDump = (MemoryDump) reader.readObject();
|
memoryDump = (MemoryDump) reader.readObject();
|
||||||
reader.close();
|
reader.close();
|
||||||
String ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
String ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
||||||
ret += ("<seperate>" + memoryDump.jseDump.invokeID + ";" + memoryDump.jseDump.ranSeed + ";" + memoryDump.jseDump.numsOfCopies + "");
|
ret += ("<seperate>" + memoryDump.jseDump.invokeID + ";" + memoryDump.jseDump.ranSeed
|
||||||
|
+ ";" + memoryDump.jseDump.numsOfCopies + "");
|
||||||
return ret;
|
return ret;
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -43,23 +44,14 @@ public class MemoryDumpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static String getContentFromFile2(String path) {
|
* public static String getContentFromFile2(String path) { File file = new File(path);
|
||||||
File file = new File(path);
|
* ObjectInputStream reader; try { FileInputStream fileout = new FileInputStream(file); reader =
|
||||||
ObjectInputStream reader;
|
* new ObjectInputStream(fileout); String ret = (String)reader.readObject(); reader.close();
|
||||||
try {
|
* return ret; } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return
|
||||||
FileInputStream fileout = new FileInputStream(file);
|
* null; }
|
||||||
reader = new ObjectInputStream(fileout);
|
*/
|
||||||
String ret = (String)reader.readObject();
|
|
||||||
reader.close();
|
|
||||||
return ret;
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//stateful 表示合约是有/无状态合约
|
// stateful 表示合约是有/无状态合约
|
||||||
public String dumpMemory(String path, boolean stateful) {
|
public String dumpMemory(String path, boolean stateful) {
|
||||||
synchronized (engine) {
|
synchronized (engine) {
|
||||||
String ret;
|
String ret;
|
||||||
@@ -73,16 +65,21 @@ public class MemoryDumpUtil {
|
|||||||
long id = memoryDump.allocate(obj);
|
long id = memoryDump.allocate(obj);
|
||||||
root.addField(key, id);
|
root.addField(key, id);
|
||||||
}
|
}
|
||||||
memoryDump.jseDump = new JSEDump(JavaScriptEntry.invokeID, Long.parseLong(JavaScriptEntry.currentSyncUtil.contractID), JavaScriptEntry.numOfCopies);
|
memoryDump.jseDump = new JSEDump(JavaScriptEntry.invokeID,
|
||||||
|
Long.parseLong(JavaScriptEntry.currentSyncUtil.contractID),
|
||||||
|
JavaScriptEntry.numOfCopies);
|
||||||
ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
||||||
} else { //无状态合约
|
} else { // 无状态合约
|
||||||
memoryDump.jseDump = new JSEDump(JavaScriptEntry.invokeID, Long.parseLong(JavaScriptEntry.currentSyncUtil.contractID), JavaScriptEntry.numOfCopies);
|
memoryDump.jseDump = new JSEDump(JavaScriptEntry.invokeID,
|
||||||
|
Long.parseLong(JavaScriptEntry.currentSyncUtil.contractID),
|
||||||
|
JavaScriptEntry.numOfCopies);
|
||||||
memoryDump.objects.clear();
|
memoryDump.objects.clear();
|
||||||
ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
ret = JsonUtil.toPrettyJson(memoryDump.objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += "--seperate--";
|
ret += "--seperate--";
|
||||||
ret += (memoryDump.jseDump.invokeID + ";" + memoryDump.jseDump.ranSeed + ";" + memoryDump.jseDump.numsOfCopies);
|
ret += (memoryDump.jseDump.invokeID + ";" + memoryDump.jseDump.ranSeed + ";"
|
||||||
|
+ memoryDump.jseDump.numsOfCopies);
|
||||||
|
|
||||||
if (path == null || path.equals("")) {
|
if (path == null || path.equals("")) {
|
||||||
return ret;
|
return ret;
|
||||||
@@ -90,13 +87,14 @@ public class MemoryDumpUtil {
|
|||||||
|
|
||||||
File mem = new File(path);
|
File mem = new File(path);
|
||||||
File parent = mem.getParentFile();
|
File parent = mem.getParentFile();
|
||||||
if (!parent.exists()) parent.mkdirs();
|
if (!parent.exists())
|
||||||
|
parent.mkdirs();
|
||||||
ObjectOutputStream writer;
|
ObjectOutputStream writer;
|
||||||
try {
|
try {
|
||||||
FileOutputStream fileout = new FileOutputStream(mem);
|
FileOutputStream fileout = new FileOutputStream(mem);
|
||||||
GZIPOutputStream out = new GZIPOutputStream(fileout);
|
GZIPOutputStream out = new GZIPOutputStream(fileout);
|
||||||
writer = new ObjectOutputStream(out);
|
writer = new ObjectOutputStream(out);
|
||||||
//writer.writeObject(memoryDump.objects);
|
// writer.writeObject(memoryDump.objects);
|
||||||
writer.writeObject(memoryDump);
|
writer.writeObject(memoryDump);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
@@ -112,44 +110,25 @@ public class MemoryDumpUtil {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public String dumpMemory(String path) {
|
* public String dumpMemory(String path) { memoryDump = new MemoryDump(); Bindings bindings =
|
||||||
memoryDump = new MemoryDump();
|
* engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||||
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
* System.out.println("[MemoryDumpUtil] bindings size=" + bindings.size()); MemoryJSObject root
|
||||||
System.out.println("[MemoryDumpUtil] bindings size=" + bindings.size());
|
* = memoryDump.getRoot(); for (String key : bindings.keySet()) {
|
||||||
MemoryJSObject root = memoryDump.getRoot();
|
* System.out.println("[MemoryDumpUtil] dumpMemory " + key); Object obj = bindings.get(key);
|
||||||
for (String key : bindings.keySet()) {
|
* long id = memoryDump.allocate(obj); root.addField(key, id);
|
||||||
System.out.println("[MemoryDumpUtil] dumpMemory " + key);
|
*
|
||||||
Object obj = bindings.get(key);
|
* System.out.println("[root addFiled] key=" + key + " id=" + id); } String ret =
|
||||||
long id = memoryDump.allocate(obj);
|
* JsonUtil.toPrettyJson(memoryDump); dumpContent = ret;
|
||||||
root.addField(key, id);
|
*
|
||||||
|
* if(path == null || path.equals("")) { return ret; }
|
||||||
System.out.println("[root addFiled] key=" + key + " id=" + id);
|
*
|
||||||
}
|
* File mem = new File(path); File parent = mem.getParentFile(); if (!parent.exists())
|
||||||
String ret = JsonUtil.toPrettyJson(memoryDump);
|
* parent.mkdirs(); ObjectOutputStream writer; try { FileOutputStream fileout = new
|
||||||
dumpContent = ret;
|
* FileOutputStream(mem); writer = new ObjectOutputStream(fileout);
|
||||||
|
* writer.writeObject(dumpContent);
|
||||||
if(path == null || path.equals("")) {
|
*
|
||||||
return ret;
|
* writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); }
|
||||||
}
|
*
|
||||||
|
* memoryDump = null; return ret; }
|
||||||
File mem = new File(path);
|
*/
|
||||||
File parent = mem.getParentFile();
|
|
||||||
if (!parent.exists())
|
|
||||||
parent.mkdirs();
|
|
||||||
ObjectOutputStream writer;
|
|
||||||
try {
|
|
||||||
FileOutputStream fileout = new FileOutputStream(mem);
|
|
||||||
writer = new ObjectOutputStream(fileout);
|
|
||||||
writer.writeObject(dumpContent);
|
|
||||||
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
memoryDump = null;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MemoryFunctionObject extends MemoryObject {
|
public class MemoryFunctionObject extends MemoryObject {
|
||||||
private static final long serialVersionUID = 5169037078273981613L;
|
private static final long serialVersionUID = 5169037078273981613L;
|
||||||
Map<String, Long> fields;
|
Map<String, Long> fields;
|
||||||
|
|
||||||
public MemoryFunctionObject(long id) {
|
public MemoryFunctionObject(long id) {
|
||||||
super(id);
|
super(id);
|
||||||
fields = new HashMap<>();
|
fields = new HashMap<>();
|
||||||
type = MOType.JSFunction;
|
type = MOType.JSFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addField(String key, long id) {
|
public void addField(String key, long id) {
|
||||||
fields.put(key, id);
|
fields.put(key, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
package org.bdware.sc.memory;
|
package org.bdware.sc.memory;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MemoryJSObject extends MemoryObject {
|
public class MemoryJSObject extends MemoryObject {
|
||||||
private static final long serialVersionUID = -2290414347562477503L;
|
private static final long serialVersionUID = -2290414347562477503L;
|
||||||
LinkedHashMap<String, Long> fields;
|
LinkedHashMap<String, Long> fields;
|
||||||
|
|
||||||
public MemoryJSObject(long id) {
|
public MemoryJSObject(long id) {
|
||||||
super(id);
|
super(id);
|
||||||
fields = new LinkedHashMap<>();
|
fields = new LinkedHashMap<>();
|
||||||
type = MOType.JSObject;
|
type = MOType.JSObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addField(String key, long id) {
|
public void addField(String key, long id) {
|
||||||
fields.put(key, id);
|
fields.put(key, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class MemoryRecoverUtil {
|
|||||||
this.resource = r;
|
this.resource = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
//支持传入memory文件路径或者直接是memory的字符串
|
// 支持传入memory文件路径或者直接是memory的字符串
|
||||||
public void loadMemory(String path, boolean stateful) {
|
public void loadMemory(String path, boolean stateful) {
|
||||||
synchronized (engine) {
|
synchronized (engine) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
@@ -39,9 +39,9 @@ public class MemoryRecoverUtil {
|
|||||||
GZIPInputStream gzin = new GZIPInputStream(fileout);
|
GZIPInputStream gzin = new GZIPInputStream(fileout);
|
||||||
ObjectInputStream reader = new ObjectInputStream(gzin);
|
ObjectInputStream reader = new ObjectInputStream(gzin);
|
||||||
|
|
||||||
// MemoryDump temp = new MemoryDump();
|
// MemoryDump temp = new MemoryDump();
|
||||||
// temp.objects = (Map<Long, MemoryObject>) reader.readObject();
|
// temp.objects = (Map<Long, MemoryObject>) reader.readObject();
|
||||||
// String content = JsonUtil.toPrettyJson(temp);
|
// String content = JsonUtil.toPrettyJson(temp);
|
||||||
|
|
||||||
MemoryDump temp = (MemoryDump) reader.readObject();
|
MemoryDump temp = (MemoryDump) reader.readObject();
|
||||||
String content = JsonUtil.toPrettyJson(temp.objects);
|
String content = JsonUtil.toPrettyJson(temp.objects);
|
||||||
@@ -67,7 +67,7 @@ public class MemoryRecoverUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//memoryDump = MemoryDump.loadFromStr(content);
|
// memoryDump = MemoryDump.loadFromStr(content);
|
||||||
if (stateful) {
|
if (stateful) {
|
||||||
memoryDump = temp;
|
memoryDump = temp;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ public class MemoryRecoverUtil {
|
|||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else { //直接传入的是字符串
|
} else { // 直接传入的是字符串
|
||||||
String[] strs = path.split("--seperate--");
|
String[] strs = path.split("--seperate--");
|
||||||
String content = strs[0];
|
String content = strs[0];
|
||||||
String jse = strs[1];
|
String jse = strs[1];
|
||||||
@@ -103,7 +103,7 @@ public class MemoryRecoverUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stateful) { //有状态合约
|
if (stateful) { // 有状态合约
|
||||||
memoryDump = MemoryDump.loadFromStr(content);
|
memoryDump = MemoryDump.loadFromStr(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,8 @@ public class MemoryRecoverUtil {
|
|||||||
ScriptObjectMirror global = (ScriptObjectMirror) objects.get(0L);
|
ScriptObjectMirror global = (ScriptObjectMirror) objects.get(0L);
|
||||||
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||||
for (Object key : global.keySet()) {
|
for (Object key : global.keySet()) {
|
||||||
if (global.get(key) != null) bindings.put((String) key, global.get(key));
|
if (global.get(key) != null)
|
||||||
|
bindings.put((String) key, global.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.memoryDump = null;
|
this.memoryDump = null;
|
||||||
@@ -127,34 +128,20 @@ public class MemoryRecoverUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public void loadMemory(String path) {
|
* public void loadMemory(String path) { try { String memory; File mem = new File(path);
|
||||||
try {
|
* FileInputStream fileout = new FileInputStream(mem); ObjectInputStream reader = new
|
||||||
String memory;
|
* ObjectInputStream(fileout); loadContent = (String) reader.readObject(); //
|
||||||
File mem = new File(path);
|
* System.out.println("[MemoryRecoverUtil] loadContent : \n" + loadContent); reader.close();
|
||||||
FileInputStream fileout = new FileInputStream(mem);
|
* memoryDump = MemoryDump.loadFromStr(loadContent);
|
||||||
ObjectInputStream reader = new ObjectInputStream(fileout);
|
*
|
||||||
loadContent = (String) reader.readObject();
|
*
|
||||||
// System.out.println("[MemoryRecoverUtil] loadContent : \n" + loadContent);
|
* String ret = JsonUtil.toPrettyJson(memoryDump); MemoryJSObject root = memoryDump.getRoot();
|
||||||
reader.close();
|
* Map<Long, Object> objects = memoryDump.recreateObject(); ScriptObjectMirror global =
|
||||||
memoryDump = MemoryDump.loadFromStr(loadContent);
|
* (ScriptObjectMirror) objects.get(0L); Bindings bindings =
|
||||||
|
* engine.getBindings(ScriptContext.ENGINE_SCOPE); for (Object key : global.keySet()) { if
|
||||||
|
* (global.get(key) != null) bindings.put((String) key, global.get(key)); } this.memoryDump =
|
||||||
String ret = JsonUtil.toPrettyJson(memoryDump);
|
* null; if (resource != null) ((Invocable) engine).invokeFunction("defineProp", "Resources",
|
||||||
MemoryJSObject root = memoryDump.getRoot();
|
* resource); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
|
||||||
Map<Long, Object> objects = memoryDump.recreateObject();
|
* }
|
||||||
ScriptObjectMirror global = (ScriptObjectMirror) objects.get(0L);
|
*/
|
||||||
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
|
||||||
for (Object key : global.keySet()) {
|
|
||||||
if (global.get(key) != null)
|
|
||||||
bindings.put((String) key, global.get(key));
|
|
||||||
}
|
|
||||||
this.memoryDump = null;
|
|
||||||
if (resource != null)
|
|
||||||
((Invocable) engine).invokeFunction("defineProp", "Resources", resource);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ import java.util.Map;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class TransRecordUtil {
|
public class TransRecordUtil {
|
||||||
public static final int RESERVED = 20; //最近的多少次records内存也保存,如果一个节点距离集群当前的seq相差超过这个值,就不从本地恢复,让别的节点现场dump
|
public static final int RESERVED = 20; // 最近的多少次records内存也保存,如果一个节点距离集群当前的seq相差超过这个值,就不从本地恢复,让别的节点现场dump
|
||||||
public static final int DUMP_PERIOD = 50; //每满50次记录,就记录一次全量状态,清一次trans记录
|
public static final int DUMP_PERIOD = 50; // 每满50次记录,就记录一次全量状态,清一次trans记录
|
||||||
private static final Logger LOGGER = LogManager.getLogger(TransRecordUtil.class);
|
private static final Logger LOGGER = LogManager.getLogger(TransRecordUtil.class);
|
||||||
public Map<Integer, TransRecord> cacheTransRecords = new TreeMap<Integer, TransRecord>(); //TODO 认为其中records一定是seq连续的,否则可能有问题?
|
public Map<Integer, TransRecord> cacheTransRecords = new TreeMap<Integer, TransRecord>(); // TODO
|
||||||
//public PriorityQueue<TransRecord> transRecords = new PriorityQueue<TransRecord>();
|
// 认为其中records一定是seq连续的,否则可能有问题?
|
||||||
|
// public PriorityQueue<TransRecord> transRecords = new PriorityQueue<TransRecord>();
|
||||||
public TransRecord currentTransRecord;
|
public TransRecord currentTransRecord;
|
||||||
SyncMechUtil syncUtil;
|
SyncMechUtil syncUtil;
|
||||||
DesktopEngine engine;
|
DesktopEngine engine;
|
||||||
@@ -30,20 +31,20 @@ public class TransRecordUtil {
|
|||||||
fileName = path;
|
fileName = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
//每次事务开始时初始化
|
// 每次事务开始时初始化
|
||||||
public void startNext(String fun, JsonElement arg, int sequence) {
|
public void startNext(String fun, JsonElement arg, int sequence) {
|
||||||
//logger.debug("TransRecordUtil 开始记录事务");
|
// logger.debug("TransRecordUtil 开始记录事务");
|
||||||
currentTransRecord = new TransRecord(fun, arg, sequence);
|
currentTransRecord = new TransRecord(fun, arg, sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNext(String fun, JsonElement arg) {
|
public void startNext(String fun, JsonElement arg) {
|
||||||
//logger.debug("TransRecordUtil 开始记录事务");
|
// logger.debug("TransRecordUtil 开始记录事务");
|
||||||
currentTransRecord = new TransRecord(fun, arg);
|
currentTransRecord = new TransRecord(fun, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//每次事务结束时记录
|
// 每次事务结束时记录
|
||||||
public synchronized void eachFinish() {
|
public synchronized void eachFinish() {
|
||||||
//logger.debug("TransRecordUtil 记录完一个事务 \n" + currentTransRecord.toString());
|
// logger.debug("TransRecordUtil 记录完一个事务 \n" + currentTransRecord.toString());
|
||||||
cacheTransRecords.put(currentTransRecord.seq, currentTransRecord);
|
cacheTransRecords.put(currentTransRecord.seq, currentTransRecord);
|
||||||
if (cacheTransRecords.size() == RESERVED) {
|
if (cacheTransRecords.size() == RESERVED) {
|
||||||
int temp = 0;
|
int temp = 0;
|
||||||
@@ -54,10 +55,10 @@ public class TransRecordUtil {
|
|||||||
cacheTransRecords.remove(temp);
|
cacheTransRecords.remove(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendTransFile(currentTransRecord); //执行前已经定序了,所以trans其实没必要定序
|
appendTransFile(currentTransRecord); // 执行前已经定序了,所以trans其实没必要定序
|
||||||
}
|
}
|
||||||
|
|
||||||
//追加写入最后一个TransRecord
|
// 追加写入最后一个TransRecord
|
||||||
public void appendTransFile(TransRecord record) {
|
public void appendTransFile(TransRecord record) {
|
||||||
syncUtil.filedTrans.getAndIncrement();
|
syncUtil.filedTrans.getAndIncrement();
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ public class TransRecordUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//自动触发检查点
|
// 自动触发检查点
|
||||||
if (syncUtil.filedTrans.get() == DUMP_PERIOD) {
|
if (syncUtil.filedTrans.get() == DUMP_PERIOD) {
|
||||||
LOGGER.info("自动触发检查点 DUMP_PERIOD=" + DUMP_PERIOD);
|
LOGGER.info("自动触发检查点 DUMP_PERIOD=" + DUMP_PERIOD);
|
||||||
file = new File(syncUtil.memoryDir);
|
file = new File(syncUtil.memoryDir);
|
||||||
@@ -106,7 +107,7 @@ public class TransRecordUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//sync文件删除第2,3行
|
// sync文件删除第2,3行
|
||||||
file = new File(syncUtil.syncDir + "/" + syncUtil.syncFileName);
|
file = new File(syncUtil.syncDir + "/" + syncUtil.syncFileName);
|
||||||
String firstLine = "";
|
String firstLine = "";
|
||||||
try {
|
try {
|
||||||
@@ -143,7 +144,7 @@ public class TransRecordUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//record executeContract in current trans
|
// record executeContract in current trans
|
||||||
public void recordExecutes(String k, String v) {
|
public void recordExecutes(String k, String v) {
|
||||||
if (currentTransRecord != null) {
|
if (currentTransRecord != null) {
|
||||||
currentTransRecord.executes.put(k, v);
|
currentTransRecord.executes.put(k, v);
|
||||||
@@ -155,13 +156,13 @@ public class TransRecordUtil {
|
|||||||
public String getCachedTransRecords(int start) {
|
public String getCachedTransRecords(int start) {
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
|
|
||||||
//先查看有没有第1个
|
// 先查看有没有第1个
|
||||||
if (!cacheTransRecords.containsKey(start))
|
if (!cacheTransRecords.containsKey(start))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
synchronized (cacheTransRecords) {
|
synchronized (cacheTransRecords) {
|
||||||
int temp = -1;
|
int temp = -1;
|
||||||
int j = start - 1;//确保有从start开始的连续trans,j记录上一个i值
|
int j = start - 1;// 确保有从start开始的连续trans,j记录上一个i值
|
||||||
for (Integer i : cacheTransRecords.keySet()) {
|
for (Integer i : cacheTransRecords.keySet()) {
|
||||||
if (i >= start) {
|
if (i >= start) {
|
||||||
if (i == (j + 1)) {
|
if (i == (j + 1)) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class TransRecoverUtil {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] strs = line.split(";");
|
String[] strs = line.split(";");
|
||||||
String arg;
|
String arg;
|
||||||
if (strs.length < 5) { //调用记录参数为空
|
if (strs.length < 5) { // 调用记录参数为空
|
||||||
arg = null;
|
arg = null;
|
||||||
} else {
|
} else {
|
||||||
arg = strs[4];
|
arg = strs[4];
|
||||||
@@ -46,7 +46,8 @@ public class TransRecoverUtil {
|
|||||||
System.out.println("恢复时加入 " + cur_read.toString());
|
System.out.println("恢复时加入 " + cur_read.toString());
|
||||||
}
|
}
|
||||||
if (strs[1].equals("true"))
|
if (strs[1].equals("true"))
|
||||||
cur_read = new TransRecord(strs[3], JsonUtil.parseString(arg), Integer.parseInt(strs[2]));
|
cur_read = new TransRecord(strs[3], JsonUtil.parseString(arg),
|
||||||
|
Integer.parseInt(strs[2]));
|
||||||
else
|
else
|
||||||
cur_read = new TransRecord(strs[3], JsonUtil.parseString(arg));
|
cur_read = new TransRecord(strs[3], JsonUtil.parseString(arg));
|
||||||
} else {
|
} else {
|
||||||
@@ -83,7 +84,8 @@ public class TransRecoverUtil {
|
|||||||
ac.seq = curRecoverRecord.seq;
|
ac.seq = curRecoverRecord.seq;
|
||||||
LOGGER.info("[TransRecordUtil] redo 重新执行事务 " + ac.seq);
|
LOGGER.info("[TransRecordUtil] redo 重新执行事务 " + ac.seq);
|
||||||
}
|
}
|
||||||
System.out.println("[TransRecoverUtil] recover " + ac.needSeq + " " + ac.seq + " " + ac.getAction() + " " + ac.getArg());
|
System.out.println("[TransRecoverUtil] recover " + ac.needSeq + " " + ac.seq + " "
|
||||||
|
+ ac.getAction() + " " + ac.getArg());
|
||||||
|
|
||||||
ContractResult result = engine.executeContract(ac);
|
ContractResult result = engine.executeContract(ac);
|
||||||
|
|
||||||
@@ -95,8 +97,8 @@ public class TransRecoverUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
// TODO
|
||||||
public void recoverFromATransRecord(TransRecord record) {
|
public void recoverFromATransRecord(TransRecord record) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user