@@ -43,7 +43,9 @@ public class BftsmartMessageService implements MessageService { | |||
throw new RuntimeException(e); | |||
} finally { | |||
asyncPeerProxyPool.returnObject(asynchServiceProxy); | |||
if (asynchServiceProxy != null) { | |||
asyncPeerProxyPool.returnObject(asynchServiceProxy); | |||
} | |||
} | |||
return asyncFuture; | |||
@@ -33,7 +33,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer | |||
private static Logger LOGGER = LoggerFactory.getLogger(BftsmartNodeServer.class); | |||
private static final String DEFAULT_BINDING_HOST = "0.0.0.0"; | |||
// private static final String DEFAULT_BINDING_HOST = "0.0.0.0"; | |||
private List<StateHandle> stateHandles = new CopyOnWriteArrayList<>(); | |||
@@ -59,7 +59,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer | |||
private TOMConfiguration tomConfig; | |||
private TOMConfiguration outerTomConfig; | |||
// private TOMConfiguration outerTomConfig; | |||
private HostsConfig hostsConfig; | |||
private Properties systemConfig; | |||
@@ -129,12 +129,12 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer | |||
} | |||
protected void initConfig(int id, Properties systemsConfig, HostsConfig hostConfig) { | |||
byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig); | |||
Properties sysConfClone = (Properties)systemsConfig.clone(); | |||
int port = hostConfig.getPort(id); | |||
hostConfig.add(id, DEFAULT_BINDING_HOST, port); | |||
// byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig); | |||
// Properties sysConfClone = (Properties)systemsConfig.clone(); | |||
// int port = hostConfig.getPort(id); | |||
// hostConfig.add(id, DEFAULT_BINDING_HOST, port); | |||
this.tomConfig = new TOMConfiguration(id, systemsConfig, hostConfig); | |||
this.outerTomConfig = new TOMConfiguration(id, sysConfClone, BinarySerializeUtils.deserialize(serialHostConf)); | |||
// this.outerTomConfig = new TOMConfiguration(id, systemsConfig, hostConfig); | |||
} | |||
@Override | |||
@@ -153,7 +153,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer | |||
} | |||
public TOMConfiguration getTomConfig() { | |||
return outerTomConfig; | |||
return tomConfig; | |||
} | |||
public int getId() { | |||
@@ -165,7 +165,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer | |||
throw new IllegalArgumentException("ReplicaID is negative!"); | |||
} | |||
this.tomConfig.setProcessId(id); | |||
this.outerTomConfig.setProcessId(id); | |||
// this.outerTomConfig.setProcessId(id); | |||
} | |||
public BftsmartConsensusSettings getConsensusSetting() { | |||
@@ -3,6 +3,8 @@ package com.jd.blockchain.gateway.web; | |||
import com.jd.blockchain.crypto.*; | |||
import com.jd.blockchain.gateway.service.GatewayInterceptService; | |||
import com.jd.blockchain.transaction.SignatureUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
@@ -27,6 +29,8 @@ import com.jd.blockchain.web.converters.BinaryMessageConverter; | |||
@RestController | |||
public class TxProcessingController implements TransactionService { | |||
private static Logger LOGGER = LoggerFactory.getLogger(TxProcessingController.class); | |||
@Autowired | |||
private PeerService peerService; | |||
@@ -59,11 +63,14 @@ public class TxProcessingController implements TransactionService { | |||
throw new IllegalStateException("Not implemented!"); | |||
} else { | |||
// 验证签名; | |||
StringBuilder signer = new StringBuilder(txRequest.getHash().toString()).append("->"); | |||
for (DigitalSignature sign : partiSigns) { | |||
signer.append(AddressEncoding.generateAddress(sign.getPubKey()).toBase58()).append(","); | |||
if (!SignatureUtils.verifySignature(txRequest.getTransactionContent(), sign.getDigest(), sign.getPubKey())) { | |||
throw new BusinessException("The validation of participant signatures fail!"); | |||
} | |||
} | |||
LOGGER.debug(signer.toString()); | |||
} | |||
// 注:转发前自动附加网关的签名并转发请求至共识节点;异步的处理方式 | |||
@@ -370,9 +370,11 @@ public class LedgerQueryService implements BlockchainQueryService { | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address)); | |||
// int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount()); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount()); | |||
// return dataAccount.getDataset().getDataEntry(key, version).getDataEntries(pages[0], pages[1]); | |||
fromIndex = pages[0]; | |||
count = pages[1]; | |||
DataIterator<String, TypedValue> iterator = dataAccount.getDataset().iterator(); | |||
iterator.skip(fromIndex); | |||
DataEntry<String, TypedValue>[] dataEntries = iterator.next(count); | |||
@@ -1,11 +1,9 @@ | |||
package com.jd.blockchain.ledger.core; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.*; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.utils.Bytes; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -117,6 +115,12 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||
TransactionRequestExtension reqExt = new TransactionRequestExtensionImpl(request); | |||
// 初始化交易的用户安全策略; | |||
// Set<Bytes> endPointAddresses = reqExt.getEndpointAddresses(); | |||
// int index = 0; | |||
// for (Bytes address : endPointAddresses) { | |||
// System.out.printf("EndPoint Sign Address %s[%s] -> %s \r\n", request.getHash(), index++, address.toBase58()); | |||
//// LOGGER.debug("EndPoint Sign Address {}[{}] -> {}", request.getHash(), index++, address.toBase58()); | |||
// } | |||
SecurityPolicy securityPolicy = securityManager.createSecurityPolicy(reqExt.getEndpointAddresses(), | |||
reqExt.getNodeAddresses()); | |||
SecurityContext.setContextUsersPolicy(securityPolicy); | |||
@@ -449,8 +449,10 @@ public class LedgerQueryController implements BlockchainQueryService { | |||
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); | |||
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address)); | |||
// int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount()); | |||
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount()); | |||
// return dataAccount.getDataEntries(pages[0], pages[1]); | |||
fromIndex = pages[0]; | |||
count = pages[1]; | |||
DataIterator<String, TypedValue> iterator = dataAccount.getDataset().iterator(); | |||
iterator.skip(fromIndex); | |||
@@ -8,14 +8,13 @@ import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.crypto.HashFunction; | |||
import com.jd.blockchain.ledger.DigitalSignature; | |||
import com.jd.blockchain.ledger.NodeRequest; | |||
import com.jd.blockchain.ledger.TransactionRequest; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.*; | |||
import com.jd.blockchain.transaction.SignatureUtils; | |||
import com.jd.blockchain.transaction.TransactionService; | |||
import com.jd.blockchain.transaction.TxRequestMessage; | |||
import com.jd.blockchain.utils.concurrent.AsyncFuture; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
/** | |||
* {@link NodeSigningAppender} 以装饰者模式实现,为交易请求附加上节点签名; | |||
@@ -25,6 +24,8 @@ import com.jd.blockchain.utils.concurrent.AsyncFuture; | |||
*/ | |||
public class NodeSigningAppender implements TransactionService { | |||
private static Logger LOGGER = LoggerFactory.getLogger(NodeSigningAppender.class); | |||
static { | |||
DataContractRegistry.register(NodeRequest.class); | |||
} | |||
@@ -78,8 +79,58 @@ public class NodeSigningAppender implements TransactionService { | |||
HashDigest txHash = hashFunc.hash(nodeRequestBytes); | |||
txMessage.setHash(txHash); | |||
AsyncFuture<byte[]> result = messageService.sendOrdered(BinaryProtocol.encode(txMessage, TransactionRequest.class)); | |||
try { | |||
AsyncFuture<byte[]> asyncFuture = messageService.sendOrdered(BinaryProtocol.encode(txMessage, TransactionRequest.class)); | |||
byte[] result = asyncFuture.get(); | |||
if (result == null) { | |||
LOGGER.error("Gateway receive [{}]'s result is null!", txRequest.getHash()); | |||
return new ErrorTransactionResponse(txRequest.getTransactionContent().getHash()); | |||
} | |||
return BinaryProtocol.decode(result); | |||
} catch (IllegalStateException e) { | |||
e.printStackTrace(); | |||
LOGGER.error("Gateway send tx [{}] error {} !", txRequest.getHash(), e); | |||
return new ErrorTransactionResponse(txRequest.getTransactionContent().getHash()); | |||
} | |||
} | |||
private static class ErrorTransactionResponse implements TransactionResponse { | |||
HashDigest contentHash; | |||
public ErrorTransactionResponse(HashDigest contentHash) { | |||
this.contentHash = contentHash; | |||
} | |||
@Override | |||
public HashDigest getContentHash() { | |||
return contentHash; | |||
} | |||
@Override | |||
public TransactionState getExecutionState() { | |||
return TransactionState.TIMEOUT; | |||
} | |||
@Override | |||
public HashDigest getBlockHash() { | |||
return null; | |||
} | |||
@Override | |||
public long getBlockHeight() { | |||
return -1L; | |||
} | |||
@Override | |||
public boolean isSuccess() { | |||
return false; | |||
} | |||
return BinaryProtocol.decode(result.get()); | |||
@Override | |||
public OperationResult[] getOperationResults() { | |||
return null; | |||
} | |||
} | |||
} |
@@ -82,7 +82,7 @@ public class SDK_GateWay_User_Test_ { | |||
CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0); | |||
GATEWAY_IPADDR = "127.0.0.1"; | |||
GATEWAY_PORT = 8081; | |||
GATEWAY_PORT = 10300; | |||
SECURE = false; | |||
GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE, | |||
CLIENT_CERT); | |||