| @@ -8,11 +8,11 @@ package com.jd.blockchain.consts; | |||
| */ | |||
| public interface DataCodes { | |||
| public static final int BYTES_VALUE = 0x80; | |||
| public static final int BYTES_VALUE = 0x080; | |||
| public static final int BYTES_VALUE_LIST = 0x81; | |||
| public static final int BYTES_VALUE_LIST = 0x081; | |||
| public static final int BLOCK_CHAIN_IDENTITY = 0x90; | |||
| public static final int BLOCK_CHAIN_IDENTITY = 0x090; | |||
| public static final int BLOCK = 0x100; | |||
| @@ -52,12 +52,17 @@ public interface DataCodes { | |||
| public static final int TX_RESPONSE = 0x350; | |||
| public static final int TX_OP_RESULT = 0x360; | |||
| // enum types of permissions; | |||
| public static final int ENUM_TX_PERMISSIONS = 0x401; | |||
| public static final int ENUM_LEDGER_PERMISSIONS = 0x402; | |||
| // contract types of metadata; | |||
| public static final int METADATA = 0x600; | |||
| public static final int METADATA_INIT_SETTING = 0x610; | |||
| public static final int METADATA_INIT_PERMISSION = 0x611; | |||
| public static final int METADATA_INIT_PROPOSAL = 0x611; | |||
| public static final int METADATA_INIT_DECISION = 0x612; | |||
| @@ -18,15 +18,13 @@ public class GatewayBooter { | |||
| writePID(); | |||
| GatewayServerBooter.main(args); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); | |||
| } | |||
| } | |||
| private static final void writePID() throws Exception { | |||
| URL url = GatewayBooter.class | |||
| .getProtectionDomain() | |||
| .getCodeSource() | |||
| .getLocation(); | |||
| URL url = GatewayBooter.class.getProtectionDomain().getCodeSource().getLocation(); | |||
| String currPath = java.net.URLDecoder.decode(url.getPath(), "UTF-8"); | |||
| if (currPath.contains("!/")) { | |||
| currPath = currPath.substring(5, currPath.indexOf("!/")); | |||
| @@ -40,6 +38,10 @@ public class GatewayBooter { | |||
| String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log"; | |||
| File pidFile = new File(pidFilePath); | |||
| if (!pidFile.exists()) { | |||
| File dir = pidFile.getParentFile(); | |||
| if (!dir.exists()) { | |||
| dir.mkdirs(); | |||
| } | |||
| pidFile.createNewFile(); | |||
| } | |||
| String name = ManagementFactory.getRuntimeMXBean().getName(); | |||
| @@ -0,0 +1,63 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import java.util.BitSet; | |||
| import com.jd.blockchain.utils.io.BytesSerializable; | |||
| /** | |||
| * LedgerPrivilege 账本特权是授权给特定角色的权限代码序列; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| public abstract class AbstractPrivilege<E extends Enum<?>> implements Privilege<E>, BytesSerializable { | |||
| private BitSet permissions; | |||
| public AbstractPrivilege(byte[] codeBytes) { | |||
| permissions = BitSet.valueOf(codeBytes); | |||
| } | |||
| public boolean isEnable(E permission) { | |||
| return permissions.get(getCodeIndex(permission)); | |||
| } | |||
| public void enable(E permission) { | |||
| permissions.set(getCodeIndex(permission)); | |||
| } | |||
| public void disable(E permission) { | |||
| permissions.clear(getCodeIndex(permission)); | |||
| } | |||
| // private int getCodeIndex(E permission) { | |||
| // return permission.CODE & 0xFF; | |||
| // } | |||
| protected abstract int getCodeIndex(E permission); | |||
| @Override | |||
| public byte[] toBytes() { | |||
| return permissions.toByteArray(); | |||
| } | |||
| // public boolean[] getPermissionStates() { | |||
| // LedgerPermission[] PMs = LedgerPermission.values(); | |||
| // | |||
| // LedgerPermission maxPermission = Arrays.stream(PMs).max(new Comparator<LedgerPermission>() { | |||
| // @Override | |||
| // public int compare(LedgerPermission o1, LedgerPermission o2) { | |||
| // return getCodeIndex(o1) - getCodeIndex(o2); | |||
| // } | |||
| // }).get(); | |||
| // | |||
| // boolean[] states = new boolean[getCodeIndex(maxPermission) + 1]; | |||
| // int idx = -1; | |||
| // for (LedgerPermission pm : PMs) { | |||
| // idx = getCodeIndex(pm); | |||
| // states[idx] = permissions.get(idx); | |||
| // } | |||
| // | |||
| // return states; | |||
| // } | |||
| } | |||
| @@ -1,7 +1,5 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.ledger.DigitalSignature; | |||
| /** | |||
| * {@link Authorization} 抽象了对特定用户/角色的授权信息; | |||
| * | |||
| @@ -1,21 +0,0 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| /** | |||
| * @author hhq | |||
| * @version 1.0 | |||
| * @created 14-6��-2018 12:13:32 | |||
| */ | |||
| public class Consensus { | |||
| public P2PRealm m_P2PRealm; | |||
| public Consensus(){ | |||
| } | |||
| public void finalize() throws Throwable { | |||
| } | |||
| } | |||
| @@ -1,5 +0,0 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| public enum LedgerAdminPrivilege { | |||
| } | |||
| @@ -13,8 +13,8 @@ import com.jd.blockchain.ledger.LedgerInitOperation; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = DataCodes.METADATA_INIT_PERMISSION) | |||
| public interface LedgerInitPermission { | |||
| @DataContract(code = DataCodes.METADATA_INIT_PROPOSAL) | |||
| public interface LedgerInitProposal { | |||
| /** | |||
| * 做出许可的参与方 ID; | |||
| @@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| public class LedgerInitPermissionData implements LedgerInitPermission { | |||
| public class LedgerInitProposalData implements LedgerInitProposal { | |||
| private int participantId; | |||
| @@ -11,10 +11,10 @@ public class LedgerInitPermissionData implements LedgerInitPermission { | |||
| /** | |||
| * a private contructor for deserialize; | |||
| */ | |||
| private LedgerInitPermissionData() { | |||
| private LedgerInitProposalData() { | |||
| } | |||
| public LedgerInitPermissionData(int participantId, SignatureDigest initTxSignature) { | |||
| public LedgerInitProposalData(int participantId, SignatureDigest initTxSignature) { | |||
| this.participantId = participantId; | |||
| this.transactionSignature = initTxSignature; | |||
| } | |||
| @@ -1,9 +1,94 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.EnumContract; | |||
| import com.jd.blockchain.binaryproto.EnumField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * 账本相关的权限,这些权限属于全局性的; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @EnumContract(code = DataCodes.ENUM_LEDGER_PERMISSIONS) | |||
| public enum LedgerPermission { | |||
| SET_ROLE((byte) 0); | |||
| /** | |||
| * 设置角色权限;<br> | |||
| * 包括:创建角色、设置角色的权限代码、分配用户角色; | |||
| */ | |||
| SET_ROLE_PERMISSION((byte) 0x01), | |||
| /** | |||
| * 设置共识协议;<br> | |||
| */ | |||
| SET_CONSENSUS((byte) 0x02), | |||
| /** | |||
| * 设置密码体系;<br> | |||
| */ | |||
| SET_CRYPTO((byte) 0x03), | |||
| /** | |||
| * 注册参与方;<br> | |||
| */ | |||
| REGISTER_PARTICIPANT((byte) 0x04), | |||
| /** | |||
| * 设置参与方的权限;<br> | |||
| * | |||
| * 如果不具备此项权限,则无法设置参与方的“提交交易”、“参与共识”的权限; | |||
| */ | |||
| SET_PARTICIPANT_PERMISSION((byte) 0x05), | |||
| /** | |||
| * 参与方核准交易;<br> | |||
| * | |||
| * 如果不具备此项权限,则无法作为网关节点接入并签署由终端提交的交易; | |||
| */ | |||
| APPROVE_TX((byte) 0x06), | |||
| /** | |||
| * 参与方共识交易;<br> | |||
| * | |||
| * 如果不具备此项权限,则无法作为共识节点接入并对交易进行共识; | |||
| */ | |||
| CONSENSUS_TX((byte) 0x07), | |||
| /** | |||
| * 注册用户;<br> | |||
| * | |||
| * 如果不具备此项权限,则无法注册用户; | |||
| */ | |||
| REGISTER_USER((byte) 0x08), | |||
| /** | |||
| * 设置用户属性;<br> | |||
| */ | |||
| SET_USER_ATTRIBUTES((byte) 0x09), | |||
| /** | |||
| * 注册数据账户;<br> | |||
| */ | |||
| REGISTER_DATA_ACCOUNT((byte) 0x0A), | |||
| /** | |||
| * 写入数据账户;<br> | |||
| */ | |||
| WRITE_DATA_ACCOUNT((byte) 0x0B), | |||
| /** | |||
| * 注册合约;<br> | |||
| */ | |||
| REGISTER_CONTRACT((byte) 0x0C), | |||
| /** | |||
| * 升级合约 | |||
| */ | |||
| UPGRADE_CONTRACT((byte) 0x0D); | |||
| @EnumField(type = PrimitiveType.INT8) | |||
| public final byte CODE; | |||
| private LedgerPermission(byte code) { | |||
| @@ -0,0 +1,20 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| /** | |||
| * LedgerPrivilege 账本特权是授权给特定角色的权限代码序列; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| public class LedgerPrivilege extends AbstractPrivilege<LedgerPermission> { | |||
| public LedgerPrivilege(byte[] codeBytes) { | |||
| super(codeBytes); | |||
| } | |||
| @Override | |||
| protected int getCodeIndex(LedgerPermission permission) { | |||
| return permission.CODE & 0xFF; | |||
| } | |||
| } | |||
| @@ -22,7 +22,7 @@ public class LedgerSecurityManager { | |||
| throw new IllegalStateException("Not implemented!"); | |||
| } | |||
| public Role setRole(String role, Privilege privilege) { | |||
| public Role setRole(String role, LedgerPrivilege privilege) { | |||
| throw new IllegalStateException("Not implemented!"); | |||
| } | |||
| @@ -1,21 +0,0 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| /** | |||
| * @author hhq | |||
| * @version 1.0 | |||
| * @created 14-6��-2018 12:13:33 | |||
| */ | |||
| public class P2PRealm { | |||
| public Peer m_Peer; | |||
| public P2PRealm(){ | |||
| } | |||
| public void finalize() throws Throwable { | |||
| } | |||
| } | |||
| @@ -1,54 +1,5 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import java.util.Arrays; | |||
| import java.util.BitSet; | |||
| import java.util.Comparator; | |||
| public interface Privilege<E extends Enum<?>> { | |||
| public class Privilege { | |||
| private BitSet permissions; | |||
| public Privilege(byte[] codeBytes) { | |||
| permissions = BitSet.valueOf(codeBytes); | |||
| } | |||
| public boolean isEnable(LedgerPermission permission) { | |||
| return permissions.get(getCodeIndex(permission)); | |||
| } | |||
| public void enable(LedgerPermission permission) { | |||
| permissions.set(getCodeIndex(permission)); | |||
| } | |||
| public void disable(LedgerPermission permission) { | |||
| permissions.clear(getCodeIndex(permission)); | |||
| } | |||
| public static int getCodeIndex(LedgerPermission permission) { | |||
| return permission.CODE & 0xFF; | |||
| } | |||
| public byte[] toCodeBytes() { | |||
| return permissions.toByteArray(); | |||
| } | |||
| public boolean[] getPermissionStates() { | |||
| LedgerPermission[] PMs = LedgerPermission.values(); | |||
| LedgerPermission maxPermission = Arrays.stream(PMs).max(new Comparator<LedgerPermission>() { | |||
| @Override | |||
| public int compare(LedgerPermission o1, LedgerPermission o2) { | |||
| return getCodeIndex(o1) - getCodeIndex(o2); | |||
| } | |||
| }).get(); | |||
| boolean[] states = new boolean[getCodeIndex(maxPermission) + 1]; | |||
| int idx = -1; | |||
| for (LedgerPermission pm : PMs) { | |||
| idx = getCodeIndex(pm); | |||
| states[idx] = permissions.get(idx); | |||
| } | |||
| return states; | |||
| } | |||
| } | |||
| @@ -6,7 +6,7 @@ public class Role { | |||
| private long version; | |||
| private Privilege privilege; | |||
| private LedgerPrivilege privilege; | |||
| @@ -18,7 +18,7 @@ public class Role { | |||
| return version; | |||
| } | |||
| public Privilege getPrivilege() { | |||
| public LedgerPrivilege getPrivilege() { | |||
| return privilege; | |||
| } | |||
| @@ -0,0 +1,68 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.ByteArrayOutputStream; | |||
| import com.jd.blockchain.utils.io.BytesEncoding; | |||
| import com.jd.blockchain.utils.io.BytesSerializable; | |||
| /** | |||
| * 表示赋予角色的特权码; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| public class RolePrivilege implements BytesSerializable { | |||
| // 权限码的数量;目前有2种:账本权限 + 交易权限; | |||
| private static final int SEGMENT_COUNT = 2; | |||
| private LedgerPrivilege ledgerPrivilege; | |||
| private TxPrivilege txPrivilege; | |||
| public Privilege<TxPermission> getTxPrivilege() { | |||
| return txPrivilege; | |||
| } | |||
| public Privilege<LedgerPermission> getLedgerPrivilege() { | |||
| return ledgerPrivilege; | |||
| } | |||
| public RolePrivilege(byte[] priviledgeCodes) { | |||
| byte[][] bytesSegments = decodeBytes(priviledgeCodes); | |||
| ledgerPrivilege = new LedgerPrivilege(bytesSegments[0]); | |||
| txPrivilege = new TxPrivilege(bytesSegments[1]); | |||
| } | |||
| private byte[] encodeBytes(byte[]... bytes) { | |||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||
| // write one byte; | |||
| out.write(bytes.length); | |||
| for (int i = 0; i < bytes.length; i++) { | |||
| BytesEncoding.writeInTiny(bytes[i], out); | |||
| } | |||
| return out.toByteArray(); | |||
| } | |||
| private byte[][] decodeBytes(byte[] bytes) { | |||
| ByteArrayInputStream in = new ByteArrayInputStream(bytes); | |||
| // read one byte; | |||
| int len = in.read(); | |||
| if (len < 1 || len > SEGMENT_COUNT) { | |||
| throw new IllegalStateException("Decoded illegal privilege bytes!"); | |||
| } | |||
| byte[][] bytesSegments = new byte[len][]; | |||
| for (int i = 0; i < bytesSegments.length; i++) { | |||
| bytesSegments[i] = BytesEncoding.readInTiny(in); | |||
| } | |||
| return bytesSegments; | |||
| } | |||
| @Override | |||
| public byte[] toBytes() { | |||
| // 保持和解码时一致的顺序; | |||
| return encodeBytes(ledgerPrivilege.toBytes(), txPrivilege.toBytes()); | |||
| } | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.EnumContract; | |||
| import com.jd.blockchain.binaryproto.EnumField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * TxPermission 交易权限表示一个用户可以发起的交易类型; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @EnumContract(code = DataCodes.ENUM_TX_PERMISSIONS) | |||
| public enum TxPermission { | |||
| /** | |||
| * 交易中包含指令操作; | |||
| */ | |||
| COMMAND((byte) 0x01), | |||
| /** | |||
| * 交易中包含合约操作; | |||
| */ | |||
| CONTRACT((byte) 0x02); | |||
| @EnumField(type = PrimitiveType.INT8) | |||
| public final byte CODE; | |||
| private TxPermission(byte code) { | |||
| this.CODE = code; | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| public class TxPrivilege extends AbstractPrivilege<TxPermission> { | |||
| public TxPrivilege(byte[] codeBytes) { | |||
| super(codeBytes); | |||
| } | |||
| @Override | |||
| protected int getCodeIndex(TxPermission permission) { | |||
| return permission.CODE & 0xFF; | |||
| } | |||
| } | |||
| @@ -26,7 +26,7 @@ import com.jd.blockchain.ledger.PreparedTransaction; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.TransactionTemplate; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.impl.LedgerManager; | |||
| import com.jd.blockchain.sdk.BlockchainService; | |||
| @@ -326,7 +326,7 @@ public class ConsensusTest { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||
| @@ -398,7 +398,7 @@ public class ConsensusTest { | |||
| return invoker.start(); | |||
| } | |||
| public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| ConsensusSettings csProps) { | |||
| return controller.prepareLocalPermission(id, privKey, setting, csProps); | |||
| } | |||
| @@ -28,7 +28,7 @@ import com.jd.blockchain.ledger.PreparedTransaction; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.TransactionTemplate; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.impl.LedgerManager; | |||
| import com.jd.blockchain.sdk.BlockchainService; | |||
| @@ -326,7 +326,7 @@ public class GlobalPerformanceTest { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||
| @@ -400,7 +400,7 @@ public class GlobalPerformanceTest { | |||
| return invoker.start(); | |||
| } | |||
| public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| ConsensusSettings csProps) { | |||
| return controller.prepareLocalPermission(id, privKey, setting, csProps); | |||
| } | |||
| @@ -21,7 +21,7 @@ import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.ledger.LedgerBlock; | |||
| import com.jd.blockchain.ledger.core.CryptoConfig; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.UserAccount; | |||
| import com.jd.blockchain.ledger.core.UserAccountSet; | |||
| @@ -251,10 +251,10 @@ public class LedgerInitializeTest { | |||
| } | |||
| @Override | |||
| public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitPermission> invoker = new ThreadInvoker<LedgerInitPermission>() { | |||
| public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitProposal> invoker = new ThreadInvoker<LedgerInitProposal>() { | |||
| @Override | |||
| protected LedgerInitPermission invoke() { | |||
| protected LedgerInitProposal invoke() { | |||
| return initCsService.requestPermission(requesterId, signature); | |||
| } | |||
| }; | |||
| @@ -26,7 +26,7 @@ import com.jd.blockchain.ledger.Operation; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.UserRegisterOperation; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.UserAccount; | |||
| import com.jd.blockchain.ledger.core.UserAccountSet; | |||
| @@ -112,10 +112,10 @@ public class LedgerInitializeWebTest { | |||
| PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
| // 测试生成“账本初始化许可”; | |||
| LedgerInitPermission permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
| LedgerInitPermission permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); | |||
| LedgerInitPermission permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); | |||
| LedgerInitPermission permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); | |||
| LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
| LedgerInitProposal permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); | |||
| LedgerInitProposal permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); | |||
| LedgerInitProposal permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); | |||
| TransactionContent initTxContent0 = node0.getInitTxContent(); | |||
| TransactionContent initTxContent1 = node1.getInitTxContent(); | |||
| @@ -205,9 +205,9 @@ public class LedgerInitializeWebTest { | |||
| testRequestDecision(node3, node2, initCsService2); | |||
| } | |||
| private LedgerInitPermission testPreparePermisssion(NodeWebContext node, PrivKey privKey, | |||
| private LedgerInitProposal testPreparePermisssion(NodeWebContext node, PrivKey privKey, | |||
| LedgerInitProperties setting, ConsensusSettings csProps) { | |||
| LedgerInitPermission permission = node.preparePermision(privKey, setting, csProps); | |||
| LedgerInitProposal permission = node.preparePermision(privKey, setting, csProps); | |||
| return permission; | |||
| } | |||
| @@ -215,7 +215,7 @@ public class LedgerInitializeWebTest { | |||
| private void testRequestPermission(NodeWebContext fromNode, PrivKey fromPrivkey, NodeWebContext targetNode, | |||
| LedgerInitConsensusService targetNodeService) { | |||
| SignatureDigest reqSignature = fromNode.createPermissionRequestSignature(fromNode.getId(), fromPrivkey); | |||
| LedgerInitPermission targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); | |||
| LedgerInitProposal targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); | |||
| } | |||
| private void testRequestDecision(NodeWebContext fromNode, NodeWebContext targetNode, | |||
| @@ -374,7 +374,7 @@ public class LedgerInitializeWebTest { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||
| @@ -457,7 +457,7 @@ public class LedgerInitializeWebTest { | |||
| return invoker.start(); | |||
| } | |||
| public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| ConsensusSettings csProps) { | |||
| return controller.prepareLocalPermission(id, privKey, setting, csProps); | |||
| } | |||
| @@ -18,7 +18,7 @@ import com.jd.blockchain.consensus.ConsensusSettings; | |||
| import com.jd.blockchain.ledger.CryptoSetting; | |||
| import com.jd.blockchain.ledger.core.CryptoConfig; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.impl.LedgerManager; | |||
| import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
| @@ -202,10 +202,10 @@ public class Utils { | |||
| } | |||
| @Override | |||
| public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitPermission> invoker = new ThreadInvoker<LedgerInitPermission>() { | |||
| public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitProposal> invoker = new ThreadInvoker<LedgerInitProposal>() { | |||
| @Override | |||
| protected LedgerInitPermission invoke() { | |||
| protected LedgerInitProposal invoke() { | |||
| return initCsService.requestPermission(requesterId, signature); | |||
| } | |||
| }; | |||
| @@ -30,7 +30,7 @@ import com.jd.blockchain.ledger.LedgerInitOperation; | |||
| import com.jd.blockchain.ledger.UserRegisterOperation; | |||
| import com.jd.blockchain.ledger.core.CryptoConfig; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.UserAccount; | |||
| import com.jd.blockchain.ledger.core.UserAccountSet; | |||
| @@ -301,10 +301,10 @@ public class LedgerInitializeTest { | |||
| } | |||
| @Override | |||
| public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitPermission> invoker = new ThreadInvoker<LedgerInitPermission>() { | |||
| public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { | |||
| ThreadInvoker<LedgerInitProposal> invoker = new ThreadInvoker<LedgerInitProposal>() { | |||
| @Override | |||
| protected LedgerInitPermission invoke() { | |||
| protected LedgerInitProposal invoke() { | |||
| return initCsService.requestPermission(requesterId, signature); | |||
| } | |||
| }; | |||
| @@ -213,7 +213,7 @@ public class LedgerInitializeWeb4Nodes { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||
| @@ -27,7 +27,7 @@ import com.jd.blockchain.ledger.Operation; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.UserRegisterOperation; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.impl.LedgerManager; | |||
| import com.jd.blockchain.storage.service.DbConnection; | |||
| @@ -116,10 +116,10 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
| PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); | |||
| // 测试生成“账本初始化许可”; | |||
| LedgerInitPermission permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
| LedgerInitPermission permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); | |||
| LedgerInitPermission permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); | |||
| LedgerInitPermission permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); | |||
| LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); | |||
| LedgerInitProposal permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); | |||
| LedgerInitProposal permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); | |||
| LedgerInitProposal permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); | |||
| TransactionContent initTxContent0 = node0.getInitTxContent(); | |||
| TransactionContent initTxContent1 = node1.getInitTxContent(); | |||
| @@ -240,9 +240,9 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
| testRequestDecision(node3, node2, initCsService2); | |||
| } | |||
| private LedgerInitPermission testPreparePermisssion(NodeWebContext node, PrivKey privKey, | |||
| private LedgerInitProposal testPreparePermisssion(NodeWebContext node, PrivKey privKey, | |||
| LedgerInitProperties setting, ConsensusSettings csProps) { | |||
| LedgerInitPermission permission = node.preparePermision(privKey, setting, csProps); | |||
| LedgerInitProposal permission = node.preparePermision(privKey, setting, csProps); | |||
| assertEquals(node.getId(), permission.getParticipantId()); | |||
| assertNotNull(permission.getTransactionSignature()); | |||
| @@ -253,7 +253,7 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
| private void testRequestPermission(NodeWebContext fromNode, PrivKey fromPrivkey, NodeWebContext targetNode, | |||
| LedgerInitConsensusService targetNodeService) { | |||
| SignatureDigest reqSignature = fromNode.createPermissionRequestSignature(fromNode.getId(), fromPrivkey); | |||
| LedgerInitPermission targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); | |||
| LedgerInitProposal targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); | |||
| assertEquals(targetNode.getId(), targetPermission.getParticipantId()); | |||
| assertEquals(targetNode.getLocalPermission().getTransactionSignature(), | |||
| targetPermission.getTransactionSignature()); | |||
| @@ -312,7 +312,7 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||
| @@ -385,7 +385,7 @@ public class LedgerInitializeWeb4SingleStepsTest { | |||
| return invoker.start(); | |||
| } | |||
| public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, | |||
| ConsensusSettings csProps) { | |||
| return controller.prepareLocalPermission(id, privKey, setting, csProps); | |||
| } | |||
| @@ -2,7 +2,7 @@ package com.jd.blockchain.tools.initializer.web; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.utils.http.HttpAction; | |||
| import com.jd.blockchain.utils.http.HttpMethod; | |||
| import com.jd.blockchain.utils.http.HttpService; | |||
| @@ -21,7 +21,7 @@ public interface LedgerInitConsensusService { | |||
| * 请求者的私钥对 “id” + “账本种子” 做出的签名;只有签名合法且参与者是初始化配置中的参与方才能获得有效返回,否则将被拒绝; | |||
| */ | |||
| @HttpAction(path = "/legerinit/permission/{requesterId}", method = HttpMethod.POST, contentType = LedgerInitMessageConverter.CONTENT_TYPE_VALUE, responseConverter = PermissionResponseConverter.class) | |||
| LedgerInitPermission requestPermission(@PathParam(name = "requesterId") int requesterId, | |||
| LedgerInitProposal requestPermission(@PathParam(name = "requesterId") int requesterId, | |||
| @RequestBody(converter = SignatureDigestRequestBodyConverter.class) SignatureDigest signature); | |||
| /** | |||
| @@ -17,8 +17,8 @@ import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermissionData; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
| import com.jd.blockchain.utils.io.BytesUtils; | |||
| /** | |||
| @@ -38,10 +38,10 @@ public class LedgerInitMessageConverter implements HttpMessageConverter<Object> | |||
| private static final Map<Class<?>, Class<?>> SUPPORTED_CONTRACT_TYPES = new HashMap<>(); | |||
| static { | |||
| DataContractRegistry.register(LedgerInitPermission.class); | |||
| DataContractRegistry.register(LedgerInitProposal.class); | |||
| DataContractRegistry.register(LedgerInitDecision.class); | |||
| SUPPORTED_CONTRACT_TYPES.put(LedgerInitPermission.class, LedgerInitPermissionData.class); | |||
| SUPPORTED_CONTRACT_TYPES.put(LedgerInitProposal.class, LedgerInitProposalData.class); | |||
| SUPPORTED_CONTRACT_TYPES.put(LedgerInitDecision.class, LedgerInitDecisionData.class); | |||
| // SUPPORTED_CONTRACT_TYPES.add(LedgerInitResponse.class); | |||
| @@ -46,8 +46,8 @@ import com.jd.blockchain.ledger.UserRegisterOperation; | |||
| import com.jd.blockchain.ledger.core.CryptoConfig; | |||
| import com.jd.blockchain.ledger.core.LedgerEditor; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermissionData; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
| import com.jd.blockchain.ledger.core.LedgerManage; | |||
| import com.jd.blockchain.ledger.core.LedgerTransactionContext; | |||
| import com.jd.blockchain.storage.service.DbConnection; | |||
| @@ -84,7 +84,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| private final SignatureFunction SIGN_FUNC; | |||
| private volatile LedgerInitPermission localPermission; | |||
| private volatile LedgerInitProposal localPermission; | |||
| private TransactionContent initTxContent; | |||
| @@ -92,7 +92,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| private volatile LedgerInitSetting ledgerInitSetting; | |||
| private volatile LedgerInitPermission[] permissions; | |||
| private volatile LedgerInitProposal[] permissions; | |||
| private volatile NetworkAddress[] initializerAddresses; | |||
| @@ -140,7 +140,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| return initTxContent; | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return localPermission; | |||
| } | |||
| @@ -319,13 +319,13 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| return defCryptoSetting; | |||
| } | |||
| public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| public LedgerInitProposal prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| ConsensusSettings consensusProps) { | |||
| CryptoSetting defCryptoSetting = createDefaultCryptoSetting(); | |||
| return prepareLocalPermission(currentId, privKey, ledgerProps, consensusProps, defCryptoSetting); | |||
| } | |||
| public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| public LedgerInitProposal prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| ConsensusSettings csSettings, CryptoSetting cryptoSetting) { | |||
| // 创建初始化配置; | |||
| LedgerInitSettingData initSetting = new LedgerInitSettingData(); | |||
| @@ -383,10 +383,10 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| // 对初始交易签名,生成当前参与者的账本初始化许可; | |||
| SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); | |||
| LedgerInitPermissionData permission = new LedgerInitPermissionData(currentId, permissionSign); | |||
| LedgerInitProposalData permission = new LedgerInitProposalData(currentId, permissionSign); | |||
| this.currentId = currentId; | |||
| this.permissions = new LedgerInitPermission[initSetting.getConsensusParticipants().length]; | |||
| this.permissions = new LedgerInitProposal[initSetting.getConsensusParticipants().length]; | |||
| this.permissions[currentId] = permission; | |||
| this.localPermission = permission; | |||
| @@ -493,7 +493,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| continue; | |||
| } | |||
| PubKey pubKey = participants[i].getPubKey(); | |||
| LedgerInitPermission permission = (LedgerInitPermission) results[i].getValue(); | |||
| LedgerInitProposal permission = (LedgerInitProposal) results[i].getValue(); | |||
| if (permission.getParticipantId() != participants[i].getId()) { | |||
| prompter.error("\r\nThe id of received permission isn't equal to it's participant ! --[Id=%s][name=%s]", | |||
| participants[i].getAddress(), participants[i].getName()); | |||
| @@ -534,16 +534,16 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| * @param latch | |||
| * @return | |||
| */ | |||
| private InvocationResult<LedgerInitPermission> doRequestPermission(int targetId, SignatureDigest reqAuthSign, | |||
| private InvocationResult<LedgerInitProposal> doRequestPermission(int targetId, SignatureDigest reqAuthSign, | |||
| CountDownLatch latch) { | |||
| InvocationResult<LedgerInitPermission> result = new InvocationResult<>(); | |||
| InvocationResult<LedgerInitProposal> result = new InvocationResult<>(); | |||
| try { | |||
| LedgerInitConsensusService initConsensus = connectToParticipant(targetId); | |||
| Thread thrd = new Thread(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| try { | |||
| LedgerInitPermission permission = initConsensus.requestPermission(currentId, reqAuthSign); | |||
| LedgerInitProposal permission = initConsensus.requestPermission(currentId, reqAuthSign); | |||
| result.setValue(permission); | |||
| } catch (Exception e) { | |||
| result.setError(e); | |||
| @@ -561,7 +561,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI | |||
| @RequestMapping(path = "/legerinit/permission/{requesterId}", method = RequestMethod.POST, produces = LedgerInitMessageConverter.CONTENT_TYPE_VALUE, consumes = LedgerInitMessageConverter.CONTENT_TYPE_VALUE) | |||
| @Override | |||
| public LedgerInitPermission requestPermission(@PathVariable(name = "requesterId") int requesterId, | |||
| public LedgerInitProposal requestPermission(@PathVariable(name = "requesterId") int requesterId, | |||
| @RequestBody SignatureDigest signature) { | |||
| if (requesterId == currentId) { | |||
| throw new LedgerInitException("There is a id conflict!"); | |||
| @@ -3,7 +3,7 @@ package com.jd.blockchain.tools.initializer.web; | |||
| import java.io.InputStream; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermissionData; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposalData; | |||
| import com.jd.blockchain.tools.initializer.LedgerInitException; | |||
| import com.jd.blockchain.utils.http.HttpServiceContext; | |||
| import com.jd.blockchain.utils.http.ResponseConverter; | |||
| @@ -45,7 +45,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| private final SignatureFunction SIGN_FUNC; | |||
| private volatile LedgerInitPermission localPermission; | |||
| private volatile LedgerInitProposal localPermission; | |||
| private TransactionContent initTxContent; | |||
| @@ -92,7 +92,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| return initTxContent; | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return localPermission; | |||
| } | |||
| @@ -129,7 +129,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| prompter.info("Init settings and sign permision..."); | |||
| prepareLocalPermission(currentId, privKey, ledgerInitProps, null, cryptoSetting); | |||
| prepareLocalProposal(currentId, privKey, ledgerInitProps, null, cryptoSetting); | |||
| try { | |||
| // 连接数据库; | |||
| @@ -201,7 +201,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| return defCryptoSetting; | |||
| } | |||
| public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| public LedgerInitProposal prepareLocalProposal(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, | |||
| ConsensusSettings csSettings, CryptoSetting cryptoSetting) { | |||
| // 创建初始化配置; | |||
| LedgerInitSettingData initSetting = new LedgerInitSettingData(); | |||
| @@ -249,7 +249,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| // 对初始交易签名,生成当前参与者的账本初始化许可; | |||
| SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); | |||
| localPermission = new LedgerInitPermissionData(currentId, permissionSign); | |||
| localPermission = new LedgerInitProposalData(currentId, permissionSign); | |||
| this.currentId = currentId; | |||
| return localPermission; | |||
| @@ -300,7 +300,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon | |||
| } | |||
| @Override | |||
| public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { | |||
| public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { | |||
| return localPermission; | |||
| } | |||
| @@ -4,7 +4,7 @@ import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.crypto.PrivKey; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.core.LedgerInitDecision; | |||
| import com.jd.blockchain.ledger.core.LedgerInitPermission; | |||
| import com.jd.blockchain.ledger.core.LedgerInitProposal; | |||
| import com.jd.blockchain.ledger.core.LedgerRepository; | |||
| import com.jd.blockchain.ledger.core.impl.LedgerManager; | |||
| import com.jd.blockchain.mocker.config.LedgerInitWebConfiguration; | |||
| @@ -48,7 +48,7 @@ public class NodeWebContext { | |||
| return controller.getInitTxContent(); | |||
| } | |||
| public LedgerInitPermission getLocalPermission() { | |||
| public LedgerInitProposal getLocalPermission() { | |||
| return controller.getLocalPermission(); | |||
| } | |||